Skip to content

Gazelle generation mode per file: Unexpected behavior if a binary is added to a folder containing a binary. #2627

Closed
@gueraf

Description

@gueraf

🐞 bug report

Affected Rule

Gazelle

Is this a regression?

The current behavior is misaligned with my interpretation of the documentation.

Description

With # gazelle:python_generation_mode file, if there is a folder with say existing_main.py and :existing_main of type py_binary, then if I add added_main.py, I'd expect a py_binary named :added_main to be generated.

Reading documentation, in particular If python_generation_mode is set to file, then instead of one py_binary target per module, Gazelle will create one py_binary target for each file with such a line, and the name of the target will match the name of the script., I think this aligns with my expectation.

Unfortunately it seems like right now :added_main is not generated. Please see this unit test and corresponding output.

🔬 Minimal Reproduction

git clone https://github.com/gueraf/rules_python/tree/new_test &&
cd rules_python/gazelle/python && \
bazel test //python:python_test_add_binary_to_existing_binary_per_file

# https://gist.github.com/gueraf/0e837ecdbff82a235bb7ce441c14832d

🔥 Exception or Error


        python_test.go:186: add_binary_to_existing_binary_per_file/BUILD diff (-want,+got):
              (
              	"""
              	... // 7 identical lines
              	    visibility = ["//:__subpackages__"],
              	)
            - 	
            - 	py_binary(
            - 	    name = "added_main",
            - 	    srcs = ["added_main.py"],
            - 	    visibility = ["//:__subpackages__"],
            - 	)
              	"""
              )

🌍 Your Environment

Operating System:

  
Ubuntu 24.04.2 LTS
  

Output of bazel version:

  
Bazelisk version: v1.25.0
Build label: 8.1.0
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Thu Feb 13 19:02:11 2025 (1739473331)
Build timestamp: 1739473331
Build timestamp as int: 1739473331
  

Rules_python version:

  
git head (fa882817a7a69ae1e6bc3a63530ce158b64d2efd)
  

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions