Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prepare the candidate before calculating the hash #1108

Merged
merged 2 commits into from
Jun 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/1103.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Prepare the candidate to replace any vars in the link URL before calculating the hash.
15 changes: 10 additions & 5 deletions pdm/models/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down