-
-
Notifications
You must be signed in to change notification settings - Fork 610
do not index py_binary unless in file mode #2989
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
base: main
Are you sure you want to change the base?
Conversation
This PR is ready for review. The failing CI is an infra issue |
Added tests. Please take another look |
@aignas friendly ping... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tested this on our big repo that uses file mode; looks good (eg gazelle didn't cause any unexpected changes).
Request: please update CHANGELOG.md
with a fixed
entry.
For my own future reference, this is what happens without the fix (eg reverting e9bd803):
=================== Test output for //python:python_test_import_with_same_srcs_library_and_binary:
--- FAIL: TestGazelleBinary (0.00s)
--- FAIL: TestGazelleBinary/import_with_same_srcs_library_and_binary (0.03s)
python_test.go:168: expected gazelle exit code: 0
got: 1
python_test.go:178: expected gazelle stderr:
got: gazelle: ERROR: failed to validate dependencies for target "//bar:py_default_library":
"bar/bar.py", line 1: multiple targets (//foo:script, //foo:py_default_library) may be imported with "foo.script": possible solutions:
1. Disambiguate the above multiple targets by removing duplicate srcs entries.
2. Use the '# gazelle:resolve py foo.script TARGET_LABEL' BUILD file directive to resolve to one of the above targets.
"bar/bar.py", line 1: "foo" is an invalid dependency: possible solutions:
1. Add it as a dependency in the requirements.txt file.
2. Use the '# gazelle:resolve py foo TARGET_LABEL' BUILD file directive to resolve to a known dependency.
3. Ignore it with a comment '# gazelle:ignore foo' in the Python file.
FAIL
================================================================================
gazelle/python/testdata/import_with_same_srcs_library_and_binary/BUILD.in
Outdated
Show resolved
Hide resolved
gazelle/python/testdata/import_with_same_srcs_library_and_binary/test.yaml
Outdated
Show resolved
Hide resolved
gazelle/python/testdata/import_with_same_srcs_library_and_binary/foo/script.py
Outdated
Show resolved
Hide resolved
PTAL |
This is yet another implementation of #2822. Based on this:
rules_python/gazelle/python/generate.go
Lines 248 to 252 in 94e08f7
The only case when a python file does not exist in
py_library
is in file mode. Stop indexingpy_binary
in other mode to avoid ambiguous dependency resolution.