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

env._find_executable_and_scripts(): Prefer the venv installation scheme if it exists #434

Merged
merged 3 commits into from Mar 18, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 13 additions & 6 deletions src/build/env.py
Expand Up @@ -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.
Copy link
Member

@layday layday Jan 31, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this is relevant or something that distributors should be doing, varying the scheme at runtime depending on the prefix.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is the reality. We need to do that. See mostly https://bugs.python.org/issue43976

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately, this was made possible with the introduction of sysconfig._get_preferred_schemes in 3.10, so something like this is needed.

# 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.
# 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():
# But it does not (yet) set the "venv" scheme.
# If the Apple-custom "osx_framework_library" scheme is available but "venv"
# is not, we use "posix_prefix" instead which is venv-compatible there.
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():
hroncok marked this conversation as resolved.
Show resolved Hide resolved
paths = sysconfig.get_paths(scheme='posix_prefix', vars=config_vars)
else:
paths = sysconfig.get_paths(vars=config_vars)
Expand Down