Skip to content

Commit

Permalink
fix(resolution): fix a bug that versions with local part can't be fou…
Browse files Browse the repository at this point in the history
…nd and installed

Close #1093
  • Loading branch information
frostming committed Jun 24, 2022
1 parent 07117ce commit c727a4a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions news/1093.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix a bug that candidates with local part in the version can't be found and installed correctly.
6 changes: 2 additions & 4 deletions pdm/models/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
parse_requirement,
)
from pdm.models.search import SearchResultParser
from pdm.models.specifiers import PySpecSet, get_specifier
from pdm.models.specifiers import PySpecSet
from pdm.utils import normalize_name, url_without_fragments

if TYPE_CHECKING:
Expand Down Expand Up @@ -198,9 +198,7 @@ def get_hashes(self, candidate: Candidate) -> dict[str, str] | None:
return None
if candidate.hashes:
return candidate.hashes
req = dataclasses.replace(
candidate.req, specifier=get_specifier(f"=={candidate.version}")
)
req = candidate.req.as_pinned_version(candidate.version)
if candidate.req.is_file_or_url:
matching_candidates: Iterable[Candidate] = [candidate]
else:
Expand Down
8 changes: 7 additions & 1 deletion pdm/models/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from packaging.requirements import Requirement as PackageRequirement
from packaging.specifiers import SpecifierSet
from packaging.utils import parse_sdist_filename, parse_wheel_filename
from packaging.version import parse as parse_version
from unearth import Link

from pdm.compat import Distribution
Expand Down Expand Up @@ -102,7 +103,12 @@ def as_pinned_version(self: T, other_version: str | None) -> T:
"""Return a new requirement with the given pinned version."""
if self.is_pinned or not other_version:
return self
return dataclasses.replace(self, specifier=get_specifier(f"=={other_version}"))
version = parse_version(other_version)
normalized = str(version)
if version.local:
# Remove the local part to accept wider range of prereleases.
normalized = normalized.rsplit("+", 1)[0]
return dataclasses.replace(self, specifier=get_specifier(f"=={normalized}"))

def _hash_key(self) -> tuple:
return (
Expand Down

0 comments on commit c727a4a

Please sign in to comment.