From 3c4b48dfb08222ba5b6d813699cf5578ca10816c Mon Sep 17 00:00:00 2001 From: Bernat Gabor Date: Wed, 29 Jan 2020 13:59:06 +0000 Subject: [PATCH] Support relative paths for the python specification string. The python info discovery mechanism does not work with relative paths, normalize python specification strings to always be absolute paths. --- docs/changelog/1514.bugfix.rst | 1 + src/virtualenv/discovery/py_spec.py | 2 +- tests/unit/discovery/test_py_spec.py | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 docs/changelog/1514.bugfix.rst diff --git a/docs/changelog/1514.bugfix.rst b/docs/changelog/1514.bugfix.rst new file mode 100644 index 000000000..3ce79852d --- /dev/null +++ b/docs/changelog/1514.bugfix.rst @@ -0,0 +1 @@ +Support relative paths for ``-p`` - by ``gaborbernat``. diff --git a/src/virtualenv/discovery/py_spec.py b/src/virtualenv/discovery/py_spec.py index 3433b5a13..678c65a1f 100644 --- a/src/virtualenv/discovery/py_spec.py +++ b/src/virtualenv/discovery/py_spec.py @@ -65,7 +65,7 @@ def _int_or_none(val): arch = _int_or_none(groups["arch"]) if not ok: - path = string_spec + path = os.path.abspath(string_spec) return cls(string_spec, impl, major, minor, patch, arch, path) diff --git a/tests/unit/discovery/test_py_spec.py b/tests/unit/discovery/test_py_spec.py index 5afb43a48..e118e3ee8 100644 --- a/tests/unit/discovery/test_py_spec.py +++ b/tests/unit/discovery/test_py_spec.py @@ -1,6 +1,7 @@ from __future__ import absolute_import, unicode_literals import itertools +import os import sys from copy import copy @@ -104,3 +105,10 @@ def test_version_satisfies_nok(req, spec): req_spec = PythonSpec.from_string_spec("python{}".format(req)) sat_spec = PythonSpec.from_string_spec("python{}".format(spec)) assert sat_spec.satisfies(req_spec) is False + + +def test_relative_spec(tmp_path, monkeypatch): + monkeypatch.chdir(tmp_path) + a_relative_path = str((tmp_path / "a" / "b").relative_to(tmp_path)) + spec = PythonSpec.from_string_spec(a_relative_path) + assert spec.path == os.path.abspath(str(tmp_path / a_relative_path))