-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
Add install scheme for virtual environments #89576
Comments
Python 3.10 introduced sysconfig._get_preferred_schemes[1], a mechanism to allow downstream distributors to overwrite the default install scheme. This presents an issue for projects/people that need to bootstrap virtual environments, like virtualenv (see [2]). As distributors might now be customizing the default install scheme, there is no guarantee that the information returned by sysconfig.get_default_scheme/get_paths is correct for the virtual environment, the only guarantee we have is that it correct for the *current* environment. When bootstrapping a virtual environment, we need to know its layout, so that we can place the files in the correct locations. The usual solution in situations like this would be to invoke the interpreter we are targeting to get the correct information (eg. path/to/python -m sysconfig), but that is not possible here as the environment does not exist yet -- we are the ones trying to create it. To solve this issue, I propose the addition of a "virtual" or "venv" install scheme, for virtual environments. The idea is that virtual environments (defined by the presence of pyvenv.cfg, see [3][4]) will always use this scheme, they will use the paths specified by this scheme and sysconfig.get_default_scheme will always return it (_get_preferred_schemes would have no effect here!). I am not cure if this should be adopted in 3.10 or 3.11, as it effectively makes it impossible to reliably construct virtual environments, and requires workarounds such as [5], that pretty much implements this proposal with non-standardized downstream patches. [1] https://docs.python.org/3/library/sysconfig.html#sysconfig.\_get_preferred_schemes |
The existing install schemes contain values for all different kinds of OSes, somehow named according to them. If we introduce a single "virtual"/"venv" scheme, it would need to have different contents on different OSes (e.g. Windows vs POSIX). I don't think that would cause any actual trouble, but it would be somewhat different than all the other schemes. If we introduce multiple ones (e.g. "posix_venv" and "nt_venv") we would need an additional layer to get the one appropriate for the current platform. Hence, I think having a single one is more pragmatic. |
Yes, we could have several schemes, but I think having only one is more sensible. The implementation would be fairly easy. We would just copy the "nt" scheme if on Windows, otherwise "posix_prefix". |
Starting out with just "venv" doesn't mean we can't add "posix_venv"/"nt_venv" later (if e.g. someone needs to install into a filesystem for another platform). |
I'll try to draft this change for Python 3.11. |
I've created a draft PR in #31034 It is still missing tests and I have not checked it on Windows, hence still a draft. |
The PR is now ready for review. |
I think we want the scheme to be static and accessible on all platforms, like the others. So it probably should be 'nt_venv' and 'posix_venv' with additional/improved logic to help apps determine when they need each. |
I agree. |
Why? (This is a real question, I genuinely don't know.) To put this in context, this has been discussed since October, and there was agreement on how to change it. How can we ensure the decision won't change again? |
All I can say is that I wasn't aware of this discussion, or it blurred into the other discussions and didn't seem to need any attention from me. I definitely don't want to say that I must be consulted on every sysconfig/site/getpath change (because I don't want to be!), but I hesitate to say that this was the wrong way for it to be caught. It's only "too late" after a release has included it, and up until then it's fine. So I guess it can be avoided in the future by checking the surrounding code and seeing how it's used? In this case, the schemes are all approximately static (for a given version of Python), and the *selection* of a scheme is based on the platform. The proposed venv scheme itself is based on the platform, while selection is static. That stands out to me as a difference. |
I don't think the proposal is incompatible with what I discussed. I haven't been super clear on my opinions on the implementation, so let me try to clarify them.
So, my proposal would be to define a single static scheme, and changing the interpreter path initialization logic to hardcode its paths when on virtual environments. Hopefully that clarifies things up a bit. We should sort it out as soon as possible and update the PR, I don't think the PR as-is is the best approach. What do you think? |
I've adapted the PR. See the latest commit (Instead of *venv* scheme, have *posix_venv* and *nt_venv*). |
Steve, could you take a look at the PR discussion and chime in about how this should be done? |
With PR 31034 merged, we can now mark this as resolved. As mentioned in the PR, there are still some concerns about maintainability and avoiding similar issues to happen in the future. That can be done later, as people find time to work on it. Thanks! |
pre-commit doesn't work on Debian Testing after python is upgraded to 3.10. It seems that this issue is only resolved in python 3.11 [4] ``` 1. pre-commit/pre-commit#2299 2. pre-commit/pre-commit#2336 3. https://bugs.launchpad.net/ubuntu/+source/python3.10/+bug/1967920 4. python/cpython#89576 ``` Signed-off-by: Gabor Nagy <[email protected]>
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: