summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshley Whetter <AWhetter@users.noreply.github.com>2019-05-16 02:14:49 -0700
committerBernát Gábor <bgabor8@bloomberg.net>2019-05-16 10:14:49 +0100
commita8b34cc5690cef34fa91ca0f1950a1fdde0f8b72 (patch)
tree1f6b34eaa44bd8663d172cb3fa689d9c36d42aa1
parent666f6cd38c5e587620d2d4e8bc9697056010a014 (diff)
downloadtox-git-a8b34cc5690cef34fa91ca0f1950a1fdde0f8b72.tar.gz
Fixed result of tox_get_python_executable not being used to make virtualenvs (#1301)
* Fixed result of tox_get_python_executable not being used to make virtualenvs * fix formatting and add changelog
-rw-r--r--CONTRIBUTORS1
-rw-r--r--docs/changelog/1301.bugfix.rst1
-rw-r--r--src/tox/interpreters.py1
-rw-r--r--src/tox/logs/env.py1
-rw-r--r--tests/unit/test_interpreters.py31
5 files changed, 35 insertions, 0 deletions
diff --git a/CONTRIBUTORS b/CONTRIBUTORS
index e3301f9f..fcd11b18 100644
--- a/CONTRIBUTORS
+++ b/CONTRIBUTORS
@@ -6,6 +6,7 @@ Allan Feldman
Andrii Soldatenko
Anthon van der Neuth
Anthony Sottile
+Ashley Whetter
Asmund Grammeltwedt
Barry Warsaw
Bartolome Sanchez Salado
diff --git a/docs/changelog/1301.bugfix.rst b/docs/changelog/1301.bugfix.rst
new file mode 100644
index 00000000..c666827f
--- /dev/null
+++ b/docs/changelog/1301.bugfix.rst
@@ -0,0 +1 @@
+When creating virtual environments we no longer ask the python to tell its path, but rather use the discovered path.
diff --git a/src/tox/interpreters.py b/src/tox/interpreters.py
index 23be42d6..14f9eb42 100644
--- a/src/tox/interpreters.py
+++ b/src/tox/interpreters.py
@@ -67,6 +67,7 @@ def run_and_get_interpreter_info(name, executable):
result["version_info"] = tuple(result["version_info"]) # fix json dump transformation
del result["name"]
del result["version"]
+ result["executable"] = str(executable)
except ExecFailed as e:
return NoInterpreterInfo(name, executable=e.executable, out=e.out, err=e.err)
else:
diff --git a/src/tox/logs/env.py b/src/tox/logs/env.py
index bbdc0be5..f134440a 100644
--- a/src/tox/logs/env.py
+++ b/src/tox/logs/env.py
@@ -20,6 +20,7 @@ class EnvLog(object):
cmd = [str(python_executable), VERSION_QUERY_SCRIPT]
result = subprocess.check_output(cmd, universal_newlines=True)
answer = json.loads(result)
+ answer["executable"] = python_executable
self.dict["python"] = answer
def get_commandlog(self, name):
diff --git a/tests/unit/test_interpreters.py b/tests/unit/test_interpreters.py
index 1eba27eb..e7928cf7 100644
--- a/tests/unit/test_interpreters.py
+++ b/tests/unit/test_interpreters.py
@@ -1,4 +1,7 @@
+from __future__ import unicode_literals
+
import os
+import stat
import subprocess
import sys
@@ -137,6 +140,34 @@ class TestInterpreters:
assert not info.executable
assert isinstance(info, NoInterpreterInfo)
+ @pytest.mark.skipif("sys.platform == 'win32'", reason="Uses a unix only wrapper")
+ def test_get_info_uses_hook_path(self, tmp_path):
+ magic = tmp_path / "magic{}".format(os.path.splitext(sys.executable)[1])
+ wrapper = (
+ "#!{executable}\n"
+ "import subprocess\n"
+ "import sys\n"
+ 'sys.exit(subprocess.call(["{executable}"] + sys.argv[1:]))\n'
+ ).format(executable=sys.executable)
+ magic.write_text(wrapper)
+ magic.chmod(magic.stat().st_mode | stat.S_IEXEC)
+
+ class MockHook:
+ def tox_get_python_executable(self, envconfig):
+ return str(magic)
+
+ class envconfig:
+ basepython = sys.executable
+ envname = "magicpy"
+
+ # Check that the wrapper is working first.
+ # If it isn't, the default is to return the passed path anyway.
+ subprocess.check_call([str(magic), "--help"])
+
+ interpreters = Interpreters(hook=MockHook())
+ info = interpreters.get_info(envconfig)
+ assert info.executable == str(magic)
+
def test_get_sitepackagesdir_error(self, interpreters):
class envconfig:
basepython = sys.executable