bpo-45413: Define "posix_venv", "nt_venv" and "venv" sysconfig installation schemes (GH-31034)

Define *posix_venv* and *nt_venv* sysconfig installation schemes
to be used for bootstrapping new virtual environments.
Add *venv* sysconfig installation scheme to get the appropriate one of the above.
The schemes are identical to the pre-existing
*posix_prefix* and *nt* install schemes.
The venv module now uses the *venv* scheme to create new virtual environments
instead of hardcoding the paths depending only on the platform. Downstream
Python distributors customizing the *posix_prefix* or *nt* install
scheme in a way that is not compatible with the install scheme used in
virtual environments are encouraged not to customize the *venv* schemes.
When Python itself runs in a virtual environment,
sysconfig.get_default_scheme and
sysconfig.get_preferred_scheme with `key="prefix"` returns
*venv*.
This commit is contained in:
Miro Hrončok 2022-03-18 10:53:29 +01:00 committed by GitHub
parent cd44afc573
commit 48d9262699
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 211 additions and 16 deletions

View file

@ -73,7 +73,7 @@ Every new component that is installed using :mod:`distutils` or a
Distutils-based system will follow the same scheme to copy its file in the right
places.
Python currently supports six schemes:
Python currently supports nine schemes:
- *posix_prefix*: scheme for POSIX platforms like Linux or macOS. This is
the default scheme used when Python or a component is installed.
@ -83,8 +83,14 @@ Python currently supports six schemes:
- *posix_user*: scheme for POSIX platforms used when a component is installed
through Distutils and the *user* option is used. This scheme defines paths
located under the user home directory.
- *posix_venv*: scheme for :mod:`Python virtual environments <venv>` on POSIX
platforms; by default it is the same as *posix_prefix* .
- *nt*: scheme for NT platforms like Windows.
- *nt_user*: scheme for NT platforms, when the *user* option is used.
- *nt_venv*: scheme for :mod:`Python virtual environments <venv>` on NT
platforms; by default it is the same as *nt* .
- *venv*: a scheme with values from ether *posix_venv* or *nt_venv* depending
on the platform Python runs on
- *osx_framework_user*: scheme for macOS, when the *user* option is used.
Each scheme is itself composed of a series of paths and each path has a unique
@ -119,6 +125,9 @@ identifier. Python currently uses eight paths:
This function was previously named ``_get_default_scheme()`` and
considered an implementation detail.
.. versionchanged:: 3.11
When Python runs from a virtual environment,
the *venv* scheme is returned.
.. function:: get_preferred_scheme(key)
@ -132,6 +141,10 @@ identifier. Python currently uses eight paths:
.. versionadded:: 3.10
.. versionchanged:: 3.11
When Python runs from a virtual environment and ``key="prefix"``,
the *venv* scheme is returned.
.. function:: _get_preferred_schemes()

View file

@ -177,6 +177,11 @@ creation according to their needs, the :class:`EnvBuilder` class.
``clear=True``, contents of the environment directory will be cleared
and then all necessary subdirectories will be recreated.
.. versionchanged:: 3.11
The *venv*
:ref:`sysconfig installation scheme <installation_paths>`
is used to construct the paths of the created directories.
.. method:: create_configuration(context)
Creates the ``pyvenv.cfg`` configuration file in the environment.