Skip to content

[Bug]: py_binary rule conflicts with its own .venv #686

@antspy

Description

@antspy

What happened?

Hi,

The py_binary rule exports a .venv rule which apparently cannot be built together with the main rule.
I have a simple py_binary rule:

py_binary(
    name = "generate",
    srcs = ["generate.py"],
    data = ["//src/.../jinja_templates"],
    visibility = ["//:__subpackages__"],
    deps = [
        "@pip//jinja2",
    ],
)

The following invocations both work fine:
bazel build src:generate
bazel build src:generate.venv

But if I build them both at the same time:
bazel build src:generate src:generate.venv

It raises this error:

ERROR: file 'src/environments/generate.venv.pth' is generated by these conflicting actions:
Label: //src/environments:generate, //src/environments:generate.venv
RuleClass: py_binary rule, _py_venv_binary rule
JavaActionClass: class com.google.devtools.build.lib.analysis.actions.ParameterFileWriteAction
Configuration: 4a505f9f7d9c617851c7bc765bdd315e69b5fe3381b136a958d350d48ba6243d
Mnemonic: FileWrite
Action key: 445cfa74138db6883bd7263f60c713f19d07f9bc86b6494924dc2d8dd131e606, 197c4693f167b4e8245ea736167c5f197ef437caea8ed99e8af81eb590fa9ea4
Progress message: Writing file src/environments/generate.venv.pth
Action describeKey: GUID: 45f678d8-e395-401e-8446-e795ccc6361f
Param File Type: UNQUOTED
Content digest (approximate): b4c825f4cda889218b1ab8173333ec3a0393318fd8597dcfccef6f2a293df9d6
NOTE: Content digest reflects approximate, analysis-time data; it does not account for data available during execution (e.g. tree artifact expansions), GUID: 45f678d8-e395-401e-8446-e795ccc6361f
Param File Type: UNQUOTED
Content digest (approximate): a3e4592c5dda521bb972b93f22645b15e3911959effd5efa0d4690e137115ea9
NOTE: Content digest reflects approximate, analysis-time data; it does not account for data available during execution (e.g. tree artifact expansions)
PrimaryInput: (null)
PrimaryOutput: File:[[<execution_root>]bazel-out/k8-fastbuild/bin]src/environments/generate.venv.pth
Owner information: ConfiguredTargetKey{label=//src/environments:generate, config=BuildConfigurationKey[4a505f9f7d9c617851c7bc765bdd315e69b5fe3381b136a958d350d48ba6243d]}, ConfiguredTargetKey{label=//src/environments:generate.venv, config=BuildConfigurationKey[4a505f9f7d9c617851c7bc765bdd315e69b5fe3381b136a958d350d48ba6243d]}
MandatoryInputs: are equal
Outputs: are equal

Surprisingly, however, building every target works fine:
bazel build src:all

Not sure what this is the case. I am having issues with this because during CI I run:
bazel build $(bazel query '//src/... except attr(tags, "skip-ci", //src/...)') and it breaks.

This behavior only happened after updating bazel to 8.4 and the aspect rules py library version to 1.6.6. If I downgrade the aspect_rules_py version to 1.3.4, it works correctly again.

Version

Development (host) and target OS/architectures: Ubuntu

Output of bazel --version:
aspect 2025.41.11-104e7b18 (using bazel version 8.4.0)

Version of the Aspect rules, or other relevant rules from your
WORKSPACE or MODULE.bazel file:
1.6.6 fails, 1.3.4 works.
Language(s) and/or frameworks involved:
python

How to reproduce

See above

Any other information?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions