Skip to content

Commit

Permalink
Fix relative discovery (#1734)
Browse files Browse the repository at this point in the history
Signed-off-by: Bernat Gabor <bgabor8@bloomberg.net>
  • Loading branch information
gaborbernat committed Mar 19, 2020
1 parent 84d6108 commit 8f20134
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/changelog/1734.bugfix.rst
@@ -0,0 +1 @@
Fix relative path discovery of interpreters - by :user:`gaborbernat`.
4 changes: 2 additions & 2 deletions src/virtualenv/discovery/py_info.py
Expand Up @@ -229,8 +229,8 @@ def clear_cache(cls, app_data):

def satisfies(self, spec, impl_must_match):
"""check if a given specification can be satisfied by the this python interpreter instance"""
if self.executable == spec.path: # if the path is a our own executable path we're done
return True
if spec.path and self.executable == os.path.abspath(spec.path):
return True # if the path is a our own executable path we're done

if spec.path is not None: # if path set, and is not our original executable name, this does not match
root, _ = os.path.splitext(os.path.basename(self.original_executable))
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/discovery/test_discovery.py
Expand Up @@ -44,3 +44,12 @@ def test_discovery_via_path_not_found(tmp_path, monkeypatch):
monkeypatch.setenv(str("PATH"), str(tmp_path))
interpreter = get_interpreter(uuid4().hex)
assert interpreter is None


def test_relative_path(tmp_path, session_app_data, monkeypatch):
sys_executable = Path(PythonInfo.current_system(app_data=session_app_data).system_executable)
cwd = sys_executable.parents[1]
monkeypatch.chdir(str(cwd))
relative = str(sys_executable.relative_to(cwd))
result = get_interpreter(relative, session_app_data)
assert result is not None

0 comments on commit 8f20134

Please sign in to comment.