Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion pep517/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ class Pep517HookCaller(object):
pyproject.toml.
backend_path : The backend path, as per PEP 517, from pyproject.toml.
runner : A callable that invokes the wrapper subprocess.
python_executable : The Python executable used to invoke the backend

The 'runner', if provided, must expect the following:
cmd : a list of strings representing the command and arguments to
Expand All @@ -131,6 +132,7 @@ def __init__(
build_backend,
backend_path=None,
runner=None,
python_executable=None,
):
if runner is None:
runner = default_subprocess_runner
Expand All @@ -143,6 +145,9 @@ def __init__(
]
self.backend_path = backend_path
self._subprocess_runner = runner
if not python_executable:
python_executable = sys.executable
self.python_executable = python_executable

@contextmanager
def subprocess_runner(self, runner):
Expand Down Expand Up @@ -262,7 +267,7 @@ def _call_hook(self, hook_name, kwargs):
# Run the hook in a subprocess
with _in_proc_script_path() as script:
self._subprocess_runner(
[sys.executable, str(script), hook_name, td],
[self.python_executable, str(script), hook_name, td],
cwd=self.source_dir,
extra_environ=extra_environ
)
Expand Down
20 changes: 20 additions & 0 deletions tests/test_call_hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
import pytest
import toml
import zipfile
import sys

from mock import Mock

from pep517.wrappers import Pep517HookCaller, default_subprocess_runner
from pep517.wrappers import UnsupportedOperation, BackendUnavailable


if sys.version_info[0] == 2:
FileNotFoundError = IOError


SAMPLES_DIR = pjoin(dirname(abspath(__file__)), 'samples')
BUILDSYS_PKGS = pjoin(SAMPLES_DIR, 'buildsys_pkgs')

Expand Down Expand Up @@ -131,3 +137,17 @@ def test_runner_replaced_on_exception(monkeypatch):

hooks.get_requires_for_build_wheel()
runner.assert_called_once()


def test_custom_python_executable(monkeypatch, tmpdir):
monkeypatch.setenv('PYTHONPATH', BUILDSYS_PKGS)

runner = Mock(autospec=default_subprocess_runner)
hooks = get_hooks('pkg1', runner=runner, python_executable='some-python')

with hooks.subprocess_runner(runner):
with pytest.raises(FileNotFoundError):
# output.json is missing because we didn't actually run the hook
hooks.get_requires_for_build_wheel()
runner.assert_called_once()
assert runner.call_args[0][0][0] == 'some-python'