From 1a1f874864f26342461607e6f79036b358fc869d Mon Sep 17 00:00:00 2001 From: Frost Ming Date: Wed, 1 Jun 2022 15:54:53 +0800 Subject: [PATCH] Include hashes for file URLs Fix #1103 --- news/1103.bugfix.md | 1 + pdm/models/repositories.py | 13 ++++++++----- 2 files changed, 9 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..ed90707b32 --- /dev/null +++ b/news/1103.bugfix.md @@ -0,0 +1 @@ +Fix a bug that the hashes for file URLs are not included in the lock file. diff --git a/pdm/models/repositories.py b/pdm/models/repositories.py index b579374e65..b7ec58c346 100644 --- a/pdm/models/repositories.py +++ b/pdm/models/repositories.py @@ -211,13 +211,16 @@ def get_hashes(self, candidate: Candidate) -> dict[str, str] | None: matching_candidates: Iterable[Candidate] = [candidate] else: matching_candidates = self.find_candidates(req, True) + result: dict[str, str] = {} with self.environment.get_finder(self.sources) as finder: self._hash_cache.session = finder.session # type: ignore - return { - c.link.filename: self._hash_cache.get_hash(c.link) # type: ignore - for c in matching_candidates - if c.link and not c.link.is_vcs - } or None + for c in matching_candidates: + link = c.prepare(self.environment).ireq.link + if not link or link.is_vcs: + continue + result[link.filename] = self._hash_cache.get_hash(link) + + return result or None def dependency_generators(self) -> Iterable[Callable[[Candidate], CandidateInfo]]: """Return an iterable of getter functions to get dependencies, which will be