From 305c671d1fb5068b53454df79667d4fd8d172234 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Tue, 20 Aug 2019 12:40:35 +0530 Subject: [PATCH 1/2] Add RequirementSet.add_unnamed_requirement() --- src/pip/_internal/req/req_set.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/pip/_internal/req/req_set.py b/src/pip/_internal/req/req_set.py index cd51d17250e..118d92f9a79 100644 --- a/src/pip/_internal/req/req_set.py +++ b/src/pip/_internal/req/req_set.py @@ -52,6 +52,11 @@ def __repr__(self): return ('<%s object; %d requirement(s): %s>' % (self.__class__.__name__, len(reqs), reqs_str)) + def add_unnamed_requirement(self, install_req): + # type: (InstallRequirement) -> None + assert not install_req.name + self.unnamed_requirements.append(install_req) + def add_requirement( self, install_req, # type: InstallRequirement @@ -105,8 +110,7 @@ def add_requirement( # Unnamed requirements are scanned again and the requirement won't be # added as a dependency until after scanning. if not name: - # url or path requirement w/o an egg fragment - self.unnamed_requirements.append(install_req) + self.add_unnamed_requirement(install_req) return [install_req], None try: From 476dfd2a8cef09f8e661682518857776ab42d15b Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Wed, 21 Aug 2019 15:44:48 +0530 Subject: [PATCH 2/2] Add RequirementSet.add_named_requirement() --- src/pip/_internal/req/req_set.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/pip/_internal/req/req_set.py b/src/pip/_internal/req/req_set.py index 118d92f9a79..269a045d592 100644 --- a/src/pip/_internal/req/req_set.py +++ b/src/pip/_internal/req/req_set.py @@ -57,6 +57,16 @@ def add_unnamed_requirement(self, install_req): assert not install_req.name self.unnamed_requirements.append(install_req) + def add_named_requirement(self, install_req): + # type: (InstallRequirement) -> None + assert install_req.name + name = install_req.name + + self.requirements[name] = install_req + # FIXME: what about other normalizations? E.g., _ vs. -? + if name.lower() != name: + self.requirement_aliases[name.lower()] = name + def add_requirement( self, install_req, # type: InstallRequirement @@ -134,11 +144,8 @@ def add_requirement( # When no existing requirement exists, add the requirement as a # dependency and it will be scanned again after. if not existing_req: - self.requirements[name] = install_req - # FIXME: what about other normalizations? E.g., _ vs. -? - if name.lower() != name: - self.requirement_aliases[name.lower()] = name - # We'd want to rescan this requirements later + self.add_named_requirement(install_req) + # We'd want to rescan this requirement later return [install_req], install_req # Assume there's no need to scan, and that we've already