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

Handle Debian's posix_local scheme #463

Merged
merged 1 commit into from May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
7 changes: 7 additions & 0 deletions src/build/env.py
Expand Up @@ -307,6 +307,13 @@ def _find_executable_and_scripts(path: str) -> Tuple[str, str, str]:
# See https://bugs.python.org/issue45413
# and https://github.com/pypa/virtualenv/issues/2208
paths = sysconfig.get_paths(scheme='venv', vars=config_vars)
elif 'posix_local' in scheme_names:
# The Python that ships on Debian/Ubuntu varies the default scheme to
# install to /usr/local
# But it does not (yet) set the "venv" scheme.
# If we're the Debian "posix_local" scheme is available, but "venv"
# is not, we use "posix_prefix" instead which is venv-compatible there.
paths = sysconfig.get_paths(scheme='posix_prefix', vars=config_vars)
elif 'osx_framework_library' in scheme_names:
# The Python that ships with the macOS developer tools varies the
# default scheme depending on whether the ``sys.prefix`` is part of a framework.
Expand Down
12 changes: 12 additions & 0 deletions tests/test_env.py
Expand Up @@ -5,6 +5,7 @@
import platform
import subprocess
import sys
import sysconfig

import pytest

Expand Down Expand Up @@ -56,6 +57,17 @@ def test_can_get_venv_paths_with_conflicting_default_scheme(mocker):
assert get_scheme_names.call_count == 1


@pytest.mark.skipif('posix_local' not in sysconfig.get_scheme_names(), reason='workaround for Debian/Ubuntu Python')
def test_can_get_venv_paths_with_posix_local_default_scheme(mocker):
get_paths = mocker.spy(sysconfig, 'get_paths')
# We should never call this, but we patch it to ensure failure if we do
get_default_scheme = mocker.patch('sysconfig.get_default_scheme', return_value='posix_local')
with build.env.IsolatedEnvBuilder():
pass
get_paths.assert_called_once_with(scheme='posix_prefix', vars=mocker.ANY)
assert get_default_scheme.call_count == 0


def test_executable_missing_post_creation(mocker):
venv_create = mocker.patch('venv.EnvBuilder.create')
with pytest.raises(RuntimeError, match='Virtual environment creation failed, executable .* missing'):
Expand Down