Skip to content

Commit 211bd2f

Browse files
committed
env._find_executable_and_scripts(): Prefer the venv installation scheme if it exists
Python distributors with custom default installation scheme can set a scheme that can't be used to expand the paths in a venv. This can happen if build itself is not installed in a venv. The distributors are encouraged to set a "venv" scheme to be used for this. See https://bugs.python.org/issue45413 and pypa/virtualenv#2208 Since Python that ships with the macOS developer tools does not have the "venv" scheme yet, we keep the special case below. Once it gains the "venv" scheme, it will be preferred. Fixes pypa#433
1 parent 96f9188 commit 211bd2f

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

src/build/env.py

+13-6
Original file line numberDiff line numberDiff line change
@@ -293,14 +293,21 @@ def _find_executable_and_scripts(path: str) -> Tuple[str, str, str]:
293293
"""
294294
config_vars = sysconfig.get_config_vars().copy() # globally cached, copy before altering it
295295
config_vars['base'] = path
296+
# Python distributors with custom default installation scheme can set a
297+
# scheme that can't be used to expand the paths in a venv.
298+
# This can happen if build itself is not installed in a venv.
299+
# The distributors are encouraged to set a "venv" scheme to be used for this.
300+
# See https://bugs.python.org/issue45413
301+
# and https://github.com/pypa/virtualenv/issues/2208
302+
#
296303
# The Python that ships with the macOS developer tools varies the
297304
# default scheme depending on whether the ``sys.prefix`` is part of a framework.
298-
# The framework "osx_framework_library" scheme
299-
# can't be used to expand the paths in a venv, which
300-
# can happen if build itself is not installed in a venv.
301-
# If the Apple-custom "osx_framework_library" scheme is available
302-
# we enforce "posix_prefix", the venv scheme, for isolated envs.
303-
if 'osx_framework_library' in sysconfig.get_scheme_names():
305+
# But it does not (yet) set the "venv" scheme.
306+
# If the Apple-custom "osx_framework_library" scheme is available but "venv"
307+
# is not, we use "posix_prefix" instead which is venv-compatible there.
308+
if 'venv' in sysconfig.get_scheme_names():
309+
paths = sysconfig.get_paths(scheme='venv', vars=config_vars)
310+
elif 'osx_framework_library' in sysconfig.get_scheme_names():
304311
paths = sysconfig.get_paths(scheme='posix_prefix', vars=config_vars)
305312
else:
306313
paths = sysconfig.get_paths(vars=config_vars)

0 commit comments

Comments
 (0)