Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Continuing Discussion] python_no_test_files directive #1826

Open
dougthor42 opened this issue Mar 28, 2024 · 0 comments
Open

[Continuing Discussion] python_no_test_files directive #1826

dougthor42 opened this issue Mar 28, 2024 · 0 comments
Labels
gazelle Gazelle plugin related issues help wanted

Comments

@dougthor42
Copy link
Contributor

This is a continuation of the discussion from #1819 (comment).

🚀 feature request

Relevant Rules

  • gazelle

Description

The summary of the discussion in #1819 (comment) so far is:

  • Having python_test_file_pattern accept no value is unintuitive and should raise an error. feat(gazelle): Add "python_test_file_pattern" directive #1819 includes this.
  • Setting python_test_file_pattern back to "default" should be done manually, not through magic strings.
    • Eg: # gazelle:python_test_file_pattern *_test.py,test_*.py
  • There's still not a nice way to tell gazelle that there are no files in the bazel package that should be mapped to py_test targets but should still be processed as py_library or py_binary (see example below).
    • Workaround: set python_test_file_pattern to a value that ends in something other than .py, such as gazelle:python_test_file_pattern ignore_me.txt. This will work because a prior check (here and here) asserts that the files being processed by gazelle end in .py.
  • All of the above led to the conclusion that there should be a python_no_test_files directive.
# example of project structure
project/
+ BUILD.bazel
+ MODULE.bazel
+ src/mypackage/               # guaranteed to have no py_test targets
    + BUILD.bazel
    + run_electrical_test.py   # py_binary
    + electrical_test.py       # py_library
+ tests/                       # will have any py_* targets
    + BUILD.bazel
    + foo_test.py              # py_test
    + bar_test.py              # py_test
    + test_utils.py            # py_library
    + run_all_test.py          # py_binary

How does python_no_test_files behave? Does it:

  1. cause gazelle to simply ignore all files that match python_test_file_pattern? or
  2. cause gazelle to map all files that match python_test_file_pattern to py_library or py_binary (if they have if __name__ ...)?

Describe the solution you'd like

With behavior (1), there's still a feature gap for the example case above, and the workaround feels a bit hacky.

For behavior (2) we'd probably want to name the directive something else.

Describe alternatives you've considered

Using python_ignore_files and then manually generating the py_library targets for files that match python_test_file_pattern. This is less than ideal when adding things to large projects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
gazelle Gazelle plugin related issues help wanted
Projects
None yet
Development

No branches or pull requests

3 participants