Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

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

未关闭
#4,234 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@gleyba 已经在做这个了。

开始于 2026年10月9日。

  • #4235 来自 @gleyba —— 未关闭

评估

难度
4/5
预计耗时
3-5 天
新手友好度
30/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
活跃
技术栈
python, shell
领域
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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

bazel-contrib/rules_python 的其他 Issue

查看 bazel-contrib/rules_python 的全部 Issue

相似的 Issue

更多 Build System Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。