Support relative home in pyvenv.cfg (host-relocatable venv)
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Feature or enhancement
Proposal:
The central idea is to allow a venv to be relocatable between different hosts by using a relative path in pyvenv.cfg for the home value. Relative paths allow avoiding use of an absolute path that is likely host-specific. Concretely, I propose making a relative home value relative to the pyvenv.cfg file.
Today, the home key is officially documented to be an absolute path. If a relative path is used, then official behavior is undefined. In practice, it is treated as relative to the current working directory (so, in effect, could be anywhere). (By omitting the home key entirely (https://github.com/python/cpython/issues/135773), it gets computed based on the bin/python3 symlink, but this is undesirable behavior).
I think there's a variety of things this enables or otherwise makes much simpler. The main one that comes to mind is that multiple venvs can efficiently share a runtime (while still being host-relocatable). Not needing a system Python itself to create the venv is another benefit. The explicitly looser coupling between the venv and system state (i.e where the desired Python is) is also appealing.
For the runtime itself, making relative home paths work is simple and about 2 lines. See https://github.com/python/cpython/compare/main...rickeylev:cpython:feat.relative.pyvenv.home
As the python-ideas discussion points out, other parts of venv creation and dependency installation would also need to be aware of this.
I expect a PEP will be requested, so I'll start on that and put more details there rather than here.
Parties that should probably be part of the discussion:
- rules_python: @rickeylev @aignas @groodt
- rules_py: @alexeagle @arrdem
- uv owners
- python venv module owners
- pip owners
Related
- PEP 711 (self contained application zip files)
uv venv --relocatable. From a cursory look, the basic thing it does is generate "relative aware" scripts inbin/and put arelocatable=truesetting in pyvenv.cfg.- python-build-standalone relocatable python installation
- relative pyvenv.cfg PEP draft: https://github.com/python/peps/pull/4476
Has this already been discussed elsewhere?
I have already discussed this feature proposal on Discourse
Links to previous discussion of this feature:
https://discuss.python.org/t/making-venvs-relocatable-friendly/96177
https://discuss.python.org/t/q-what-stops-a-venv-from-being-relocatable/57166
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
先从链接的相对 pyvenv.cfg PEP 草案以及本 issue 中描述的 venv 模块行为开始,然后查看链接的 Discourse 讨论。确定相对 home 路径的完整范围,包括 venv 创建和依赖项安装。完成的要求是:达成一致的设计和实现计划,并处理超出仅运行时变更范围的主机迁移问题。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- tooling
- Issue 类型
- 功能
- 难度
- 5/5
- 预计耗时
- 一周以上
- 活跃度
- 停滞
- 描述清晰度
- 需要澄清
- 新手友好度
- 25/100