-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve support for PEP-440 direct references
With this change we allow for PEP-508 string for file dependencies to use PEP-440 direct reference using the file URI scheme (RFC-8089). Note that this implementation will not allow non RFC-8089 file path references. URI will maintain relative paths in order to allow for sdist to be portable in all sane use cases. References: - https://www.python.org/dev/peps/pep-0508/#backwards-compatibility - https://www.python.org/dev/peps/pep-0440/#direct-references - https://tools.ietf.org/html/rfc8089 - https://discuss.python.org/t/what-is-the-correct-interpretation-of-path-based-pep-508-uri-reference/2815/11
- Loading branch information
Showing
8 changed files
with
185 additions
and
30 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# These test scenarios are ported over from pypa/pip | ||
# https://raw.githubusercontent.com/pypa/pip/b447f438df08303f4f07f2598f190e73876443ba/tests/unit/test_urls.py | ||
|
||
import os | ||
import sys | ||
|
||
import pytest | ||
|
||
from poetry.core.packages import path_to_url | ||
from poetry.core.packages import url_to_path as u2p | ||
from poetry.core.packages.utils.utils import pathname2url | ||
|
||
|
||
def url_to_path(*args, **kwargs): | ||
return str(u2p(*args, **kwargs)) | ||
|
||
|
||
@pytest.mark.skipif("sys.platform == 'win32'") | ||
def test_path_to_url_unix(): | ||
assert path_to_url("/tmp/file") == "file:///tmp/file" | ||
path = os.path.join(os.getcwd(), "file") | ||
assert path_to_url("file") == "file://" + pathname2url(path) | ||
|
||
|
||
@pytest.mark.skipif("sys.platform != 'win32'") | ||
def test_path_to_url_win(): | ||
assert path_to_url("c:/tmp/file") == "file:///C:/tmp/file" | ||
assert path_to_url("c:\\tmp\\file") == "file:///C:/tmp/file" | ||
assert path_to_url(r"\\unc\as\path") == "file://unc/as/path" | ||
path = os.path.join(os.getcwd(), "file") | ||
assert path_to_url("file") == "file:" + pathname2url(path) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"url,win_expected,non_win_expected", | ||
[ | ||
("file:tmp", "tmp", "tmp"), | ||
("file:c:/path/to/file", r"C:\path\to\file", "c:/path/to/file"), | ||
("file:/path/to/file", r"\path\to\file", "/path/to/file"), | ||
("file://localhost/tmp/file", r"\tmp\file", "/tmp/file"), | ||
("file://localhost/c:/tmp/file", r"C:\tmp\file", "/c:/tmp/file"), | ||
("file://somehost/tmp/file", r"\\somehost\tmp\file", None), | ||
("file:///tmp/file", r"\tmp\file", "/tmp/file"), | ||
("file:///c:/tmp/file", r"C:\tmp\file", "/c:/tmp/file"), | ||
], | ||
) | ||
def test_url_to_path(url, win_expected, non_win_expected): | ||
if sys.platform == "win32": | ||
expected_path = win_expected | ||
else: | ||
expected_path = non_win_expected | ||
|
||
if expected_path is None: | ||
with pytest.raises(ValueError): | ||
url_to_path(url) | ||
else: | ||
assert url_to_path(url) == expected_path | ||
|
||
|
||
@pytest.mark.skipif("sys.platform != 'win32'") | ||
def test_url_to_path_path_to_url_symmetry_win(): | ||
path = r"C:\tmp\file" | ||
assert url_to_path(path_to_url(path)) == path | ||
|
||
unc_path = r"\\unc\share\path" | ||
assert url_to_path(path_to_url(unc_path)) == unc_path |