From 2e1dfbef76190ee512151cd0d7c18d30e3ebe730 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul=20=28ACSONE=29?= Date: Thu, 15 Aug 2019 23:00:55 +0200 Subject: [PATCH] consolidate vcs link detection --- news/6883.trivial | 1 + src/pip/_internal/download.py | 9 ++------- src/pip/_internal/models/link.py | 14 ++++++++------ src/pip/_internal/operations/prepare.py | 3 +-- src/pip/_internal/wheel.py | 2 +- tests/unit/test_link.py | 10 ++++++++++ tests/unit/test_wheel.py | 3 +-- 7 files changed, 24 insertions(+), 18 deletions(-) create mode 100644 news/6883.trivial diff --git a/news/6883.trivial b/news/6883.trivial new file mode 100644 index 00000000000..e6731cdbef6 --- /dev/null +++ b/news/6883.trivial @@ -0,0 +1 @@ +replace is_vcs_url function by is_vcs Link property \ No newline at end of file diff --git a/src/pip/_internal/download.py b/src/pip/_internal/download.py index 0c6492a8d78..159a4433e39 100644 --- a/src/pip/_internal/download.py +++ b/src/pip/_internal/download.py @@ -76,7 +76,7 @@ __all__ = ['get_file_content', 'is_url', 'url_to_path', 'path_to_url', 'is_archive_file', 'unpack_vcs_link', - 'unpack_file_url', 'is_vcs_url', 'is_file_url', + 'unpack_file_url', 'is_file_url', 'unpack_http_url', 'unpack_url', 'parse_content_disposition', 'sanitize_content_filename'] @@ -744,11 +744,6 @@ def _get_used_vcs_backend(link): return None -def is_vcs_url(link): - # type: (Link) -> bool - return bool(_get_used_vcs_backend(link)) - - def is_file_url(link): # type: (Link) -> bool return link.url.lower().startswith('file:') @@ -1063,7 +1058,7 @@ def unpack_url( would ordinarily raise HashUnsupported) are allowed. """ # non-editable vcs urls - if is_vcs_url(link): + if link.is_vcs: unpack_vcs_link(link, location) # file urls diff --git a/src/pip/_internal/models/link.py b/src/pip/_internal/models/link.py index 190e89b3b9a..56ad2a5be5c 100644 --- a/src/pip/_internal/models/link.py +++ b/src/pip/_internal/models/link.py @@ -179,6 +179,13 @@ def is_wheel(self): # type: () -> bool return self.ext == WHEEL_EXTENSION + @property + def is_vcs(self): + # type: () -> bool + from pip._internal.vcs import vcs + + return self.scheme in vcs.all_schemes + @property def is_artifact(self): # type: () -> bool @@ -186,12 +193,7 @@ def is_artifact(self): Determines if this points to an actual artifact (e.g. a tarball) or if it points to an "abstract" thing like a path or a VCS location. """ - from pip._internal.vcs import vcs - - if self.scheme in vcs.all_schemes: - return False - - return True + return not self.is_vcs @property def is_yanked(self): diff --git a/src/pip/_internal/operations/prepare.py b/src/pip/_internal/operations/prepare.py index 1d9ee8af53c..3cb09d83c68 100644 --- a/src/pip/_internal/operations/prepare.py +++ b/src/pip/_internal/operations/prepare.py @@ -16,7 +16,6 @@ from pip._internal.download import ( is_dir_url, is_file_url, - is_vcs_url, unpack_url, url_to_path, ) @@ -163,7 +162,7 @@ def prepare_linked_requirement( # we would report less-useful error messages for # unhashable requirements, complaining that there's no # hash provided. - if is_vcs_url(link): + if link.is_vcs: raise VcsHashUnsupported() elif is_file_url(link) and is_dir_url(link): raise DirectoryUrlHashUnsupported() diff --git a/src/pip/_internal/wheel.py b/src/pip/_internal/wheel.py index cd0d3460f9e..da890089c5a 100644 --- a/src/pip/_internal/wheel.py +++ b/src/pip/_internal/wheel.py @@ -815,7 +815,7 @@ def should_use_ephemeral_cache( ) return None - if req.link and not req.link.is_artifact: + if req.link and req.link.is_vcs: # VCS checkout. Build wheel just for this run. return True diff --git a/tests/unit/test_link.py b/tests/unit/test_link.py index 8a8182d3919..8fbafe082e8 100644 --- a/tests/unit/test_link.py +++ b/tests/unit/test_link.py @@ -127,3 +127,13 @@ def test_is_hash_allowed__none_hashes(self, hashes, expected): url = 'https://example.com/wheel.whl#sha512={}'.format(128 * 'a') link = Link(url) assert link.is_hash_allowed(hashes) == expected + + @pytest.mark.parametrize('url, expected', [ + ('git+https://github.com/org/repo', True), + ('bzr+http://bzr.myproject.org/MyProject/trunk/#egg=MyProject', True), + ('https://example.com/some.whl', False), + ('file://home/foo/some.whl', False), + ]) + def test_is_vcs(self, url, expected): + link = Link(url) + assert link.is_vcs is expected diff --git a/tests/unit/test_wheel.py b/tests/unit/test_wheel.py index 9775d6f317e..449da28c199 100644 --- a/tests/unit/test_wheel.py +++ b/tests/unit/test_wheel.py @@ -126,7 +126,6 @@ def test_should_use_ephemeral_cache__disallow_binaries_and_vcs_checkout( causes should_use_ephemeral_cache() to return None for VCS checkouts. """ req = Requirement('pendulum') - # Passing a VCS url causes link.is_artifact to return False. link = Link(url='git+https://git.example.com/pendulum.git') req = InstallRequirement( req=req, @@ -137,7 +136,7 @@ def test_should_use_ephemeral_cache__disallow_binaries_and_vcs_checkout( source_dir='/tmp/pip-install-9py5m2z1/pendulum', ) assert not req.is_wheel - assert not req.link.is_artifact + assert req.link.is_vcs format_control = FormatControl() if disallow_binaries: