Hacktoberfest 2026: die Issues, die Maintainer für den Oktober markiert haben – offen und einsteigerfreundlich. Hacktoberfest-Issues durchsuchen

Bazel 7 native py_binary: startup and import failures with rules_python 2.4.1

Offen
#4,234 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

@gleyba arbeitet bereits daran.

Seit 09.10.2026.

  • #4235 von @gleyba — offen

Bewertung

Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Anfängerfreundlichkeit
30/100
Issue-Typ
Bug
Klarheit
Größtenteils klar
Aktivitätsstatus
Aktiv
Tech-Stack
python, shell
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

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus bazel-contrib/rules_python

Alle Issues in bazel-contrib/rules_python

Ähnliche Issues

Weitere Issues zu Build System

Neue Issues direkt in Ihr Postfach

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