python / python/cpython

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

Aperta
#136,051 3 commenti 6 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

stdlib topic-venv type-feature
Lingua principale
Python
Stelle
77.2k
Fork
35.9k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dalla bozza di PEP collegata relativa a pyvenv.cfg relativi e al comportamento del modulo venv descritto in questa issue, quindi esamina le discussioni Discourse collegate. Determina l’ambito completo dei percorsi home relativi, inclusi la creazione di venv e l’installazione delle dipendenze. Il lavoro sarà considerato completato quando saranno disponibili un design concordato e un piano di implementazione che affrontino la rilocazione dell’host oltre la modifica limitata al runtime.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
python
Ambito
tooling
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.