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 calculation of PipProvider._known_depths #10482

Merged
merged 18 commits into from
Sep 26, 2021
Merged
Show file tree
Hide file tree
Changes from 16 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/10482.bugfix.rst
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.
2 changes: 1 addition & 1 deletion src/pip/_internal/resolution/resolvelib/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ def get_preference(
for _, parent in information[identifier]
)
inferred_depth = min(d for d in parent_depths) + 1.0
self._known_depths[identifier] = inferred_depth
else:
inferred_depth = 1.0
self._known_depths[identifier] = inferred_depth

requested_order = self._user_requested.get(identifier, math.inf)

Expand Down
65 changes: 65 additions & 0 deletions tests/unit/resolution_resolvelib/test_provider.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
from pip._vendor.resolvelib.resolvers import RequirementInformation

from pip._internal.models.candidate import InstallationCandidate
from pip._internal.models.link import Link
from pip._internal.req.constructors import install_req_from_req_string
from pip._internal.resolution.resolvelib.provider import PipProvider
from pip._internal.resolution.resolvelib.requirements import SpecifierRequirement


def build_requirement_information(name, parent):
install_requirement = install_req_from_req_string(name)
requirement_information = RequirementInformation(
requirement=SpecifierRequirement(install_requirement), parent=parent
)
return [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_information = build_requirement_information(
name=root_requirement_name, parent=None
)
provider.get_preference(
identifier=root_requirement_name,
resolutions={},
candidates={},
information={root_requirement_name: root_requirement_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_information = build_requirement_information(
name=transative_requirement_name, parent=root_package_candidate
)
provider.get_preference(
identifier=transative_requirement_name,
resolutions={},
candidates={},
information={
root_requirement_name: root_requirement_information,
transative_requirement_name: transative_package_information,
},
)
assert provider._known_depths == {
transative_requirement_name: 2.0,
root_requirement_name: 1.0,
}