Skip to content

Replace pyvenv.cfg's home key with base-prefix and base-exec-prefix #127895

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
FFY00 opened this issue Dec 12, 2024 · 4 comments
Open

Replace pyvenv.cfg's home key with base-prefix and base-exec-prefix #127895

FFY00 opened this issue Dec 12, 2024 · 4 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-venv Related to the venv module type-feature A feature request or enhancement

Comments

@FFY00
Copy link
Member

FFY00 commented Dec 12, 2024

Feature or enhancement

Proposal:

The home key in pyvenv.cfg is used to specify the directory where the base Python executable is. During the Path Initialization, this directory, and consecutively its parents, is searched for stdlib landmarks to determine sys.base_prefix and sys.base_exec_prefix. Naturally, this isn't ideal, it would be better if pyvenv.cfg contained these values directly.

Proposed plan:

  • Update venv to start setting the base-prefix and base-exec-prefix keys in pyvenv.cfg when creating/updating environments
  • In getpath, use the base-prefix and base-exec-prefix keys to set the prefixes
  • Deprecate specifying home, in pyvenv.cfg

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

@FFY00 FFY00 added type-feature A feature request or enhancement interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-venv Related to the venv module labels Dec 12, 2024
@FFY00
Copy link
Member Author

FFY00 commented Dec 12, 2024

Optionally, we can also maybe add base-executable, to initialize sys._base_executable.

@pelson
Copy link
Contributor

pelson commented Jan 9, 2025

I also independently advocated for this yesterday in #106045 (comment). I then realised that these heuristics are also being used for non-venv based prefix determination, and now appreciate that when running a plain CPython interpreter, all you have is the executable path (plus a sysconfig full of paths for where Python was built) and heuristics are seemingly still necessary.

If we could remove the need for the core interpreter heuristics (e.g. by only using the build config), then I think we should also remove the heuristics from venv exec/prefix determination.

On the other hand, if we don't manage to remove the heuristics at the core, then I would advocate for removing home and replacing it with base-executable, since ultimately that is what is important from a venv path determination perspective.

All of this sounds like it needs a change to PEP-405 though?

@charliermarsh
Copy link

charliermarsh commented Jan 11, 2025

FWIW, I believe I agree with this, based on my experience computing home in uv.

@mayeut
Copy link

mayeut commented Jan 12, 2025

Optionally, we can also maybe add base-executable

I wonder if it wouldn't be required for venv launchers anyway (if not required, it would certainly simplify various paths computations in those launchers).
If this gets exposed, it should be made public.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-venv Related to the venv module type-feature A feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants