Skip to content

Commit

Permalink
Change pkg_resources.Requirement to be a subclass of packaging
Browse files Browse the repository at this point in the history
  • Loading branch information
s-t-e-v-e-n-k committed Mar 6, 2016
1 parent 0ed33b7 commit de4bdcf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
21 changes: 7 additions & 14 deletions pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2754,33 +2754,26 @@ def parse_requirements(strs):
yield Requirement(line)


class Requirement:
class Requirement(packaging.requirements.Requirement):
def __init__(self, requirement_string):
"""DO NOT CALL THIS UNDOCUMENTED METHOD; use Requirement.parse()!"""
try:
self.req = packaging.requirements.Requirement(requirement_string)
super(Requirement, self).__init__(requirement_string)
except packaging.requirements.InvalidRequirement as e:
raise RequirementParseError(str(e))
self.unsafe_name = self.req.name
project_name = safe_name(self.req.name)
self.project_name, self.key = project_name, project_name.lower()
self.specifier = self.req.specifier
self.unsafe_name = self.name
self.project_name, self.key = self.name, self.name.lower()
self.specs = [
(spec.operator, spec.version) for spec in self.req.specifier]
self.extras = tuple(map(safe_extra, self.req.extras))
self.marker = self.req.marker
self.url = self.req.url
(spec.operator, spec.version) for spec in self.specifier]
self.extras = tuple(map(safe_extra, self.extras))
self.hashCmp = (
self.key,
self.specifier,
frozenset(self.extras),
str(self.marker)
str(self.marker) if self.marker else None,
)
self.__hash = hash(self.hashCmp)

def __str__(self):
return str(self.req)

def __eq__(self, other):
return (
isinstance(other, Requirement) and
Expand Down
2 changes: 1 addition & 1 deletion pkg_resources/tests/test_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ def testOptionsAndHashing(self):
"twisted",
packaging.specifiers.SpecifierSet(">=1.2"),
frozenset(["foo","bar"]),
'None'
None
))
)

Expand Down
2 changes: 1 addition & 1 deletion setuptools/command/easy_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,7 @@ def process_distribution(self, requirement, dist, deps=True, *info):
elif requirement is None or dist not in requirement:
# if we wound up with a different version, resolve what we've got
distreq = dist.as_requirement()
requirement = Requirement(str(distreq.req))
requirement = Requirement(str(distreq))
log.info("Processing dependencies for %s", requirement)
try:
distros = WorkingSet([]).resolve(
Expand Down

0 comments on commit de4bdcf

Please sign in to comment.