Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit f7a5321

Browse files
committedMay 16, 2019
Fixed result of tox_get_python_executable not being used to make virtualenvs
1 parent 666f6cd commit f7a5321

File tree

4 files changed

+34
-0
lines changed

4 files changed

+34
-0
lines changed
 

‎CONTRIBUTORS

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Allan Feldman
66
Andrii Soldatenko
77
Anthon van der Neuth
88
Anthony Sottile
9+
Ashley Whetter
910
Asmund Grammeltwedt
1011
Barry Warsaw
1112
Bartolome Sanchez Salado

‎src/tox/interpreters.py

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ def run_and_get_interpreter_info(name, executable):
6767
result["version_info"] = tuple(result["version_info"]) # fix json dump transformation
6868
del result["name"]
6969
del result["version"]
70+
result["executable"] = str(executable)
7071
except ExecFailed as e:
7172
return NoInterpreterInfo(name, executable=e.executable, out=e.out, err=e.err)
7273
else:

‎src/tox/logs/env.py

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ def set_python_info(self, python_executable):
2020
cmd = [str(python_executable), VERSION_QUERY_SCRIPT]
2121
result = subprocess.check_output(cmd, universal_newlines=True)
2222
answer = json.loads(result)
23+
answer["executable"] = python_executable
2324
self.dict["python"] = answer
2425

2526
def get_commandlog(self, name):

‎tests/unit/test_interpreters.py

+31
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1+
from __future__ import unicode_literals
2+
13
import os
4+
import stat
25
import subprocess
36
import sys
47

@@ -137,6 +140,34 @@ class envconfig:
137140
assert not info.executable
138141
assert isinstance(info, NoInterpreterInfo)
139142

143+
@pytest.mark.skipif("sys.platform == 'win32'", reason="Uses a unix only wrapper")
144+
def test_get_info_uses_hook_path(self, tmp_path):
145+
magic = tmp_path / "magic{}".format(os.path.splitext(sys.executable)[1])
146+
wrapper = (
147+
"#!{executable}\n"
148+
"import subprocess\n"
149+
"import sys\n"
150+
"sys.exit(subprocess.call([\"{executable}\"] + sys.argv[1:]))\n"
151+
).format(executable=sys.executable)
152+
magic.write_text(wrapper)
153+
magic.chmod(magic.stat().st_mode | stat.S_IEXEC)
154+
155+
class MockHook:
156+
def tox_get_python_executable(self, envconfig):
157+
return str(magic)
158+
159+
class envconfig:
160+
basepython = sys.executable
161+
envname = "magicpy"
162+
163+
# Check that the wrapper is working first.
164+
# If it isn't, the default is to return the passed path anyway.
165+
subprocess.check_call([str(magic), "--help"])
166+
167+
interpreters = Interpreters(hook=MockHook())
168+
info = interpreters.get_info(envconfig)
169+
assert info.executable == str(magic)
170+
140171
def test_get_sitepackagesdir_error(self, interpreters):
141172
class envconfig:
142173
basepython = sys.executable

0 commit comments

Comments
 (0)
Please sign in to comment.