From bc7124e259616424b7e7f836f44f9d7c500555fc Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 25 Mar 2020 10:23:04 -0400 Subject: [PATCH 01/11] This commit changest the logging to use the name of the package instead of the full file path. --- src/pip/_internal/operations/prepare.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/pip/_internal/operations/prepare.py b/src/pip/_internal/operations/prepare.py index 9f87148c031..562ce9aa9c6 100644 --- a/src/pip/_internal/operations/prepare.py +++ b/src/pip/_internal/operations/prepare.py @@ -376,8 +376,7 @@ def prepare_linked_requirement( # TODO: Breakup into smaller functions if link.scheme == 'file': - path = link.file_path - logger.info('Processing %s', display_path(path)) + logger.info('Processing %s (cached)', req.name) else: logger.info('Collecting %s', req.req or req) From 3450e5bbbc8c0074e064646216649420d35d09b6 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 25 Mar 2020 10:55:42 -0400 Subject: [PATCH 02/11] add news file --- news/7815.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/7815.bugfix diff --git a/news/7815.bugfix b/news/7815.bugfix new file mode 100644 index 00000000000..f343acbad7c --- /dev/null +++ b/news/7815.bugfix @@ -0,0 +1 @@ +This change will switch from using full file path for wheel to using just the name of the package. \ No newline at end of file From 0c7c87779facab578e5d56a6a8abd243b308b507 Mon Sep 17 00:00:00 2001 From: Andrew Date: Wed, 25 Mar 2020 11:11:48 -0400 Subject: [PATCH 03/11] add new line --- news/7815.bugfix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/7815.bugfix b/news/7815.bugfix index f343acbad7c..d8996a201bc 100644 --- a/news/7815.bugfix +++ b/news/7815.bugfix @@ -1 +1 @@ -This change will switch from using full file path for wheel to using just the name of the package. \ No newline at end of file +This change will switch from using full file path for wheel to using just the name of the package. From 764fca3f22788291fae8c4a170807ce14ae699fb Mon Sep 17 00:00:00 2001 From: Andrew Date: Fri, 27 Mar 2020 13:30:44 -0400 Subject: [PATCH 04/11] check to see if it is from the wheel cache --- src/pip/_internal/operations/prepare.py | 6 +++++- src/pip/_internal/req/req_install.py | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/pip/_internal/operations/prepare.py b/src/pip/_internal/operations/prepare.py index 562ce9aa9c6..b7dbd988130 100644 --- a/src/pip/_internal/operations/prepare.py +++ b/src/pip/_internal/operations/prepare.py @@ -376,7 +376,11 @@ def prepare_linked_requirement( # TODO: Breakup into smaller functions if link.scheme == 'file': - logger.info('Processing %s (cached)', req.name) + if req.from_wheel_cache: + logger.info('Processing %s (cached)', req.link.filename) + else: + logger.info('Processing %s', req.link.filename) + else: logger.info('Collecting %s', req.req or req) diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py index f5e0197f2b4..e4731367bf2 100644 --- a/src/pip/_internal/req/req_install.py +++ b/src/pip/_internal/req/req_install.py @@ -178,6 +178,9 @@ def __init__( self.isolated = isolated self.build_env = NoOpBuildEnvironment() # type: BuildEnvironment + # This defines whether the requirement came from a local wheel cache. + self.from_wheel_cache = False + # For PEP 517, the directory where we request the project metadata # gets stored. We need this to pass to build_wheel, so the backend # can ensure that the wheel matches the metadata (see the PEP for @@ -265,6 +268,7 @@ def populate_link(self, finder, upgrade, require_hashes): supported_tags=supported_tags, ) if old_link != self.link: + self.from_wheel_cache = True logger.debug('Using cached wheel link: %s', self.link) # Things that are valid for all kinds of requirements? From a611a84b988949de32be8b1c84325d128d9a78b2 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 28 Mar 2020 22:00:15 -0400 Subject: [PATCH 05/11] Switches the variable is_from_wheel_cache to a function that looks at the link. Also adds unit tests. --- news/7815.bugfix | 2 +- src/pip/_internal/index/collector.py | 1 + src/pip/_internal/operations/prepare.py | 2 +- src/pip/_internal/req/req_install.py | 16 ++++++-- tests/unit/test_req_install.py | 53 +++++++++++++++++++++++++ 5 files changed, 68 insertions(+), 6 deletions(-) diff --git a/news/7815.bugfix b/news/7815.bugfix index d8996a201bc..fe4bb4ccc90 100644 --- a/news/7815.bugfix +++ b/news/7815.bugfix @@ -1 +1 @@ -This change will switch from using full file path for wheel to using just the name of the package. +Display only the wheel filename instead of the entire filepath, when using a cached wheel. diff --git a/src/pip/_internal/index/collector.py b/src/pip/_internal/index/collector.py index 033e37ac75b..db261f84ee2 100644 --- a/src/pip/_internal/index/collector.py +++ b/src/pip/_internal/index/collector.py @@ -543,6 +543,7 @@ def collect_links(self, project_name): :return: All the Link objects (unfiltered), as a CollectedLinks object. """ + search_scope = self.search_scope index_locations = search_scope.get_index_urls_locations(project_name) index_file_loc, index_url_loc = group_locations(index_locations) diff --git a/src/pip/_internal/operations/prepare.py b/src/pip/_internal/operations/prepare.py index b7dbd988130..457c39f2f44 100644 --- a/src/pip/_internal/operations/prepare.py +++ b/src/pip/_internal/operations/prepare.py @@ -379,7 +379,7 @@ def prepare_linked_requirement( if req.from_wheel_cache: logger.info('Processing %s (cached)', req.link.filename) else: - logger.info('Processing %s', req.link.filename) + logger.info('Processing %s', req.link.file_path) else: logger.info('Collecting %s', req.req or req) diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py index e4731367bf2..967a1108475 100644 --- a/src/pip/_internal/req/req_install.py +++ b/src/pip/_internal/req/req_install.py @@ -178,9 +178,6 @@ def __init__( self.isolated = isolated self.build_env = NoOpBuildEnvironment() # type: BuildEnvironment - # This defines whether the requirement came from a local wheel cache. - self.from_wheel_cache = False - # For PEP 517, the directory where we request the project metadata # gets stored. We need this to pass to build_wheel, so the backend # can ensure that the wheel matches the metadata (see the PEP for @@ -267,10 +264,21 @@ def populate_link(self, finder, upgrade, require_hashes): package_name=self.name, supported_tags=supported_tags, ) + if old_link != self.link: - self.from_wheel_cache = True logger.debug('Using cached wheel link: %s', self.link) + @property + def from_wheel_cache(self): + #type: () -> bool + """ + This function returns whether the file path is in the wheel cache. + """ + if self._wheel_cache is not None and self.link is not None: + return bool(self._wheel_cache.cache_dir in self.link.file_path) + else: + return False + # Things that are valid for all kinds of requirements? @property def name(self): diff --git a/tests/unit/test_req_install.py b/tests/unit/test_req_install.py index c3482d5360a..d75bbd590d2 100644 --- a/tests/unit/test_req_install.py +++ b/tests/unit/test_req_install.py @@ -4,12 +4,18 @@ import pytest from pip._vendor.packaging.requirements import Requirement +from pip._internal.cache import WheelCache from pip._internal.exceptions import InstallationError +from pip._internal.models.format_control import FormatControl from pip._internal.req.constructors import ( install_req_from_line, install_req_from_req_string, ) from pip._internal.req.req_install import InstallRequirement +from pip._internal.models.link import Link + +from tests.lib import make_test_link_collector, make_test_finder, path_to_url +from tests.lib.wheel import make_wheel class TestInstallRequirementBuildDirectory(object): @@ -108,3 +114,50 @@ def test_install_req_from_string_with_comes_from_without_link(self): assert install_req.link.url == wheel_url assert install_req.req.url == wheel_url assert install_req.is_wheel + + +class TestInstallRequirementWheelCache(object): + + def test_able_to_register_when_get_from_wheel_cache(self, tmpdir, data): + """ + This test to make sure that file is able to tell when a link is from the wheel cache + """ + + format_control = FormatControl() + wheel_path = path_to_url(make_wheel( + name='pip', + version='6.9.0' + ).save_to_dir(tmpdir)) + + wheel_cache = WheelCache(tmpdir, format_control) + + install_req = install_req_from_req_string( + req_string='pip', + wheel_cache=wheel_cache + ) + install_req.link = Link(wheel_path) + + assert install_req.from_wheel_cache + + def test_able_to_register_when_not_get_from_wheel_cache(self, tmpdir, data): + """ + This test to make sure that file is able to tell when a link is not from the wheel cache + """ + + wheel_path = path_to_url(make_wheel( + name='pip', + version='6.9.0' + ).save_to_dir(tmpdir)) + + format_control = FormatControl() + + wheel_cache = WheelCache(tmpdir + '/wheel_cache', format_control) + + install_req = install_req_from_req_string( + req_string='pip', + wheel_cache=wheel_cache + ) + + install_req.link = Link(wheel_path) + + assert not install_req.from_wheel_cache From f79c530d21aca3a36ba353a473490fb1b84446ad Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 28 Mar 2020 22:01:30 -0400 Subject: [PATCH 06/11] gets rid of empyt space. --- src/pip/_internal/index/collector.py | 1 - 1 file changed, 1 deletion(-) diff --git a/src/pip/_internal/index/collector.py b/src/pip/_internal/index/collector.py index db261f84ee2..033e37ac75b 100644 --- a/src/pip/_internal/index/collector.py +++ b/src/pip/_internal/index/collector.py @@ -543,7 +543,6 @@ def collect_links(self, project_name): :return: All the Link objects (unfiltered), as a CollectedLinks object. """ - search_scope = self.search_scope index_locations = search_scope.get_index_urls_locations(project_name) index_file_loc, index_url_loc = group_locations(index_locations) From e33c22a265c21a05d1aaaae782fdc607cc4c7024 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 28 Mar 2020 22:43:12 -0400 Subject: [PATCH 07/11] Fixing linting errors --- src/pip/_internal/req/req_install.py | 2 +- tests/unit/test_req_install.py | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py index 967a1108475..c105d6b7a89 100644 --- a/src/pip/_internal/req/req_install.py +++ b/src/pip/_internal/req/req_install.py @@ -270,7 +270,7 @@ def populate_link(self, finder, upgrade, require_hashes): @property def from_wheel_cache(self): - #type: () -> bool + # type: () -> bool """ This function returns whether the file path is in the wheel cache. """ diff --git a/tests/unit/test_req_install.py b/tests/unit/test_req_install.py index d75bbd590d2..5c5be211ace 100644 --- a/tests/unit/test_req_install.py +++ b/tests/unit/test_req_install.py @@ -14,7 +14,7 @@ from pip._internal.req.req_install import InstallRequirement from pip._internal.models.link import Link -from tests.lib import make_test_link_collector, make_test_finder, path_to_url +from tests.lib import path_to_url from tests.lib.wheel import make_wheel @@ -118,9 +118,10 @@ def test_install_req_from_string_with_comes_from_without_link(self): class TestInstallRequirementWheelCache(object): - def test_able_to_register_when_get_from_wheel_cache(self, tmpdir, data): + def test_able_to_register_when_get_from_wheel_cache(self, tmpdir): """ - This test to make sure that file is able to tell when a link is from the wheel cache + This test to make sure that file is able to tell when a link is + from the wheel cache. """ format_control = FormatControl() @@ -139,9 +140,10 @@ def test_able_to_register_when_get_from_wheel_cache(self, tmpdir, data): assert install_req.from_wheel_cache - def test_able_to_register_when_not_get_from_wheel_cache(self, tmpdir, data): + def test_able_to_register_when_not_get_from_wheel_cache(self, tmpdir): """ - This test to make sure that file is able to tell when a link is not from the wheel cache + This test to make sure that file is able to tell when a link is not + from the wheel cache. """ wheel_path = path_to_url(make_wheel( @@ -154,8 +156,8 @@ def test_able_to_register_when_not_get_from_wheel_cache(self, tmpdir, data): wheel_cache = WheelCache(tmpdir + '/wheel_cache', format_control) install_req = install_req_from_req_string( - req_string='pip', - wheel_cache=wheel_cache + req_string='pip', + wheel_cache=wheel_cache ) install_req.link = Link(wheel_path) From b5e1a88847d15128ce00a9c8051e4728a7be8886 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 28 Mar 2020 22:50:18 -0400 Subject: [PATCH 08/11] linting fixes --- tests/unit/test_req_install.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/tests/unit/test_req_install.py b/tests/unit/test_req_install.py index 5c5be211ace..0859506f57a 100644 --- a/tests/unit/test_req_install.py +++ b/tests/unit/test_req_install.py @@ -1,9 +1,8 @@ import os import tempfile - import pytest -from pip._vendor.packaging.requirements import Requirement +from pip._vendor.packaging.requirements import Requirement from pip._internal.cache import WheelCache from pip._internal.exceptions import InstallationError from pip._internal.models.format_control import FormatControl @@ -13,7 +12,6 @@ ) from pip._internal.req.req_install import InstallRequirement from pip._internal.models.link import Link - from tests.lib import path_to_url from tests.lib.wheel import make_wheel From 3449d5f8c7437848dc5e7ffa21392248976ecd85 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 29 Mar 2020 10:20:39 -0400 Subject: [PATCH 09/11] lint changes --- tests/unit/test_req_install.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/unit/test_req_install.py b/tests/unit/test_req_install.py index 0859506f57a..06a08f628cb 100644 --- a/tests/unit/test_req_install.py +++ b/tests/unit/test_req_install.py @@ -3,6 +3,7 @@ import pytest from pip._vendor.packaging.requirements import Requirement + from pip._internal.cache import WheelCache from pip._internal.exceptions import InstallationError from pip._internal.models.format_control import FormatControl From 7eb1af5108cd61be05c9f1f6b7bd818b2316e003 Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 29 Mar 2020 11:08:50 -0400 Subject: [PATCH 10/11] lint changes --- tests/unit/test_req_install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_req_install.py b/tests/unit/test_req_install.py index 06a08f628cb..f71bf3646b7 100644 --- a/tests/unit/test_req_install.py +++ b/tests/unit/test_req_install.py @@ -7,12 +7,12 @@ from pip._internal.cache import WheelCache from pip._internal.exceptions import InstallationError from pip._internal.models.format_control import FormatControl +from pip._internal.models.link import Link from pip._internal.req.constructors import ( install_req_from_line, install_req_from_req_string, ) from pip._internal.req.req_install import InstallRequirement -from pip._internal.models.link import Link from tests.lib import path_to_url from tests.lib.wheel import make_wheel From a8006e237c62e1869bede359dcb88c793d4c5a6b Mon Sep 17 00:00:00 2001 From: Andrew Date: Sun, 29 Mar 2020 11:33:30 -0400 Subject: [PATCH 11/11] lint changes --- tests/unit/test_req_install.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/unit/test_req_install.py b/tests/unit/test_req_install.py index f71bf3646b7..39b11753de7 100644 --- a/tests/unit/test_req_install.py +++ b/tests/unit/test_req_install.py @@ -1,7 +1,7 @@ import os import tempfile -import pytest +import pytest from pip._vendor.packaging.requirements import Requirement from pip._internal.cache import WheelCache