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

fix: allow prereleases when the requirement is pinned even if disabled by project #3202

Merged
merged 2 commits into from
Oct 11, 2024
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/3202.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Allow prereleases when the requirement is pinned even if disabled by project
8 changes: 6 additions & 2 deletions src/pdm/resolver/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,8 @@ def _find_candidates(self, requirement: Requirement) -> Iterable[Candidate]:
return [can]
else:
prerelease = requirement.prerelease
if prerelease is None and requirement.is_pinned and requirement.specifier.prereleases:
prerelease = True
if prerelease is None and (key := requirement.identify()) in self.locked_candidates:
# keep the prerelease if it is locked
candidates = self.locked_candidates[key]
Expand Down Expand Up @@ -265,8 +267,10 @@ def is_satisfied_by(self, requirement: Requirement, candidate: Candidate) -> boo
# This should be a URL candidate or self package, consider it to be matching
return True
# Allow prereleases if: 1) it is not specified in the tool settings or
# 2) the candidate doesn't come from PyPI index.
allow_prereleases = self.allow_prereleases in (True, None) or not candidate.req.is_named
# 2) the candidate doesn't come from PyPI index or 3) the requirement is pinned
allow_prereleases = (
self.allow_prereleases in (True, None) or not candidate.req.is_named or requirement.is_pinned
)
return requirement.specifier.contains(version, allow_prereleases)

def get_dependencies(self, candidate: Candidate) -> list[Requirement]:
Expand Down
5 changes: 5 additions & 0 deletions tests/resolver/test_resolve.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,11 @@ def test_resolve_allow_prereleases(resolve, repository):
resolve(["bar"], allow_prereleases=False)


def test_resolve_prereleases_if_disabled_by_project(resolve):
result = resolve(["urllib3==1.23b0"], allow_prereleases=False)
assert result["urllib3"].version == "1.23b0"


def test_resolve_with_extras(resolve):
result = resolve(["requests[socks]"])
assert result["pysocks"].version == "1.5.6"
Expand Down
Loading