Skip to content

Commit

Permalink
Update WorkingSet.find to consider standardised dist-info names
Browse files Browse the repository at this point in the history
  • Loading branch information
abravalheri committed Feb 26, 2025
1 parent 79d6e46 commit 2c24223
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
17 changes: 9 additions & 8 deletions pkg_resources/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,14 +708,15 @@ def find(self, req: Requirement) -> Distribution | None:
If there is no active distribution for the requested project, ``None``
is returned.
"""
dist = self.by_key.get(req.key)

if dist is None:
canonical_key = self.normalized_to_canonical_keys.get(req.key)

if canonical_key is not None:
req.key = canonical_key
dist = self.by_key.get(canonical_key)
for candidate in (
req.key,
self.normalized_to_canonical_keys.get(req.key),
safe_name(req.key).replace(".", "-"),
):
dist = self.by_key.get(candidate)
if dist:
req.key = candidate
break

if dist is not None and dist not in req:
# XXX add more info
Expand Down
1 change: 0 additions & 1 deletion pkg_resources/tests/test_pkg_resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -477,5 +477,4 @@ def test_require_normalised_name(self, tmp_path, monkeypatch, name, version, req

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

0 comments on commit 2c24223

Please sign in to comment.