summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBernát Gábor <bgabor8@bloomberg.net>2020-02-11 14:24:02 +0000
committerGitHub <noreply@github.com>2020-02-11 14:24:02 +0000
commitb577bfd31309ef20d3c2ee226f4e4d03f81fd893 (patch)
tree994c1031e555876f1863cdeedaabbd59deca0d8f
parent38460574703c3f0047474a35b292520da8afa402 (diff)
downloadvirtualenv-b577bfd31309ef20d3c2ee226f4e4d03f81fd893.tar.gz
on exe discovery ignore incorrect interpreters, also try in the… (#1573)
Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
-rw-r--r--docs/changelog/1545.bugfix.rst6
-rw-r--r--src/virtualenv/discovery/py_info.py7
-rw-r--r--tests/unit/discovery/py_info/test_py_info.py7
3 files changed, 18 insertions, 2 deletions
diff --git a/docs/changelog/1545.bugfix.rst b/docs/changelog/1545.bugfix.rst
new file mode 100644
index 0000000..ce432d7
--- /dev/null
+++ b/docs/changelog/1545.bugfix.rst
@@ -0,0 +1,6 @@
+Improve python discovery mechanism:
+
+- do not fail if there are executables that fail to query (e.g. for not having execute access to it) on the ``PATH``,
+- beside the prefix folder also try with the platform dependent binary folder within that,
+
+by :user:`gaborbernat`.
diff --git a/src/virtualenv/discovery/py_info.py b/src/virtualenv/discovery/py_info.py
index eb15341..211778c 100644
--- a/src/virtualenv/discovery/py_info.py
+++ b/src/virtualenv/discovery/py_info.py
@@ -338,7 +338,9 @@ class PythonInfo(object):
for name in possible_names:
exe_path = os.path.join(folder, name)
if os.path.exists(exe_path):
- info = self.from_exe(exe_path, resolve_to_host=False)
+ info = self.from_exe(exe_path, resolve_to_host=False, raise_on_error=False)
+ if info is None: # ignore if for some reason we can't query
+ continue
for item in ["implementation", "architecture", "version_info"]:
found = getattr(info, item)
searched = getattr(self, item)
@@ -411,6 +413,9 @@ class PythonInfo(object):
# or at root level
candidate_folder[inside_folder] = None
+ if self.executable.startswith(self.prefix):
+ binary_within = os.path.relpath(os.path.dirname(self.executable), self.prefix)
+ candidate_folder[os.path.join(inside_folder, binary_within)] = None
return list(candidate_folder.keys())
diff --git a/tests/unit/discovery/py_info/test_py_info.py b/tests/unit/discovery/py_info/test_py_info.py
index 1b3fe38..b5272e4 100644
--- a/tests/unit/discovery/py_info/test_py_info.py
+++ b/tests/unit/discovery/py_info/test_py_info.py
@@ -205,7 +205,12 @@ def test_system_executable_no_exact_match(target, discovered, position, tmp_path
target_py_info = _make_py_info(target)
mocker.patch.object(target_py_info, "_find_possible_exe_names", return_value=names)
mocker.patch.object(target_py_info, "_find_possible_folders", return_value=[str(tmp_path)])
- mocker.patch.object(target_py_info, "from_exe", side_effect=lambda k, resolve_to_host: discovered_with_path[k])
+
+ # noinspection PyUnusedLocal
+ def func(k, resolve_to_host, raise_on_error):
+ return discovered_with_path[k]
+
+ mocker.patch.object(target_py_info, "from_exe", side_effect=func)
target_py_info.real_prefix = str(tmp_path)
target_py_info.system_executable = None