commit | d5945ed2158d1c7a205f278c89520aa4da497442 | [log] [tgz] |
---|---|---|
author | Alex Martani <alexandre.martani@benchling.com> | Wed Mar 20 19:10:21 2024 -0700 |
committer | GitHub <noreply@github.com> | Thu Mar 21 02:10:21 2024 +0000 |
tree | 7154af1fdc8c1d6e811693a274c308ce55c8de5a | |
parent | e86252ffd6d1a1bf32ae99933acc5ab49b78ec1e [diff] |
fix(gazelle): Do not create invalid py_test rules in `project` generation mode (#1809) Since https://github.com/bazelbuild/rules_python/pull/1538, when using `gazelle:python_generation_mode project`, a `py_test` rule is created even when there are no test files in the project. fb673ee47b3268a65a18a154edd574b6509c38c7 (first commit on the PR branch) reproduces this issue - it shows that a `py_test` rule is created even when there is no test entrypoint file (`__test__.py`) nor any test file in the entire project. Additionally, test rules created on `project` or `package` generation mode will always set `main = "__test__.py"`, even when that file doesn't exist. This PR fixes it by only generating a `py_test` rule if it can find some test file - either an explicit `__test__.py`, or any other file prefixed with `test_` or suffixed with `_test.py`. It also changes the generated test rule to only add `main = "__test__.py"` if there is an actual `__test__.py` file. Note that, in the case where a `__test__.py` file doesn't exist, the generated `py_test` rule is likely invalid as-is due to the lack of `main`; this can be fixed by mapping to some other `py_test` implementation, and I believe the new behavior makes more sense than pointing `main` to a non-existing file. It may be useful to review per-commit (all tests pass on each commit): - First commit reproduces the issue; - Second commit fixes the issue and the corresponding tests; - Third commit adds additional test cases.
This repository is the home of the core Python rules -- py_library
, py_binary
, py_test
, py_proto_library
, and related symbols that provide the basis for Python support in Bazel. It also contains package installation rules for integrating with PyPI and other indices.
Documentation for rules_python is at https://rules-python.readthedocs.io and in the Bazel Build Encyclopedia.
Examples live in the examples directory.
Currently, the core rules build into the Bazel binary, and the symbols in this repository are simple aliases. However, we are migrating the rules to Starlark and removing them from the Bazel binary. Therefore, the future-proof way to depend on Python rules is via this repository. SeeMigrating from the Bundled Rules
below.
The core rules are stable. Their implementation in Bazel is subject to Bazel's backward compatibility policy. Once migrated to rules_python, they may evolve at a different rate, but this repository will still follow semantic versioning.
The Bazel community maintains this repository. Neither Google nor the Bazel team provides support for the code. However, this repository is part of the test suite used to vet new Bazel releases. See How to contribute page for information on our development workflow.
For detailed documentation, see https://rules-python.readthedocs.io
See Bzlmod support for more details.