-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6203 from vinicyusmacedo/fix-pep-508
Fix is_url from splitting the scheme incorrectly when using PEP 440's direct references
- Loading branch information
Showing
5 changed files
with
203 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Fix requirement line parser to correctly handle PEP 440 requirements with a URL | ||
pointing to an archive file. |
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 |
---|---|---|
|
@@ -22,6 +22,8 @@ | |
from pip._internal.operations.prepare import RequirementPreparer | ||
from pip._internal.req import InstallRequirement, RequirementSet | ||
from pip._internal.req.constructors import ( | ||
_get_url_from_path, | ||
_looks_like_path, | ||
install_req_from_editable, | ||
install_req_from_line, | ||
install_req_from_req_string, | ||
|
@@ -343,6 +345,33 @@ def test_url_with_query(self): | |
req = install_req_from_line(url + fragment) | ||
assert req.link.url == url + fragment, req.link | ||
|
||
def test_pep440_wheel_link_requirement(self): | ||
url = 'https://whatever.com/test-0.4-py2.py3-bogus-any.whl' | ||
line = 'test @ https://whatever.com/test-0.4-py2.py3-bogus-any.whl' | ||
req = install_req_from_line(line) | ||
parts = str(req.req).split('@', 1) | ||
assert len(parts) == 2 | ||
assert parts[0].strip() == 'test' | ||
assert parts[1].strip() == url | ||
|
||
def test_pep440_url_link_requirement(self): | ||
url = 'git+http://foo.com@ref#egg=foo' | ||
line = 'foo @ git+http://foo.com@ref#egg=foo' | ||
req = install_req_from_line(line) | ||
parts = str(req.req).split('@', 1) | ||
assert len(parts) == 2 | ||
assert parts[0].strip() == 'foo' | ||
assert parts[1].strip() == url | ||
|
||
def test_url_with_authentication_link_requirement(self): | ||
url = 'https://[email protected]/test-0.4-py2.py3-bogus-any.whl' | ||
line = 'https://[email protected]/test-0.4-py2.py3-bogus-any.whl' | ||
req = install_req_from_line(line) | ||
assert req.link is not None | ||
assert req.link.is_wheel | ||
assert req.link.scheme == "https" | ||
assert req.link.url == url | ||
|
||
def test_unsupported_wheel_link_requirement_raises(self): | ||
reqset = RequirementSet() | ||
req = install_req_from_line( | ||
|
@@ -634,3 +663,95 @@ def test_mismatched_versions(caplog, tmpdir): | |
'Requested simplewheel==2.0, ' | ||
'but installing version 1.0' | ||
) | ||
|
||
|
||
@pytest.mark.parametrize('args, expected', [ | ||
# Test UNIX-like paths | ||
(('/path/to/installable'), True), | ||
# Test relative paths | ||
(('./path/to/installable'), True), | ||
# Test current path | ||
(('.'), True), | ||
# Test url paths | ||
(('https://whatever.com/test-0.4-py2.py3-bogus-any.whl'), True), | ||
# Test pep440 paths | ||
(('test @ https://whatever.com/test-0.4-py2.py3-bogus-any.whl'), True), | ||
# Test wheel | ||
(('simple-0.1-py2.py3-none-any.whl'), False), | ||
]) | ||
def test_looks_like_path(args, expected): | ||
assert _looks_like_path(args) == expected | ||
|
||
|
||
@pytest.mark.skipif( | ||
not sys.platform.startswith("win"), | ||
reason='Test only available on Windows' | ||
) | ||
@pytest.mark.parametrize('args, expected', [ | ||
# Test relative paths | ||
(('.\\path\\to\\installable'), True), | ||
(('relative\\path'), True), | ||
# Test absolute paths | ||
(('C:\\absolute\\path'), True), | ||
]) | ||
def test_looks_like_path_win(args, expected): | ||
assert _looks_like_path(args) == expected | ||
|
||
|
||
@pytest.mark.parametrize('args, mock_returns, expected', [ | ||
# Test pep440 urls | ||
(('/path/to/foo @ git+http://foo.com@ref#egg=foo', | ||
'foo @ git+http://foo.com@ref#egg=foo'), (False, False), None), | ||
# Test pep440 urls without spaces | ||
(('/path/to/foo@git+http://foo.com@ref#egg=foo', | ||
'foo @ git+http://foo.com@ref#egg=foo'), (False, False), None), | ||
# Test pep440 wheel | ||
(('/path/to/test @ https://whatever.com/test-0.4-py2.py3-bogus-any.whl', | ||
'test @ https://whatever.com/test-0.4-py2.py3-bogus-any.whl'), | ||
(False, False), None), | ||
# Test name is not a file | ||
(('/path/to/simple==0.1', | ||
'simple==0.1'), | ||
(False, False), None), | ||
]) | ||
@patch('pip._internal.req.req_install.os.path.isdir') | ||
@patch('pip._internal.req.req_install.os.path.isfile') | ||
def test_get_url_from_path( | ||
isdir_mock, isfile_mock, args, mock_returns, expected | ||
): | ||
isdir_mock.return_value = mock_returns[0] | ||
isfile_mock.return_value = mock_returns[1] | ||
assert _get_url_from_path(*args) is expected | ||
|
||
|
||
@patch('pip._internal.req.req_install.os.path.isdir') | ||
@patch('pip._internal.req.req_install.os.path.isfile') | ||
def test_get_url_from_path__archive_file(isdir_mock, isfile_mock): | ||
isdir_mock.return_value = False | ||
isfile_mock.return_value = True | ||
name = 'simple-0.1-py2.py3-none-any.whl' | ||
path = os.path.join('/path/to/' + name) | ||
url = path_to_url(path) | ||
assert _get_url_from_path(path, name) == url | ||
|
||
|
||
@patch('pip._internal.req.req_install.os.path.isdir') | ||
@patch('pip._internal.req.req_install.os.path.isfile') | ||
def test_get_url_from_path__installable_dir(isdir_mock, isfile_mock): | ||
isdir_mock.return_value = True | ||
isfile_mock.return_value = True | ||
name = 'some/setuptools/project' | ||
path = os.path.join('/path/to/' + name) | ||
url = path_to_url(path) | ||
assert _get_url_from_path(path, name) == url | ||
|
||
|
||
@patch('pip._internal.req.req_install.os.path.isdir') | ||
def test_get_url_from_path__installable_error(isdir_mock): | ||
isdir_mock.return_value = True | ||
name = 'some/setuptools/project' | ||
path = os.path.join('/path/to/' + name) | ||
with pytest.raises(InstallationError) as e: | ||
_get_url_from_path(path, name) | ||
err_msg = e.value.args[0] | ||
assert "Neither 'setup.py' nor 'pyproject.toml' found" in err_msg |
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