New submission from Filipe Laíns <la...@riseup.net>:

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

----------
assignee: FFY00
messages: 403485
nosy: FFY00, gaborjbernat, hroncok, jaraco
priority: normal
severity: normal
status: open
title: Add install scheme for virtual environment
type: enhancement
versions: Python 3.10, Python 3.11

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45413>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to