python / python/cpython

Support relative home in pyvenv.cfg (host-relocatable venv)

未關閉
#136,051 3 則留言 6 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

stdlib topic-venv type-feature
主要語言
Python
星號
77.2k
分支
36k
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
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

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

先從連結的相對 pyvenv.cfg PEP 草案以及本 issue 中描述的 venv 模組行為開始,然後檢視連結的 Discourse 討論。確定相對 home 路徑的完整範圍,包括 venv 建立和相依套件安裝。完成的要求是:達成一致的設計和實作計畫,並處理超出僅執行階段變更範圍的主機遷移問題。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
tooling
Issue 類型
功能
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
需要釐清
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。