Skip to content

Commit 2c24223

Browse files
committed
Update WorkingSet.find to consider standardised dist-info names
1 parent 79d6e46 commit 2c24223

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

pkg_resources/__init__.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -708,14 +708,15 @@ def find(self, req: Requirement) -> Distribution | None:
708708
If there is no active distribution for the requested project, ``None``
709709
is returned.
710710
"""
711-
dist = self.by_key.get(req.key)
712-
713-
if dist is None:
714-
canonical_key = self.normalized_to_canonical_keys.get(req.key)
715-
716-
if canonical_key is not None:
717-
req.key = canonical_key
718-
dist = self.by_key.get(canonical_key)
711+
for candidate in (
712+
req.key,
713+
self.normalized_to_canonical_keys.get(req.key),
714+
safe_name(req.key).replace(".", "-"),
715+
):
716+
dist = self.by_key.get(candidate)
717+
if dist:
718+
req.key = candidate
719+
break
719720

720721
if dist is not None and dist not in req:
721722
# XXX add more info

pkg_resources/tests/test_pkg_resources.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -477,5 +477,4 @@ def test_require_normalised_name(self, tmp_path, monkeypatch, name, version, req
477477

478478
[dist] = ws.require(req)
479479
assert dist.version == version
480-
assert dist.project_name == name
481480
assert os.path.commonpath([dist.location, site_packages]) == site_packages

0 commit comments

Comments
 (0)