Skip to content

Commit d949df3

Browse files
authored
Merge pull request #93 from FFY00/custom-python
Allow using a custom Python interpreter to run the PEP517 hooks
2 parents ae41d4e + a61aa16 commit d949df3

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

pep517/wrappers.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class Pep517HookCaller(object):
107107
pyproject.toml.
108108
backend_path : The backend path, as per PEP 517, from pyproject.toml.
109109
runner : A callable that invokes the wrapper subprocess.
110+
python_executable : The Python executable used to invoke the backend
110111
111112
The 'runner', if provided, must expect the following:
112113
cmd : a list of strings representing the command and arguments to
@@ -122,6 +123,7 @@ def __init__(
122123
build_backend,
123124
backend_path=None,
124125
runner=None,
126+
python_executable=None,
125127
):
126128
if runner is None:
127129
runner = default_subprocess_runner
@@ -134,6 +136,9 @@ def __init__(
134136
]
135137
self.backend_path = backend_path
136138
self._subprocess_runner = runner
139+
if not python_executable:
140+
python_executable = sys.executable
141+
self.python_executable = python_executable
137142

138143
@contextmanager
139144
def subprocess_runner(self, runner):
@@ -253,7 +258,7 @@ def _call_hook(self, hook_name, kwargs):
253258
# Run the hook in a subprocess
254259
with _in_proc_script_path() as script:
255260
self._subprocess_runner(
256-
[sys.executable, str(script), hook_name, td],
261+
[self.python_executable, str(script), hook_name, td],
257262
cwd=self.source_dir,
258263
extra_environ=extra_environ
259264
)

tests/test_call_hooks.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,18 @@
66
import pytest
77
import toml
88
import zipfile
9+
import sys
910

1011
from mock import Mock
1112

1213
from pep517.wrappers import Pep517HookCaller, default_subprocess_runner
1314
from pep517.wrappers import UnsupportedOperation, BackendUnavailable
1415

16+
17+
if sys.version_info[0] == 2:
18+
FileNotFoundError = IOError
19+
20+
1521
SAMPLES_DIR = pjoin(dirname(abspath(__file__)), 'samples')
1622
BUILDSYS_PKGS = pjoin(SAMPLES_DIR, 'buildsys_pkgs')
1723

@@ -131,3 +137,17 @@ def test_runner_replaced_on_exception(monkeypatch):
131137

132138
hooks.get_requires_for_build_wheel()
133139
runner.assert_called_once()
140+
141+
142+
def test_custom_python_executable(monkeypatch, tmpdir):
143+
monkeypatch.setenv('PYTHONPATH', BUILDSYS_PKGS)
144+
145+
runner = Mock(autospec=default_subprocess_runner)
146+
hooks = get_hooks('pkg1', runner=runner, python_executable='some-python')
147+
148+
with hooks.subprocess_runner(runner):
149+
with pytest.raises(FileNotFoundError):
150+
# output.json is missing because we didn't actually run the hook
151+
hooks.get_requires_for_build_wheel()
152+
runner.assert_called_once()
153+
assert runner.call_args[0][0][0] == 'some-python'

0 commit comments

Comments
 (0)