diff --git a/docs/changelog/1734.bugfix.rst b/docs/changelog/1734.bugfix.rst new file mode 100644 index 000000000..666840913 --- /dev/null +++ b/docs/changelog/1734.bugfix.rst @@ -0,0 +1 @@ +Fix relative path discovery of interpreters - by :user:`gaborbernat`. diff --git a/src/virtualenv/discovery/py_info.py b/src/virtualenv/discovery/py_info.py index c04a31212..9a612fe14 100644 --- a/src/virtualenv/discovery/py_info.py +++ b/src/virtualenv/discovery/py_info.py @@ -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)) diff --git a/tests/unit/discovery/test_discovery.py b/tests/unit/discovery/test_discovery.py index 2533875fe..e8e9c4db9 100644 --- a/tests/unit/discovery/test_discovery.py +++ b/tests/unit/discovery/test_discovery.py @@ -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