python / python/cpython

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

Aberta
#136,051 3 comentários 6 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

stdlib topic-venv type-feature
Linguagem predominante
Python
Estrelas
77.2k
Forks
36k
Métricas de merge de PRs
Métricas de PR pendentes

Descrição

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

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

Comece pelo rascunho de PEP vinculado sobre pyvenv.cfg relativos e pelo comportamento do módulo venv descrito nesta issue; em seguida, revise as discussões vinculadas no Discourse. Determine o escopo completo dos caminhos home relativos, incluindo a criação de venv e a instalação de dependências. Para considerar o trabalho concluído, é necessário haver um design acordado e um plano de implementação que tratem da realocação do host além da alteração limitada ao runtime.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
python
Domínio
tooling
Tipo de issue
Funcionalidade
Dificuldade
5/5
Tempo estimado
Mais de uma semana
Status de atividade
Estagnada
Clareza
Precisa de esclarecimento
Facilidade para iniciantes
25/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.