Bazel 7 native py_binary: startup and import failures with rules_python 2.4.1
维护者通常 1 天内回复
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 30/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 领域
- build-system
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
🐞 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.
- 主要语言
- Starlark
- 星标
- 688
- 派生
- 724
- 平均合并
- 1 天 15 小时
- 30 天内合并 PR
- 52
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
bazel-contrib/rules_python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 88/100
bazel-contrib/rules_python#4201 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
bazel-contrib/rules_python#4164 · 1 条评论 ·
维护者通常 1 天内回复
-
go:embed stdlib_list.txt file in gazelle/python/std_modules.go is missing可能已有人在做 @udaya2899 于 12 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
bazel-contrib/rules_python#3821 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 28/100
bazel-contrib/rules_python#4218 · 2 条评论 ·
维护者通常 1 天内回复
-
type: toolchain
难度 4/5 3-5 天 新手友好度 35/100
bazel-contrib/rules_python#4216 · 6 条评论 · 1 个 reaction ·
维护者通常 1 天内回复
查看 bazel-contrib/rules_python 的全部 Issue
相似的 Issue
-
Fix Makefile build graph: add data-file prerequisites and missing .PHONY entries so make -j is safe未关闭
难度 2/5 1-3 小时 新手友好度 75/100
-
Use GHA setup gradle action可能已有人在做 @bric3 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 67/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
Homebrew/homebrew-core#317477 · 2 条评论 ·
维护者通常 1 天内回复
-
chore ci
难度 2/5 1-3 小时 新手友好度 72/100
Tollcraft/soroban-cost-linter#891 ·
维护者通常 1 天内回复
-
priority:P2 product:orazaka type:bug
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复