bazel-contrib / bazel-contrib/rules_python

precompiling results in action output conflicts

Offen
#2,445 2 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Starlark
Sterne
688
Forks
721
Ø Merge
15 Std. 7 Min.
Gemergte PRs (30 T.)
76

Beschreibung

# 🐞 bug report

### Affected Rule

```bzl
load("@rules_python//python:defs.bzl", "py_test")

py_test(
name = "first",
srcs = ["foo.py"],
main = "foo.py",
)

py_test(
name = "second",
srcs = ["foo.py"],
exec_properties = {"foo": "bar"},
main = "foo.py",
)
```

With this BUILD file, where 2 python rules include the same file, building both of these targets results in:

```
ERROR: file '__pycache__/foo.cpython-311.pyc' is generated by these conflicting actions:
Label: //:second, //:first
RuleClass: py_test rule
JavaActionClass: class com.google.devtools.build.lib.analysis.actions.StarlarkAction
Configuration: 8e4ab22e89843aa348ba782be25eadb5bae40f2ae62dec3edd2cdaf809e8d7b1
Mnemonic: PyCompile
Action key: aa843bb97b9c08aba98aa87861cf3bba7f6f80370dcc227a3aa766a618449a45, d8983143b0af1168a9ab184492ac6ef78a440269bfd600178f4e6d984e208bf7
Progress message: Python precompiling foo.py into bazel-out/darwin_arm64-fastbuild/bin/__pycache__/foo.cpython-311.pyc
Action describeKey: Python precompiling foo.py into bazel-out/darwin_arm64-fastbuild/bin/__pycache__/foo.cpython-311.pyc
Environment variable: PYTHONHASHSEED=0
Environment variable: PYTHONNOUSERSITE=1
Environment variable: PYTHONSAFEPATH=1
Argument: bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/rules_python~/python/private/python3
Argument: bazel-out/darwin_arm64-opt-exec-ST-d57f47055a04/bin/external/rules_python~/tools/precompiler/precompiler
Argument: --invalidation_mode
Argument: checked_hash
Argument: --src
Argument: foo.py
Argument: --src_name
Argument: foo.py
Argument: --pyc
Argument: bazel-out/darwin_arm64-fastbuild/bin/__pycache__/foo.cpython-311.pyc
Argument: --optimize
Argument: 0
Argument: --python_version
Argument: 3.11
Output paths mode: OFF

PrimaryInput: File:[/Users/ksmiley/Downloads/repro[source]]foo.py
PrimaryOutput: File:[[]bazel-out/darwin_arm64-fastbuild/bin]__pycache__/foo.cpython-311.pyc
Owner information: ConfiguredTargetKey{label=//:second, config=BuildConfigurationKey[8e4ab22e89843aa348ba782be25eadb5bae40f2ae62dec3edd2cdaf809e8d7b1]}, ConfiguredTargetKey{label=//:first, config=BuildConfigurationKey[8e4ab22e89843aa348ba782be25eadb5bae40f2ae62dec3edd2cdaf809e8d7b1]}
MandatoryInputs: are equal
Outputs: are equal
Use --verbose_failures to see the command lines of failed build steps.
ERROR: com.google.devtools.build.lib.actions.MutableActionGraph$ActionConflictException: for __pycache__/foo.cpython-311.pyc, previous action: action 'Python precompiling foo.py into bazel-out/darwin_arm64-fastbuild/bin/__pycache__/foo.cpython-311.pyc', attempted action: action 'Python precompiling foo.py into bazel-out/darwin_arm64-fastbuild/bin/__pycache__/foo.cpython-311.pyc'
```

### Is this a regression?

I bisected to https://github.com/bazelbuild/rules_python/commit/eb2225c31a20a7ee361054b088bcef8cd9434b74, we hit it when updating from 0.36.0 to 0.40.0

## 🔬 Minimal Reproduction

Build in this repo: [repro.zip](https://github.com/user-attachments/files/17926786/repro.zip)

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Start with the BUILD file in repro.zip and reproduce the conflict by building the first and second py_test targets together. Inspect the regression introduced by commit eb2225c31a20a7ee361054b088bcef8cd9434b74 and trace the precompilation output paths; done means both targets build without conflicting actions for the shared foo.py file.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
python
Bereich
build-system
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
42/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.