Skip to content

Commit

Permalink
fix: The cache collision issue between named requirements and url req…
Browse files Browse the repository at this point in the history
…uirements (#2067)
  • Loading branch information
frostming authored Jun 29, 2023
1 parent 105221a commit 2339fd3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
1 change: 1 addition & 0 deletions news/2064.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a cache collision between named requirements and url requirements.
15 changes: 14 additions & 1 deletion src/pdm/models/caches.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,27 @@ class CandidateInfoCache(JSONFileCache[Candidate, CandidateInfo]):
candidate -> (dependencies, requires_python, summary) mapping.
"""

@staticmethod
def get_url_part(link: Link) -> str:
import base64

from pdm.utils import url_without_fragments

url = url_without_fragments(link.split_auth()[1])
return base64.urlsafe_b64encode(url.encode()).decode()

@classmethod
def _get_key(cls, obj: Candidate) -> str:
# Name and version are set when dependencies are resolved,
# so use them for cache key. Local directories won't be cached.
if not obj.name or not obj.version:
raise KeyError("The package is missing a name or version")
extras = "[{}]".format(",".join(sorted(obj.req.extras))) if obj.req.extras else ""
return f"{obj.name}{extras}-{obj.version}"
version = obj.version
if not obj.req.is_named:
assert obj.link is not None
version = cls.get_url_part(obj.link)
return f"{obj.name}{extras}-{version}"


class HashCache:
Expand Down

0 comments on commit 2339fd3

Please sign in to comment.