python / python/cpython

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

オープン
#136,051 コメント 3 件 リアクション 6 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib topic-venv type-feature
主要言語
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
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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

リンクされている相対 pyvenv.cfg に関する PEP 草案と、この issue で説明されている venv モジュールの動作から始め、続いてリンクされている Discourse の議論を確認してください。venv の作成と依存関係のインストールを含め、相対 home パスの全体的な範囲を判断してください。完了とするには、ランタイムのみの変更を超えたホストの移設に対応する、合意済みの設計と実装計画が必要です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
tooling
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
説明が足りない
初心者へのやさしさ
25/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。