Skip to content

generate: python renames an existing python_library to the file-derived name (part of #9237) #9297

Closed

Description

@TrapsterDK

Problem

When a python_library already owns a source but has a name other than the one generate derives from the file, generate deletes it and adds a new target with the derived name. Labels that point at the old name break.

Found in #9279 (review on #9237): python/rules/BUILD.bazel has

python_library(
    name = "bench_plugin",
    srcs = ["dx_bench_plugin.py"],
    imports = ["."],
)

Generate replaces it with python_library(name = "dx_bench_plugin", ...), but python/rules/defs.bzl:140 adds Label("//python/rules:bench_plugin") to every python_benchmark, so all benchmarks (for example //python/tests/fixtures/hello:parse_bench) fail analysis.

Reproduction

On main (570927c):

tools/dx generate python/rules

proposes 4 edits to python/rules/BUILD.bazel; --apply removes bench_plugin and adds dx_bench_plugin.

Minimal case: a package with foo.py and python_library(name = "bar", srcs = ["foo.py"]). Generate renames it to foo.

Fix

Match existing rules by the sources they own before naming, as other extensions do for existing targets, so a library that already claims foo.py keeps its name.

Done when

Generate on main leaves bench_plugin in place.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Xut2hzpb4qWNZKpDCrwUz7

Activity

  1. added a commit that references this issue on Nov 7, 2026
    764ab7a
  2. added a commit that references this issue on Nov 7, 2026
    9a41d8a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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