From de4bdcffb9f11769465ba3b6bb67cfb8a5b196e2 Mon Sep 17 00:00:00 2001 From: Steve Kowalik Date: Mon, 7 Mar 2016 10:33:25 +1100 Subject: [PATCH] Change pkg_resources.Requirement to be a subclass of packaging --- pkg_resources/__init__.py | 21 +++++++-------------- pkg_resources/tests/test_resources.py | 2 +- setuptools/command/easy_install.py | 2 +- 3 files changed, 9 insertions(+), 16 deletions(-) diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index 2fb7bc5101..af336deb34 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -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 diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index 16fc319808..5f08400171 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -394,7 +394,7 @@ def testOptionsAndHashing(self): "twisted", packaging.specifiers.SpecifierSet(">=1.2"), frozenset(["foo","bar"]), - 'None' + None )) ) diff --git a/setuptools/command/easy_install.py b/setuptools/command/easy_install.py index 97de339544..0733065e19 100755 --- a/setuptools/command/easy_install.py +++ b/setuptools/command/easy_install.py @@ -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(