Skip to content

Commit

Permalink
Add helpers to RequirementSet to directly add requirements (#6904)
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyunsg authored Aug 21, 2019
2 parents 7783c47 + 476dfd2 commit 8dc5515
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/pip/_internal/req/req_set.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ 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_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
Expand Down Expand Up @@ -105,8 +120,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:
Expand All @@ -130,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
Expand Down

0 comments on commit 8dc5515

Please sign in to comment.