-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve executable discovery of a PythonInfo inside a given fol… (#1443)
- Use architecture, version, implementation and platform extensions for candiates - Cache PythonInfo.from_exe by path (resolving symlinks) - Ensure what we discover has the same version, implementation and architecture. - Improve our test suite for this functionality. Signed-off-by: Bernat Gabor <[email protected]>
- Loading branch information
1 parent
f2fc080
commit ad42aa5
Showing
4 changed files
with
110 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
tests/unit/interpreters/discovery/py_info/test_py_info_exe_based_of.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import logging | ||
import os | ||
import sys | ||
|
||
import pytest | ||
|
||
from virtualenv.interpreters.discovery.py_info import CURRENT, EXTENSIONS | ||
|
||
|
||
def test_discover_empty_folder(tmp_path, monkeypatch): | ||
with pytest.raises(RuntimeError): | ||
CURRENT.find_exe_based_of(inside_folder=str(tmp_path)) | ||
|
||
|
||
@pytest.mark.skipif(sys.platform == "win32", reason="symlink is not guaranteed to work on windows") | ||
@pytest.mark.parametrize("suffix", EXTENSIONS) | ||
@pytest.mark.parametrize("arch", [CURRENT.architecture, ""]) | ||
@pytest.mark.parametrize("version", [".".join(str(i) for i in CURRENT.version_info[0:i]) for i in range(3, 0, -1)]) | ||
@pytest.mark.parametrize("impl", [CURRENT.implementation, "python"]) | ||
@pytest.mark.parametrize("into", [CURRENT.prefix[len(CURRENT.executable) :], ""]) | ||
def test_discover_ok(tmp_path, monkeypatch, suffix, impl, version, arch, into, caplog): | ||
caplog.set_level(logging.DEBUG) | ||
folder = tmp_path / into | ||
folder.mkdir(parents=True, exist_ok=True) | ||
dest = folder / "{}{}".format(impl, version, arch, suffix) | ||
os.symlink(CURRENT.executable, str(dest)) | ||
inside_folder = str(tmp_path) | ||
assert CURRENT.find_exe_based_of(inside_folder) == str(dest) | ||
assert not caplog.text | ||
|
||
dest.rename(dest.parent / (dest.name + "-1")) | ||
with pytest.raises(RuntimeError): | ||
CURRENT.find_exe_based_of(inside_folder) |