-
-
Notifications
You must be signed in to change notification settings - Fork 468
feat: implement conflict promotion logic in requirement selection #3751
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
Merged
+118
−6
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| from __future__ import annotations | ||
|
|
||
| from collections.abc import Iterator | ||
|
|
||
| from resolvelib.resolvers import RequirementInformation | ||
|
|
||
| from pdm.models.candidates import Candidate | ||
| from pdm.models.requirements import parse_requirement | ||
| from pdm.resolver.providers import _CONFLICT_PRIORITY_THRESHOLD | ||
|
|
||
|
|
||
| def _build_candidates(identifier: str) -> dict[str, Iterator[Candidate]]: | ||
| requirement = parse_requirement(identifier) | ||
| candidate = Candidate(requirement, name=requirement.project_name, version="1.0") | ||
| return {identifier: iter([candidate])} | ||
|
|
||
|
|
||
| def _build_information(identifier: str) -> dict[str, Iterator[RequirementInformation]]: | ||
| requirement = parse_requirement(identifier) | ||
| return {identifier: iter([RequirementInformation(requirement, None)])} | ||
|
|
||
|
|
||
| def test_narrow_requirement_selection_promotes_repeated_conflicts(project, repository): | ||
| repository.add_candidate("conflict-pkg", "1.0") | ||
| repository.add_candidate("other-pkg", "1.0") | ||
|
|
||
| provider = project.get_provider() | ||
| narrow = provider.narrow_requirement_selection | ||
| causes = [RequirementInformation(parse_requirement("conflict-pkg"), None)] | ||
|
|
||
| for _ in range(1, _CONFLICT_PRIORITY_THRESHOLD): | ||
| result = list(narrow(["other-pkg"], {}, {}, {}, causes)) | ||
| assert result == ["other-pkg"] | ||
|
|
||
| result = list(narrow(["other-pkg", "conflict-pkg"], {}, {}, {}, causes)) | ||
| assert result == ["conflict-pkg"] | ||
|
|
||
| result = list(narrow(["other-pkg", "conflict-pkg"], {}, {}, {}, [])) | ||
| assert result == ["conflict-pkg"] | ||
|
|
||
| other_causes = [RequirementInformation(parse_requirement("other-pkg"), None)] | ||
| result = list(narrow(["other-pkg", "conflict-pkg"], {}, {}, {}, other_causes)) | ||
| assert result == ["other-pkg"] | ||
|
|
||
|
|
||
| def test_get_preference_prioritizes_promoted_conflicts(project, repository): | ||
| repository.add_candidate("promoted-pkg", "1.0") | ||
| repository.add_candidate("normal-pkg", "1.0") | ||
|
|
||
| provider = project.get_provider() | ||
| provider._conflict_promoted.add("promoted-pkg") | ||
|
|
||
| promoted_preference = provider.get_preference( | ||
| "promoted-pkg", | ||
| {}, | ||
| _build_candidates("promoted-pkg"), | ||
| _build_information("promoted-pkg"), | ||
| [], | ||
| ) | ||
| normal_preference = provider.get_preference( | ||
| "normal-pkg", | ||
| {}, | ||
| _build_candidates("normal-pkg"), | ||
| _build_information("normal-pkg"), | ||
| [], | ||
| ) | ||
|
|
||
| assert promoted_preference < normal_preference |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This increments
_conflict_countsevery timenarrow_requirement_selection()runs with the lastbacktrack_causes, but resolvelib keeps that samebacktrack_causeslist across subsequent successful rounds. In practice, a package that conflicted once can cross the threshold after a few unrelated pins and get added to_conflict_promotedpermanently. That turns this into a “stale last conflict” heuristic instead of a “repeated conflicts” heuristic, which can reorder later rounds badly enough to hitresolve_max_roundson otherwise-solvable dependency sets.Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How to fix this? @codex
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To use Codex here, create an environment for this repo.