This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author FFY00
Recipients FFY00, gaborjbernat, hroncok, jaraco
Date 2021-10-08.17:50:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1633715402.49.0.434363843275.issue45413@roundup.psfhosted.org>
In-reply-to
Content
Python 3.10 introduced sysconfig._get_preferred_schemes[1], a mechanism to allow downstream distributors to overwrite the default install scheme.
This is done to support downstream modifications where distributors change the installation layout (eg. different site-packages directory). So, distributors will change the default scheme to one that correctly represents their layout.

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!).
This makes it possible to know the virtual environment layout for another interpreter, via sysconfig.get_paths(scheme='virtual').

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
[2] https://github.com/pypa/virtualenv/issues/2208
[3] https://docs.python.org/3/library/site.html?highlight=pyvenv.cfg
[4] https://docs.python.org/3/library/venv.html?highlight=pyvenv.cfg
[5] https://github.com/pypa/virtualenv/pull/2209
History
Date User Action Args
2021-10-08 17:50:02FFY00setrecipients: + FFY00, jaraco, hroncok, gaborjbernat
2021-10-08 17:50:02FFY00setmessageid: <1633715402.49.0.434363843275.issue45413@roundup.psfhosted.org>
2021-10-08 17:50:02FFY00linkissue45413 messages
2021-10-08 17:50:02FFY00create