Skip to content
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

bpo-45413: Define "posix_venv", "nt_venv" and "venv" sysconfig installation schemes #31034

Merged
merged 20 commits into from
Mar 18, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
912f823
bpo-45413: Define a "venv" sysconfig installation scheme
hroncok Jan 31, 2022
4686893
Use the same conditional as previously in venv
hroncok Jan 31, 2022
6e98457
Use os.sep
hroncok Jan 31, 2022
602c2ad
A bit better wording of the comment
hroncok Feb 1, 2022
44f588a
Add a test that the venv scheme does not regress from the previously …
hroncok Feb 1, 2022
8af07ee
Revert "Use the same conditional as previously in venv"
hroncok Feb 1, 2022
c734658
venv: Resolve paths with env_dir as all bases
hroncok Feb 1, 2022
0a8556d
Optional: When we are in virtual environment, sysconfig.get_default_s…
hroncok Feb 1, 2022
cb2ed5b
Also return venv from get_preferred_scheme()
hroncok Feb 2, 2022
af47953
Rename binname to binpath in test for consistency with other names
hroncok Feb 2, 2022
4cc4015
Add documentation and what's new
hroncok Feb 2, 2022
5d04c22
Also mention this change in What's new for venv
hroncok Feb 2, 2022
5f35cd8
Sysconfig docs: The venv scheme is also for running virtual environments
hroncok Feb 2, 2022
e7444a2
Typo
hroncok Feb 2, 2022
30fdee3
Assert the preferred(prefix) and default sysconfig install scheme in …
hroncok Feb 2, 2022
27ce189
Instead of *venv* scheme, have *posix_venv* and *nt_venv*
hroncok Feb 17, 2022
6297449
Apply suggestions from language review
hroncok Mar 3, 2022
283db7a
Drop get_venv_scheme() in favor of *venv* scheme
hroncok Mar 17, 2022
594c4d9
Apply my own suggestions from docs review
hroncok Mar 17, 2022
9890918
Typo
hroncok Mar 17, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Lib/sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,28 @@
},
}

# Downstream distributors can 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. 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
# a 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 "venv" install scheme is a scheme to bootstrap virtual environments,
# essentially identical to the default posix_prefix/nt schemes.
# Downstream distributors will need to change this,
# if their posix_prefix/nt scheme is not venv-compatible.
if sys.platform == 'win32':
hroncok marked this conversation as resolved.
Show resolved Hide resolved
_INSTALL_SCHEMES['venv'] = dict(_INSTALL_SCHEMES['nt'])
else:
_INSTALL_SCHEMES['venv'] = dict(_INSTALL_SCHEMES['posix_prefix'])


# NOTE: site.py has copy of this function.
# Sync it when modify this function.
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_sysconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ def test_get_config_h_filename(self):
self.assertTrue(os.path.isfile(config_h), config_h)

def test_get_scheme_names(self):
wanted = ['nt', 'posix_home', 'posix_prefix']
wanted = ['nt', 'posix_home', 'posix_prefix', 'venv']
if HAS_USER_BASE:
wanted.extend(['nt_user', 'osx_framework_user', 'posix_user'])
self.assertEqual(get_scheme_names(), tuple(sorted(wanted)))
Expand Down
17 changes: 7 additions & 10 deletions Lib/venv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
CORE_VENV_DEPS = ('pip', 'setuptools')
logger = logging.getLogger(__name__)

def _venv_path(name):
return sysconfig.get_path(name, scheme='venv').removeprefix(sys.prefix + os.sep)
hroncok marked this conversation as resolved.
Show resolved Hide resolved


class EnvBuilder:
"""
Expand Down Expand Up @@ -120,16 +123,10 @@ def create_if_needed(d):
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')
binname = _venv_path('scripts')
incpath = _venv_path('include')
libpath = os.path.join(env_dir, _venv_path('purelib'))

context.inc_path = path = os.path.join(env_dir, incpath)
create_if_needed(path)
create_if_needed(libpath)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Define a ``"venv"`` :mod:`sysconfig` installation scheme to be used for
bootstrapping new virtual environments. It is a copy of the
``"posix_prefix"`` or ``"nt"`` install scheme depending on the platform. The
:mod:`venv` module now uses that 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 to supply a modified working ``"venv"``
scheme.