Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

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

Abierto
#4,234 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

@gleyba ya está trabajando en esto.

Desde el 9/10/2026.

  • #4235 de @gleyba — abierto

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
30/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
python, shell
Área
build-system

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

🐞 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.

Lenguaje dominante
Starlark
Estrellas
688
Forks
724
Merge medio
1 d 21 h
PR fusionados (30 d)
48

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de bazel-contrib/rules_python

Todos los issues de bazel-contrib/rules_python

Issues similares

Más issues de Build System

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.