Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support relative paths for the python specification string. #1523

Merged
merged 1 commit into from
Jan 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/changelog/1514.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Support relative paths for ``-p`` - by ``gaborbernat``.
2 changes: 1 addition & 1 deletion src/virtualenv/discovery/py_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
8 changes: 8 additions & 0 deletions tests/unit/discovery/test_py_spec.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import absolute_import, unicode_literals

import itertools
import os
import sys
from copy import copy

Expand Down Expand Up @@ -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))