diff options
author | Benoit Pierre <benoit.pierre@gmail.com> | 2019-08-13 01:10:05 +0200 |
---|---|---|
committer | Benoit Pierre <benoit.pierre@gmail.com> | 2019-08-13 01:17:38 +0200 |
commit | b03652f642a8ea04644eb7d5b38223148dea5611 (patch) | |
tree | b9a83bc18c69de1bdddf2c9f5cd94630b075e0d1 | |
parent | af871897e6cd63e083f166559ea4fc65a330eac4 (diff) | |
download | external_python_setuptools-b03652f642a8ea04644eb7d5b38223148dea5611.tar.gz external_python_setuptools-b03652f642a8ea04644eb7d5b38223148dea5611.tar.bz2 external_python_setuptools-b03652f642a8ea04644eb7d5b38223148dea5611.zip |
pkg_resources: fix ``Requirement`` hash/equality implementation
Take PEP 508 direct URL into account.
-rw-r--r-- | changelog.d/1814.change.rst | 1 | ||||
-rw-r--r-- | pkg_resources/__init__.py | 1 | ||||
-rw-r--r-- | pkg_resources/tests/test_resources.py | 17 |
3 files changed, 19 insertions, 0 deletions
diff --git a/changelog.d/1814.change.rst b/changelog.d/1814.change.rst new file mode 100644 index 00000000..c936699d --- /dev/null +++ b/changelog.d/1814.change.rst @@ -0,0 +1 @@ +Fix ``pkg_resources.Requirement`` hash/equality implementation: take PEP 508 direct URL into account. diff --git a/pkg_resources/__init__.py b/pkg_resources/__init__.py index 1f170cfd..e75769d7 100644 --- a/pkg_resources/__init__.py +++ b/pkg_resources/__init__.py @@ -3109,6 +3109,7 @@ class Requirement(packaging.requirements.Requirement): self.extras = tuple(map(safe_extra, self.extras)) self.hashCmp = ( self.key, + self.url, self.specifier, frozenset(self.extras), str(self.marker) if self.marker else None, diff --git a/pkg_resources/tests/test_resources.py b/pkg_resources/tests/test_resources.py index 86afcf74..42c801a7 100644 --- a/pkg_resources/tests/test_resources.py +++ b/pkg_resources/tests/test_resources.py @@ -520,6 +520,11 @@ class TestRequirements: assert r1 == r2 assert str(r1) == str(r2) assert str(r2) == "Twisted==1.2c1,>=1.2" + assert ( + Requirement("Twisted") + != + Requirement("Twisted @ https://localhost/twisted.zip") + ) def testBasicContains(self): r = Requirement("Twisted>=1.2") @@ -546,11 +551,23 @@ class TestRequirements: == hash(( "twisted", + None, packaging.specifiers.SpecifierSet(">=1.2"), frozenset(["foo", "bar"]), None )) ) + assert ( + hash(Requirement.parse("Twisted @ https://localhost/twisted.zip")) + == + hash(( + "twisted", + "https://localhost/twisted.zip", + packaging.specifiers.SpecifierSet(), + frozenset(), + None + )) + ) def testVersionEquality(self): r1 = Requirement.parse("foo==0.3a2") |