Commit de4bdcff authored by Steve Kowalik's avatar Steve Kowalik

Change pkg_resources.Requirement to be a subclass of packaging

parent 0ed33b7a
......@@ -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
......
......@@ -394,7 +394,7 @@ class TestRequirements:
"twisted",
packaging.specifiers.SpecifierSet(">=1.2"),
frozenset(["foo","bar"]),
'None'
None
))
)
......
......@@ -710,7 +710,7 @@ class easy_install(Command):
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(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment