From 786b0df56b8cbead348691238975eb99dc70b866 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Thu, 16 Sep 2021 23:03:11 +0300 Subject: [PATCH 1/2] req: Add warning of not recording VCS info with legacy 'setup.py install' --- news/9178.trivial.rst | 1 + src/pip/_internal/req/req_install.py | 32 +++++++++++++++++----------- 2 files changed, 21 insertions(+), 12 deletions(-) create mode 100644 news/9178.trivial.rst diff --git a/news/9178.trivial.rst b/news/9178.trivial.rst new file mode 100644 index 00000000000..2fbe844f85e --- /dev/null +++ b/news/9178.trivial.rst @@ -0,0 +1 @@ +Add warning of not recording VCS info with legacy 'setup.py install' diff --git a/src/pip/_internal/req/req_install.py b/src/pip/_internal/req/req_install.py index add22b552cf..2bbe60b9eeb 100644 --- a/src/pip/_internal/req/req_install.py +++ b/src/pip/_internal/req/req_install.py @@ -802,18 +802,26 @@ def install( self.install_succeeded = success - if success and self.legacy_install_reason == 8368: - deprecated( - reason=( - "{} was installed using the legacy 'setup.py install' " - "method, because a wheel could not be built for it.".format( - self.name - ) - ), - replacement="to fix the wheel build issue reported above", - gone_in=None, - issue=8368, - ) + if success: + if self.legacy_install_reason == 8368: + deprecated( + reason=( + "{} was installed using the legacy 'setup.py install' " + "method, because a wheel could not be built for it.".format( + self.name + ) + ), + replacement="to fix the wheel build issue reported above", + gone_in=None, + issue=8368, + ) + if self.link.is_vcs: + logger.warning( + "Direct URL of package '%s' will not be recorded when " + "using legacy 'setup.py install'.\n" + "Consider installing the 'wheel' package.", + self.name, + ) def check_invalid_constraint_type(req: InstallRequirement) -> str: From d841b460a092e1130caeea546d2d68615564bb54 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Wed, 3 Mar 2021 23:53:42 +0200 Subject: [PATCH 2/2] tests: Add test of warning of not recording VCS info with legacy 'setup.py install' --- tests/unit/test_req_install.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/tests/unit/test_req_install.py b/tests/unit/test_req_install.py index 3301cac0621..01a78cb69bd 100644 --- a/tests/unit/test_req_install.py +++ b/tests/unit/test_req_install.py @@ -5,6 +5,7 @@ from pip._vendor.packaging.requirements import Requirement from pip._internal.exceptions import InstallationError +from pip._internal.models.link import Link from pip._internal.req.constructors import ( install_req_from_line, install_req_from_req_string, @@ -106,3 +107,26 @@ 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 + + def test_install_req_vcs_without_wheel_warning(self, caplog): + """ + Test to make sure that installing from VCS without wheel generates + a warning. + """ + req = InstallRequirement( + Requirement("gputil==1.4.0"), + comes_from=[], + link=Link("git+https://github.com/llamafilm/gputil") + ) + + req.source_dir = os.curdir + req.install([]) + + actual = [(r.levelname, r.message) for r in caplog.records] + expected = ( + 'WARNING', + "Direct URL of package 'gputil' will not be recorded when using" + " legacy 'setup.py install'.\n" + "Consider installing the 'wheel' package." + ) + assert expected in actual