Creating a venv can run a local ensurepip.py
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start by reproducing the report with the supplied script on a tested CPython version, then trace how venv invokes ensurepip during environment creation. The issue links PR gh-160282, indicating work is already underway; the desired result is that a local .venv/ensurepip.py is not executed across the listed cases.
由索引模型根据 Issue 内容生成。
描述
Bug report
When you run python -m venv .venv, and .venv/ensurepip.py already exists, the file gets run.
Repro script:
import os
from pathlib import Path
import subprocess
import sys
from tempfile import TemporaryDirectory
with TemporaryDirectory() as name:
root = Path(name)
home = root / "private"
home.mkdir(mode=0o700)
env = {k: v for k, v in os.environ.items() if not k.startswith("PYTHON")}
env["PIP_NO_INDEX"] = "1"
cases = [
("normal", [], [], True),
("isolated", ["-I"], [], True),
("without-pip", ["-I"], ["--without-pip"], False),
("clear-regular-directory", ["-I"], ["--clear"], False),
]
if len(sys.argv) > 1:
cases.append(("vscode", ["-I"], [], True))
for case, interpreter_options, venv_options, expected in cases:
project = root / case
target = project / ".venv"
target.mkdir(parents=True)
marker = home / case
(target / "ensurepip.py").write_text(
"import os, runpy, sys\n"
"from pathlib import Path\n"
f"Path({str(marker)!r}).write_text('bootstrap executed')\n"
"sys.path[:] = [s for s in sys.path if os.path.realpath(s) != os.getcwd()]\n"
"runpy.run_module('ensurepip', run_name='__main__')\n"
)
if case == "vscode":
arguments = [str(Path(sys.argv[1]).resolve())]
else:
arguments = ["-m", "venv", *venv_options, ".venv"]
command = [sys.executable, *interpreter_options, *arguments]
subprocess.run(command, env=env, cwd=project, check=True, timeout=90)
print(case, "marker", marker.exists(), flush=True)
assert marker.exists() is expected
CPython versions tested on:
3.12, 3.13, CPython main branch
Operating systems tested on:
macOS, Linux
Linked PRs
- gh-160282
- 主要语言
- Python
- 星标
- 77.7k
- 派生
- 38.3k
- 平均合并
- 11 小时 58 分钟
- 30 天内合并 PR
- 672
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python/cpython 的其他 Issue
-
topic-socket type-bug
难度 2/5 1-3 小时 新手友好度 72/100
python/cpython#160561 · 7 条评论 ·
维护者通常 1 天内回复
-
tests topic-profiling type-bug
难度 2/5 1-3 小时 新手友好度 78/100
python/cpython#160334 · 1 条评论 ·
维护者通常 1 天内回复
-
extension-modules type-bug
难度 2/5 1-3 小时 新手友好度 84/100
维护者通常 1 天内回复
-
interpreter-core type-feature
难度 1/5 1 小时以内 新手友好度 78/100
python/cpython#160109 · 1 条评论 ·
维护者通常 1 天内回复
-
extension-modules type-bug
难度 2/5 1-3 小时 新手友好度 72/100
python/cpython#160001 · 3 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 68/100
Arekkazu/sgpmp-backend#744 ·
维护者通常 1 天内回复
-
agent/reviewer
难度 2/5 1-3 小时 新手友好度 78/100
projectbluefin/utah-packages#634 ·
维护者通常 1 天内回复
-
enhancement good first issue help wanted
难度 2/5 1-2 天 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
home-assistant/core#188613 ·
维护者通常 1 天内回复
-
Website未关闭good first issue
难度 2/5 1-3 小时 新手友好度 91/100
TanbirRamim/open-source-radar#314 ·
维护者通常 1 天内回复