Windows: cached venv initialization fails on dangling package symlinks
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 45/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- python
- 领域
- build-system
调研方向
The failure is in _create_venv in python/private/python_bootstrap_template.txt, at the os.makedirs(dirname(venv_abs_path), exist_ok=True) call (around line 657). The issue's reproduction script execs that template and simulates a dangling directory symlink followed by a new one; start there. Done when the script's final assertions pass on Windows, with the stale link replaced by the required directory.
由索引模型根据 Issue 内容生成。
描述
🐞 bug report
Affected Rule
py_binary: _create_venv in
python/private/python_bootstrap_template.txt.
Is this a regression?
Nope. Present since Windows site-packages venv support. (Great feature by the way - saved us with 'awesome' windows path length lmitations)
Description
On Windows, a persistent venv contains a dangling
Lib/site-packages/annotated_types directory symlink into obsolete runfiles (Got obsolete through a python version upgrade).
The next initialization fails at:
os.makedirs(dirname(venv_abs_path), exist_ok=True)
The executable exits before creating the runtime symlink. The Bazel build
succeeds. Expected: replace the dangling link with the required directory.
🔬 Minimal Reproduction
Run this from a rules_python checkout on Windows. It exercises
_create_venv with the blocking state;
import sys
import tempfile
from pathlib import Path
template = Path("python/private/python_bootstrap_template.txt")
source = template.read_text(encoding="utf-8")
for placeholder, value in [
("%shebang%", "#!/usr/bin/env python3"),
("%stage2_bootstrap%", "unused.py"),
("%runtime_venv_symlinks%", ""),
]:
source = source.replace(placeholder, value)
bootstrap = {"__name__": "bootstrap_repro"}
saved_path = sys.path[:]
try:
exec(compile(source, str(template), "exec"), bootstrap)
finally:
sys.path[:] = saved_path
with tempfile.TemporaryDirectory() as temp:
root = Path(temp)
runfiles = root / "runfiles"
old = runfiles / "old/annotated_types"
old.mkdir(parents=True)
(old / "__init__.py").touch()
bootstrap.update(
EXTRACT_ROOT=str(root / "cache"),
PYTHON_BINARY="_main/_process.venv/Scripts/python.exe",
PYTHON_BINARY_ACTUAL=sys.executable,
RESOLVE_PYTHON_BINARY_AT_RUNTIME=False,
RUNTIME_VENV_SYMLINKS={
"Lib/site-packages/annotated_types": "old/annotated_types",
},
)
bootstrap["_create_venv"](str(runfiles), [])
old.rename(root / "retired-package")
new = runfiles / "new/annotated_types"
new.mkdir(parents=True)
(new / "__init__.py").touch()
bootstrap["RUNTIME_VENV_SYMLINKS"] = {
"Lib/site-packages/annotated_types/__init__.py":
"new/annotated_types/__init__.py",
}
bootstrap["_create_venv"](str(runfiles), [])
package = root / "cache/_main/_process.venv/Lib/site-packages/annotated_types"
assert not package.is_symlink()
assert (package / "__init__.py").is_symlink()
print("Cached regular package recovered successfully")
🔥 Exception or Error
File ".../python_bootstrap...", line 909, in main
python_program = _create_venv(runfiles_root, delete_dirs)
File ".../python_bootstrap...", line 657, in _create_venv
os.makedirs(dirname(venv_abs_path), exist_ok=True)
File "<frozen os>", line 228, in makedirs
FileExistsError: [WinError 183]
...\_process.venv\Lib\site-packages\annotated_types
🌍 Your Environment
Operating System: Windows 11 x86_64 (10.0.26200).
Output of bazel version:
Build label: 9.1.1
Rules_python version: c9c1794dab34cc50260cab4a7ddf96f023cff575
Anything else relevant? CPython 3.12.7; Windows symlinks enabled;
persistent RULES_PYTHON_EXTRACT_ROOT.
- 主要语言
- Starlark
- 星标
- 687
- 派生
- 726
- 平均合并
- 1 天 7 小时
- 30 天内合并 PR
- 80
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
bazel-contrib/rules_python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
bazel-contrib/rules_python#4251 · 1 个 reaction ·
维护者通常 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 于 17 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
bazel-contrib/rules_python#3821 ·
维护者通常 1 天内回复
-
难度 5/5 一周以上 新手友好度 20/100
bazel-contrib/rules_python#4250 ·
维护者通常 1 天内回复
-
Bazel 7 native py_binary: startup and import failures with rules_python 2.4.1可能已有人在做 @gleyba 于 7 天前认领。 未关闭
难度 4/5 3-5 天 新手友好度 30/100
bazel-contrib/rules_python#4234 ·
维护者通常 1 天内回复
查看 bazel-contrib/rules_python 的全部 Issue
相似的 Issue
-
bug
难度 1/5 1 小时以内 新手友好度 90/100
维护者通常 1 天内回复
-
good first issue Hacktoberfest
难度 1/5 1 小时以内 新手友好度 90/100
Adnan9-63/life-tracker#43 ·
维护者通常 2 天内回复
-
ci: nothing regenerates the Go contract types, so a hand-edit to types.gen.go passes可能已有人在做 @shaiknoorullah 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 68/100
shaiknoorullah/hg-mono#993 · 2 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 75/100
FormidableLabs/spectacle#1372 ·