Skip to content

Commit

Permalink
env: handle Debian's posix_local scheme
Browse files Browse the repository at this point in the history
The issue and solution is the same as OSX.
The venv scheme wasn't standardised yet, so it's not using it yet.
  • Loading branch information
stefanor authored and FFY00 committed May 2, 2022
1 parent 0b40b40 commit cb36fa9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
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

0 comments on commit cb36fa9

Please sign in to comment.