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

WIP: add --prefer-minimum-versions flag #8086

Closed
wants to merge 3 commits into from
Closed
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
5 changes: 5 additions & 0 deletions news/8085.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Add a ``--prefer-minimum-versions`` command line flag to tell pip to
use older versions instead of newer versions for all
dependencies. This is useful for running test suites using the "lower
bounds" of requirements to ensure that they are accurate. The flag is
only available when the new resolver is enabled.
11 changes: 11 additions & 0 deletions src/pip/_internal/cli/cmdoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,17 @@ def check_list_path_option(options):
) # type: Callable[..., Option]


prefer_minimum_versions = partial(
Option,
'--prefer-minimum-versions',
dest='prefer_minimum_versions',
action='store_true',
default=False,
help=SUPPRESS_HELP, # TODO: Enable this when the resolver actually works.
# help='Use the lowest version that matches a requirement.',
) # type: Callable[..., Option]


##########
# groups #
##########
Expand Down
2 changes: 2 additions & 0 deletions src/pip/_internal/cli/req_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def __init__(self, *args, **kw):
super(RequirementCommand, self).__init__(*args, **kw)

self.cmd_opts.add_option(cmdoptions.no_clean())
self.cmd_opts.add_option(cmdoptions.prefer_minimum_versions())

@staticmethod
def make_requirement_preparer(
Expand Down Expand Up @@ -274,6 +275,7 @@ def make_resolver(
force_reinstall=force_reinstall,
upgrade_strategy=upgrade_strategy,
py_version_info=py_version_info,
prefer_minimum_versions=options.prefer_minimum_versions,
)
import pip._internal.resolution.legacy.resolver
return pip._internal.resolution.legacy.resolver.Resolver(
Expand Down
8 changes: 6 additions & 2 deletions src/pip/_internal/resolution/resolvelib/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ def __init__(
self,
factory, # type: Factory
ignore_dependencies, # type: bool
prefer_minimum_versions=False, # type: bool
):
# type: (...) -> None
self._factory = factory
self._ignore_dependencies = ignore_dependencies
self._prefer_minimum_versions = prefer_minimum_versions

def get_install_requirement(self, c):
# type: (Candidate) -> Optional[InstallRequirement]
Expand All @@ -36,12 +38,14 @@ def get_preference(
information # type: Sequence[Tuple[Requirement, Candidate]]
):
# type: (...) -> Any
# Use the "usual" value for now
return len(candidates)

def find_matches(self, requirement):
# type: (Requirement) -> Sequence[Candidate]
return requirement.find_matches()
results = requirement.find_matches()
if self._prefer_minimum_versions:
results = list(reversed(results))
return results

def is_satisfied_by(self, requirement, candidate):
# type: (Requirement, Candidate) -> bool
Expand Down
3 changes: 3 additions & 0 deletions src/pip/_internal/resolution/resolvelib/resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def __init__(
force_reinstall, # type: bool
upgrade_strategy, # type: str
py_version_info=None, # type: Optional[Tuple[int, ...]]
prefer_minimum_versions=False, # type: bool
):
super(Resolver, self).__init__()
self.factory = Factory(
Expand All @@ -55,6 +56,7 @@ def __init__(
py_version_info=py_version_info,
)
self.ignore_dependencies = ignore_dependencies
self.prefer_minimum_versions = prefer_minimum_versions
self._result = None # type: Optional[Result]

def resolve(self, root_reqs, check_supported_wheels):
Expand All @@ -67,6 +69,7 @@ def resolve(self, root_reqs, check_supported_wheels):
provider = PipProvider(
factory=self.factory,
ignore_dependencies=self.ignore_dependencies,
prefer_minimum_versions=self.prefer_minimum_versions,
)
reporter = BaseReporter()
resolver = RLResolver(provider, reporter)
Expand Down