Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

linzhp
Copy link
Contributor

@linzhp linzhp commented Jun 15, 2025

This is yet another implementation of #2822. Based on this:

// Remove the file from srcs if we're doing per-file library generation so
// that we don't also generate a py_library target for it.
if cfg.PerFileGeneration() {
srcs.Remove(name)
}

The only case when a python file does not exist in py_library is in file mode. Stop indexing py_binary in other mode to avoid ambiguous dependency resolution.

@linzhp
Copy link
Contributor Author

linzhp commented Jun 23, 2025

This PR is ready for review. The failing CI is an infra issue

@linzhp
Copy link
Contributor Author

linzhp commented Jun 29, 2025

Added tests. Please take another look

@linzhp
Copy link
Contributor Author

linzhp commented Jul 13, 2025

@aignas friendly ping...

Copy link
Collaborator

@dougthor42 dougthor42 left a 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
================================================================================

@linzhp
Copy link
Contributor Author

linzhp commented Jul 14, 2025

PTAL

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy