Skip to content

Commit

Permalink
Fix relative discovery
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 871ef23
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/changelog/1734.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix relative path discovery of interpreters - by :user:`gaborbernat`.
2 changes: 1 addition & 1 deletion src/virtualenv/discovery/py_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,7 @@ 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
if self.executable == os.path.abspath(spec.path): # if the path is a our own executable path we're done
return True

if spec.path is not None: # if path set, and is not our original executable name, this does not match
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/discovery/test_discovery.py
Original file line number Diff line number Diff line change
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(cwd)
relative = str(sys_executable.relative_to(cwd))
result = get_interpreter(relative, session_app_data)
assert result is not None

0 comments on commit 871ef23

Please sign in to comment.