Skip to content

Commit

Permalink
on exe discovery ignore incorrect interpreters, also try in the… (#1573)
Browse files Browse the repository at this point in the history
Signed-off-by: Bernat Gabor <[email protected]>
  • Loading branch information
gaborbernat authored Feb 11, 2020
1 parent 3846057 commit b577bfd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/changelog/1545.bugfix.rst
Original file line number Diff line number Diff line change
@@ -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`.
7 changes: 6 additions & 1 deletion src/virtualenv/discovery/py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,9 @@ def discover_exe(self, prefix, exact=True):
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)
Expand Down Expand Up @@ -411,6 +413,9 @@ def _find_possible_folders(self, inside_folder):

# 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())

Expand Down
7 changes: 6 additions & 1 deletion tests/unit/discovery/py_info/test_py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,12 @@ def _make_py_info(of):
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
Expand Down

0 comments on commit b577bfd

Please sign in to comment.