From 06df15318a5c535cedebbcd01a6c5d84af164ecb Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Wed, 1 Jun 2022 14:52:16 +0800 Subject: [PATCH 1/2] prepare the candidate before calculating hash --- news/1103.bugfix.md | 1 + pdm/models/repositories.py | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) create mode 100644 news/1103.bugfix.md diff --git a/news/1103.bugfix.md b/news/1103.bugfix.md new file mode 100644 index 0000000000..a3910add20 --- /dev/null +++ b/news/1103.bugfix.md @@ -0,0 +1 @@ +Prepare the candidate to replace any vars in the link URL before calculating the hash. diff --git a/pdm/models/repositories.py b/pdm/models/repositories.py index 493d5653d3..b0d17d6984 100644 --- a/pdm/models/repositories.py +++ b/pdm/models/repositories.py @@ -5,6 +5,8 @@ from functools import lru_cache, wraps from typing import TYPE_CHECKING, Any, Callable, Iterable, Mapping, TypeVar, cast +from unearth import Link + from pdm import termui from pdm.exceptions import CandidateInfoNotFound, CandidateNotFound, CorruptedCacheError from pdm.models.candidates import Candidate @@ -205,12 +207,15 @@ def get_hashes(self, candidate: Candidate) -> dict[str, str] | None: matching_candidates: Iterable[Candidate] = [candidate] else: matching_candidates = self.find_candidates(req, ignore_requires_python=True) + result: dict[str, str] = {} with self.environment.get_finder(self.sources) as finder: - return { - c.link.filename: self._hash_cache.get_hash(c.link, finder.session) - for c in matching_candidates - if c.link and not c.link.is_vcs - } or None + for can in matching_candidates: + if not can.link or can.link.is_vcs: + continue + # Prepare the candidate to replace the vars in the link url + link = cast(Link, can.prepare(self.environment).link) + result[link.filename] = self._hash_cache.get_hash(link, finder.session) + return result or None def dependency_generators(self) -> Iterable[Callable[[Candidate], CandidateInfo]]: """Return an iterable of getter functions to get dependencies, which will be From 4572e90a3b3377defbe045987f2de9bbc4c571e3 Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Wed, 1 Jun 2022 15:28:14 +0800 Subject: [PATCH 2/2] Trigger CI