Bazel 7 native py_binary: startup and import failures with rules_python 2.4.1
Maintainer antworten meist innerhalb von 1 Tag
Bewertung
- Schwierigkeit
- 4/5
- Geschätzter Aufwand
- 3-5 Tage
- Anfängerfreundlichkeit
- 30/100
- Issue-Typ
- Bug
- Klarheit
- Größtenteils klar
- Aktivitätsstatus
- Aktiv
- Bereich
- build-system
Rechercherichtung
Start with the launcher templates python/private/python_bootstrap_template.txt and python/private/stage1_bootstrap_template.sh, and the unexpanded %runtime_venv_symlinks%, %interpreter_args% and %stage2_bootstrap% placeholders. Reproduce from the crash/, shell_launchers/ and import_issue/ workspaces, which use Bazel 7.7.1 and rules_python 2.4.1. Done when the hello programs run under the native targets and the declared py_library module imports from the direct-to-main fallback.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
🐞 bug report
Affected Rule
Bazel 7's built-in py_binary using the default runtime supplied by
rules_python. The affected launcher templates are
python/private/python_bootstrap_template.txt and
python/private/stage1_bootstrap_template.sh.
Is this a regression?
Not bisected; I do not have a verified last working rules_python release.
Confirmed with 2.4.1, with similar failures previously observed on 2.3.4.
Description
During a rules_python upgrade, dependencies can still define built-in Python
targets without loading rules_python's Starlark replacements. Bazel 7 leaves
newer launcher placeholders unexpanded, causing startup failures with both
the Python and shell bootstraps.
After bypassing the Python launcher's first crash, its direct-to-main fallback
also fails to make declared import roots available. A module supplied by a
declared py_library dependency cannot be imported even though its source is
present in runfiles.
Expected: the hello programs run, and the declared dependency is importable.
🔬 Minimal Reproduction
The reproduction contains three independent Bzlmod workspaces, each pinned to
Bazel 7.7.1 through .bazelversion. Each uses rules_python 2.4.1:
bazel_dep(name = "rules_python", version = "2.4.1")
The rules are deliberately built-in py_binary/py_library, without Starlark
load() statements. No custom runtimes or toolchains are configured.
1. Python launcher: crash/ — unpatched release
The local external repository @native_tool defines a native py_binary
whose main file only prints launcher reached main, without any imports.
From crash/, run:
bazelisk run @native_tool//:hello
The launcher crashes while parsing the unexpanded %runtime_venv_symlinks%
placeholder, before executing the main file.
2. Shell launcher: shell_launchers/ — unpatched release
This workspace has only the dependency above, a native hello target, and its
one-line Python source:
py_binary(name = "hello", srcs = ["hello.py"])
print("launcher reached main")
From shell_launchers/, run:
bazelisk run --@rules_python//python/config_settings:bootstrap_impl=script //:hello
The flag selects the shell launcher; it is not a runtime override. The launcher
passes the literal %interpreter_args% to Python as a script filename and
fails before executing hello.py. %stage2_bootstrap% is also unexpanded.
3. Declared imports: import_issue/ — explicit crash guard
This third example intentionally patches the release. MODULE.bazel applies
avoid-bootstrap-crash.patch through single_version_override. The patch only
treats the unexpanded venv-symlink placeholder as an empty mapping. It does not
change import paths; without it, the first crash hides this second failure.
The dependency and import root are explicitly declared:
py_library(
name = "declared_import",
srcs = ["lib/import_fixture.py"],
imports = ["lib"],
)
py_binary(name = "imports", srcs = ["imports.py"], deps = [":declared_import"])
imports.py starts with from import_fixture import MESSAGE. From
import_issue/, run:
bazelisk run //:imports
The program reaches its main file but raises ModuleNotFoundError. The
fallback executes the main directly without the import setup normally
performed by stage 2.
🔥 Exception or Error
Python launcher, unpatched:
RUNTIME_VENV_SYMLINKS = dict(line.split("|") for line in RUNTIME_VENV_SYMLINKS if line)
ValueError: dictionary update sequence element #0 has length 1; 2 is required
Shell launcher, unpatched:
python3: can't open file '.../%interpreter_args%': [Errno 2] No such file or directory
Declared imports, after the explicit crash guard:
from import_fixture import MESSAGE
ModuleNotFoundError: No module named 'import_fixture'
🌍 Your Environment
Operating System:
Ubuntu 20.04.2 LTS container, Linux x86_64
Kernel: 6.8.0-142-generic
Output of bazel version:
Build label: 7.7.1
Build target: @@//src/main/java/com/google/devtools/build/lib/bazel:BazelServer
Build time: Wed Nov 12 17:33:47 2025 (1762968827)
Build timestamp: 1762968827
Build timestamp as int: 1762968827
Rules_python version:
2.4.1
Anything else relevant?
Related work: PR #3495
added the Python launcher's %main% fallback for native targets. I understand
that this mixed native/rules_python configuration is a legacy compatibility
path rather than supported modern Starlark usage; this report documents the
remaining startup and import failures in that path.
- Vorherrschende Sprache
- Starlark
- Sterne
- 687
- Forks
- 726
- Ø Merge
- 1 T. 1 Std.
- Gemergte PRs (30 T.)
- 89
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus bazel-contrib/rules_python
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 68/100
bazel-contrib/rules_python#4251 · 1 Reaktion ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
bazel-contrib/rules_python#4164 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
go:embed stdlib_list.txt file in gazelle/python/std_modules.go is missingEvtl. vergeben @udaya2899 hat das vor 21 Tagen übernommen. Offen
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
bazel-contrib/rules_python#3821 ·
Maintainer antworten meist innerhalb von 1 Tag
-
pip.parse ignores uv.lock dependency-edge platform markersEvtl. vergeben @kdelalic hat das heute übernommen. Offen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 20/100
bazel-contrib/rules_python#4287 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Empty `py_library` targets that have the `imports` attribute added are not automatically removedEvtl. vergeben @dougthor42 hat das vor 1 Tag übernommen. Offen
bazel-contrib/rules_python#4282 · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 1 Tag
Alle Issues in bazel-contrib/rules_python
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
ROCm/rocm-libraries#14012 ·
Maintainer antworten meist innerhalb von 2 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 71/100
awslabs/aws-checksums#121 ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
rstackjs/storybook-rsbuild#606 ·
Maintainer antworten meist innerhalb von 1 Tag
-
good first issue help wanted
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
-
bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
swc-project/swc-next#1022 ·
Maintainer antworten meist innerhalb von 1 Tag