summaryrefslogtreecommitdiffstats
path: root/Lib/venv
diff options
context:
space:
mode:
authorMiro HronĨok <miro@hroncok.cz>2022-03-18 09:53:29 (GMT)
committerGitHub <noreply@github.com>2022-03-18 09:53:29 (GMT)
commit48d926269963cfe7a49c0a4f34af4fe9b832399b (patch)
treed3fc5c6c1e6b8db9f95eb0fa1987c2738985f654 /Lib/venv
parentcd44afc573e2e2de8d7e5a9119c347373066cd10 (diff)
downloadcpython-48d926269963cfe7a49c0a4f34af4fe9b832399b.zip
cpython-48d926269963cfe7a49c0a4f34af4fe9b832399b.tar.gz
cpython-48d926269963cfe7a49c0a4f34af4fe9b832399b.tar.bz2
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*.
Diffstat (limited to 'Lib/venv')
-rw-r--r--Lib/venv/__init__.py31
1 files changed, 17 insertions, 14 deletions
diff --git a/Lib/venv/__init__.py b/Lib/venv/__init__.py
index b907650..a8640d9 100644
--- a/Lib/venv/__init__.py
+++ b/Lib/venv/__init__.py
@@ -93,6 +93,15 @@ class EnvBuilder:
elif os.path.isdir(fn):
shutil.rmtree(fn)
+ def _venv_path(self, env_dir, name):
+ vars = {
+ 'base': env_dir,
+ 'platbase': env_dir,
+ 'installed_base': env_dir,
+ 'installed_platbase': env_dir,
+ }
+ return sysconfig.get_path(name, scheme='venv', vars=vars)
+
def ensure_directories(self, env_dir):
"""
Create the directories for the environment.
@@ -120,18 +129,12 @@ class EnvBuilder:
context.executable = executable
context.python_dir = dirname
context.python_exe = exename
- if sys.platform == 'win32':
- binname = 'Scripts'
- incpath = 'Include'
- libpath = os.path.join(env_dir, 'Lib', 'site-packages')
- else:
- binname = 'bin'
- incpath = 'include'
- libpath = os.path.join(env_dir, 'lib',
- 'python%d.%d' % sys.version_info[:2],
- 'site-packages')
- context.inc_path = path = os.path.join(env_dir, incpath)
- create_if_needed(path)
+ binpath = self._venv_path(env_dir, 'scripts')
+ incpath = self._venv_path(env_dir, 'include')
+ libpath = self._venv_path(env_dir, 'purelib')
+
+ context.inc_path = incpath
+ create_if_needed(incpath)
create_if_needed(libpath)
# Issue 21197: create lib64 as a symlink to lib on 64-bit non-OS X POSIX
if ((sys.maxsize > 2**32) and (os.name == 'posix') and
@@ -139,8 +142,8 @@ class EnvBuilder:
link_path = os.path.join(env_dir, 'lib64')
if not os.path.exists(link_path): # Issue #21643
os.symlink('lib', link_path)
- context.bin_path = binpath = os.path.join(env_dir, binname)
- context.bin_name = binname
+ context.bin_path = binpath
+ context.bin_name = os.path.relpath(binpath, env_dir)
context.env_exe = os.path.join(binpath, exename)
create_if_needed(binpath)
# Assign and update the command to use when launching the newly created