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 · 7 comments
Open

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

FFY00 opened this issue Dec 12, 2024 · 7 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.

@brettcannon
Copy link
Member

I'm not sure if @vsajip has an opinion on this. I'm personally fine with the proposal (including adding base-executable).

@vsajip
Copy link
Member

vsajip commented May 31, 2025

I have no problems with it either.

@pelson
Copy link
Contributor

pelson commented Jun 2, 2025

I believe there are two proposals on the table:

  • (Original proposal): setting the base-prefix and base-exec-prefix keys in pyvenv.cfg. Additionally setting base-executable. Deprecate home.
  • (My adapted proposal): setting base-executable, not setting base-exec-prefix and base-prefix and, as as argued above, use the same logic that is used for the normal startup sequence to determine them. Deprecate home.

My proposal avoids the redundancy of setting both base-exec-prefix and base-executable, and does not seek to introduce the ability to control the prefix independently of the exec-prefix (which is not possible with PEP-405, but may be one of the motivations of the original proposal? ).

Either approach is an improvement on the existing home mechanism IMO (since we no longer need to guess the executable so that we can proceed to guess the prefix and exec-prefix), and I'd be happy to take on the work, especially if there is somebody who would be willing to provide some mentorship (this would be my first CPython change which deprecates something specified in a PEP).

I note that PEP-405 states:

If a home key is found, this signifies that the Python binary belongs to a virtual environment, and the value of the home key is the directory containing the Python executable used to create this virtual environment.

I think this would need to be changed according to the proposals above (since I don't think this would take precedence over base-executable, if found).

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

6 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy