From 0b56f28e61389885444062243c6e54d7ad060c02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miro=20Hron=C4=8Dok?= Date: Mon, 31 Jan 2022 14:41:39 +0100 Subject: [PATCH] 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 https://github.com/pypa/virtualenv/issues/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 https://github.com/pypa/build/issues/433 --- src/build/env.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/build/env.py b/src/build/env.py index 80c42d8ed..f77f026a3 100644 --- a/src/build/env.py +++ b/src/build/env.py @@ -293,14 +293,21 @@ def _find_executable_and_scripts(path: str) -> Tuple[str, str, str]: """ config_vars = sysconfig.get_config_vars().copy() # globally cached, copy before altering it config_vars['base'] = path + # 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 https://github.com/pypa/virtualenv/issues/2208 + # # The Python that ships with the macOS developer tools varies the # default scheme depending on whether the ``sys.prefix`` is part of a framework. - # The framework "osx_framework_library" scheme - # can't be used to expand the paths in a venv, which - # can happen if build itself is not installed in a venv. + # But it does not (yet) set the "venv" scheme. # If the Apple-custom "osx_framework_library" scheme is available - # we enforce "posix_prefix", the venv scheme, for isolated envs. - if 'osx_framework_library' in sysconfig.get_scheme_names(): + # we enforce "posix_prefix", instead. + if 'venv' in sysconfig.get_scheme_names(): + paths = sysconfig.get_paths(scheme='venv', vars=config_vars) + elif 'osx_framework_library' in sysconfig.get_scheme_names(): paths = sysconfig.get_paths(scheme='posix_prefix', vars=config_vars) else: paths = sysconfig.get_paths(vars=config_vars)