Skip to content

feat(gazelle): Directive controlling pytest ancestor depdencies#3596

Draft
dougthor42 wants to merge 4 commits intobazel-contrib:mainfrom
dougthor42:u/dthor/gazelle-disable-conftest-gh3595
Draft

feat(gazelle): Directive controlling pytest ancestor depdencies#3596
dougthor42 wants to merge 4 commits intobazel-contrib:mainfrom
dougthor42:u/dthor/gazelle-disable-conftest-gh3595

Conversation

@dougthor42
Copy link
Collaborator

Fixes #3595.

Add a new directive python_include_ancestor_conftest, defaulting to true, that configures whether or not ancestor conftest targets are added to a py_test target's dependencies.

@dougthor42 dougthor42 added type: feature request gazelle Gazelle plugin related issues labels Feb 14, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @dougthor42, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new configuration option for Gazelle's Python extension, allowing users to explicitly control the inclusion of ancestor conftest.py files in py_test target dependencies. This addresses a previous issue where ancestor conftest files were not automatically added, and provides flexibility for users who may not desire this default behavior, ensuring better control over test dependency resolution.

Highlights

  • New Directive Introduced: A new Gazelle directive, python_include_ancestor_conftest, has been added to control whether ancestor conftest.py targets are automatically included as dependencies for py_test targets.
  • Configurable Behavior: This directive defaults to true, restoring the behavior of including all ancestor conftest.py files. Users can set it to false to revert to the pre-1.9.0 behavior where only sibling conftest targets are included.
  • Documentation and Testing: Comprehensive documentation for the new directive has been added, including examples. A new test suite has also been introduced to verify its functionality and inheritance behavior across different directory levels.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • gazelle/docs/annotations.md
    • Added an anchor for the include_pytest_conftest annotation.
  • gazelle/docs/directives.md
    • Added documentation for the new python_include_ancestor_conftest directive.
    • Included examples demonstrating the directive's behavior.
  • gazelle/python/configure.go
    • Registered python_include_ancestor_conftest in KnownDirectives.
    • Implemented parsing logic for the python_include_ancestor_conftest directive.
  • gazelle/python/testdata/directive_python_include_ancestor_conftest/BUILD.out
    • Added BUILD.out for the root conftest.py test case.
  • gazelle/python/testdata/directive_python_include_ancestor_conftest/README.md
    • Added a README explaining the test case for the new directive.
  • gazelle/python/testdata/directive_python_include_ancestor_conftest/one/BUILD.out
    • Added BUILD.out for the one/ subdirectory test case.
  • gazelle/python/testdata/directive_python_include_ancestor_conftest/one/two/BUILD.in
    • Added BUILD.in to test setting the directive to false.
  • gazelle/python/testdata/directive_python_include_ancestor_conftest/one/two/BUILD.out
    • Added BUILD.out for the one/two/ subdirectory test case with the directive set to false.
  • gazelle/python/testdata/directive_python_include_ancestor_conftest/one/two/three/BUILD.in
    • Added BUILD.in to test setting the directive back to true.
  • gazelle/python/testdata/directive_python_include_ancestor_conftest/one/two/three/BUILD.out
    • Added BUILD.out for the one/two/three/ subdirectory test case with the directive set to true.
  • gazelle/python/testdata/directive_python_include_ancestor_conftest/test.yaml
    • Added test.yaml for the new directive's test suite.
  • gazelle/pythonconfig/pythonconfig.go
    • Defined PythonIncludeAncestorConftest constant.
    • Added includeAncestorConftest field to Config struct.
    • Initialized includeAncestorConftest to true by default.
    • Implemented SetIncludeAncestorConftest and IncludeAncestorConftest methods.
    • Ensured the new field is copied in NewChild.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

The pull request introduces a new Gazelle directive, python_include_ancestor_conftest, which allows users to control whether ancestor conftest.py targets are automatically added as dependencies to py_test targets. The directive is correctly registered, documented, and integrated into the configuration parsing logic. However, the actual implementation that uses this configuration during rule generation appears to be missing from gazelle/python/generate.go. Without this logic, the directive will not function as intended. Additionally, there are minor typos in the documentation and test data.

Comment on lines +265 to +270
case pythonconfig.PythonIncludeAncestorConftest:
v, err := strconv.ParseBool(strings.TrimSpace(d.Value))
if err != nil {
log.Fatal(err)
}
config.SetIncludeAncestorConftest(v)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

critical

The directive is correctly parsed and stored in the configuration here. However, the logic to respect this setting during rule generation seems to be missing from gazelle/python/generate.go. Specifically, the loop that adds ancestor conftest paths (around line 532 in generate.go) should be conditioned on cfg.IncludeAncestorConftest(). Without this change, the directive will have no effect on the generated deps.

# Directive: `python_include_ancestor_conftest`

This test case asserts that the `# gazelle:python_include_ancestor_conftest`
directive correctly includes or excludes ancestor contest targets in `py_test`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Typo: "contest" should be "conftest".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

gazelle Gazelle plugin related issues type: feature request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feat: Directive to disable ancestor conftest.py deps

1 participant