-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Fix calculation of PipProvider._known_depths #10482
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
Merged
Changes from 14 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
43557d7
Fix known depth calculation
notatallshaw bba7e31
Add news item
notatallshaw f670368
Newline
notatallshaw 4cd08f7
News items attempt 2
notatallshaw 27da199
First attempt at provider known depths test
notatallshaw 478c5e5
Remove comments, add new line
notatallshaw 4852663
Fix lint issues
notatallshaw 0e40c94
Fix comment
notatallshaw b8ff7f3
Replace build_iter_view with iter
notatallshaw f226b2f
Fix linting
notatallshaw 7242912
Simplify test
notatallshaw d7bd6dc
Typo
notatallshaw 8aef5c2
Add argument names
notatallshaw 9844d79
Better names
notatallshaw 23050df
Replace requirement creation with install_req_from_req_string
notatallshaw d311c8c
further simplification
notatallshaw 9c52c75
Deep is more consistent than down
notatallshaw 105a328
Update news/10482.bugfix.rst
notatallshaw 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
New resolver: Fixes depth ordering of packages during resolution, e.g. a package 2 levels of dependency down will be ordered before a package 3 levels of dependecy down. |
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,84 @@ | ||
import operator | ||
|
||
from pip._vendor.packaging.requirements import Requirement | ||
from pip._vendor.resolvelib.resolvers import Criterion, RequirementInformation | ||
from pip._vendor.resolvelib.structs import IteratorMapping | ||
|
||
from pip._internal.models.candidate import InstallationCandidate | ||
from pip._internal.models.link import Link | ||
from pip._internal.req.req_install import InstallRequirement | ||
from pip._internal.resolution.resolvelib.provider import PipProvider | ||
from pip._internal.resolution.resolvelib.requirements import SpecifierRequirement | ||
|
||
|
||
def build_package_criterion(provider, name, parent): | ||
install_requirement = InstallRequirement( | ||
Requirement(name), "-r requirements.txt (line 1)" | ||
) | ||
matches = provider.find_matches( | ||
identifier=name, | ||
requirements={name: iter([SpecifierRequirement(install_requirement)])}, | ||
incompatibilities={name: iter([])}, | ||
) | ||
requirement_information = RequirementInformation( | ||
requirement=SpecifierRequirement(install_requirement), parent=parent | ||
) | ||
return Criterion(iter(matches), [requirement_information], []) | ||
|
||
|
||
def test_provider_known_depths(factory): | ||
# Root requirement is specified by the user | ||
# therefore has an infered depth of 1 | ||
root_requirement_name = "my-package" | ||
provider = PipProvider( | ||
factory=factory, | ||
constraints={}, | ||
ignore_dependencies=False, | ||
upgrade_strategy="to-satisfy-only", | ||
user_requested={root_requirement_name: 0}, | ||
) | ||
|
||
root_requirement_criteron = build_package_criterion( | ||
provider=provider, name=root_requirement_name, parent=None | ||
) | ||
provider.get_preference( | ||
identifier=root_requirement_name, | ||
resolutions={}, | ||
candidates={}, | ||
information=IteratorMapping( | ||
{root_requirement_name: root_requirement_criteron}, | ||
operator.attrgetter("information"), | ||
), | ||
) | ||
assert provider._known_depths == {root_requirement_name: 1.0} | ||
|
||
# Transative requirement is a dependency of root requirement | ||
# theforefore has an infered depth of 2 | ||
root_package_candidate = InstallationCandidate( | ||
root_requirement_name, | ||
"1.0", | ||
Link("https://{root_requirement_name}.com"), | ||
) | ||
transative_requirement_name = "my-transitive-package" | ||
|
||
transative_package_criterion = build_package_criterion( | ||
provider=provider, | ||
name=transative_requirement_name, | ||
parent=root_package_candidate, | ||
) | ||
provider.get_preference( | ||
identifier=transative_requirement_name, | ||
resolutions={}, | ||
candidates={}, | ||
information=IteratorMapping( | ||
{ | ||
root_requirement_name: root_requirement_criteron, | ||
transative_requirement_name: transative_package_criterion, | ||
}, | ||
operator.attrgetter("information"), | ||
), | ||
notatallshaw marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
assert provider._known_depths == { | ||
transative_requirement_name: 2.0, | ||
root_requirement_name: 1.0, | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.