Skip to content

Commit

Permalink
RFC: Use a PackageFinder with ignore_compatibility when collecting …
Browse files Browse the repository at this point in the history
…hashes

This fixes #4885

This is totally not ready to merge up yet, but I wanted to some early
feedback on this, as this is come I'm quite unfamiliar with.

Open questions:

1. Is "ignore_compatibility" really the right functionality to be using
   here? Hopefully it only ignores platform-related compatibility but
   not Python version?
2. I've made some minor changes here to vendored pip code to thread this
   `ignore_compatibility` parameter around. Is that ok?

TODO:

1. Actually write a unittest of this case if possible.
  • Loading branch information
jfly committed Jan 6, 2022
1 parent 3ab4763 commit 0e4b1ac
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pipenv/patched/notpip/_internal/cli/req_command.py
Expand Up @@ -430,6 +430,7 @@ def _build_package_finder(
session: PipSession,
target_python: Optional[TargetPython] = None,
ignore_requires_python: Optional[bool] = None,
ignore_compatibility: bool = False,
) -> PackageFinder:
"""
Create a package finder appropriate to this requirement command.
Expand All @@ -450,4 +451,5 @@ def _build_package_finder(
link_collector=link_collector,
selection_prefs=selection_prefs,
target_python=target_python,
ignore_compatibility=ignore_compatibility,
)
2 changes: 2 additions & 0 deletions pipenv/patched/notpip/_internal/index/package_finder.py
Expand Up @@ -628,6 +628,7 @@ def create(
link_collector: LinkCollector,
selection_prefs: SelectionPreferences,
target_python: Optional[TargetPython] = None,
ignore_compatibility: bool=False,
) -> "PackageFinder":
"""Create a PackageFinder.
Expand All @@ -652,6 +653,7 @@ def create(
allow_yanked=selection_prefs.allow_yanked,
format_control=selection_prefs.format_control,
ignore_requires_python=selection_prefs.ignore_requires_python,
ignore_compatibility=ignore_compatibility,
)

@property
Expand Down
15 changes: 14 additions & 1 deletion pipenv/utils.py
Expand Up @@ -428,6 +428,7 @@ def __init__(
self._parsed_constraints = None
self._resolver = None
self._finder = None
self._ignore_compatibility_finder = None
self._session = None
self._constraint_file = None
self._pip_options = None
Expand Down Expand Up @@ -798,6 +799,18 @@ def finder(self):
)
return self._finder

@property
def ignore_compatibility_finder(self):
from pipenv.vendor.pip_shims import shims
if self._ignore_compatibility_finder is None:
self._ignore_compatibility_finder = shims.get_package_finder(
install_cmd=self.pip_command,
options=self.pip_options,
session=self.session,
ignore_compatibility=False,
)
return self._ignore_compatibility_finder

@property
def parsed_constraints(self):
from pipenv.vendor.pip_shims import shims
Expand Down Expand Up @@ -950,7 +963,7 @@ def collect_hashes(self, ireq):
if hashes:
return hashes

applicable_candidates = self.finder.find_best_candidate(
applicable_candidates = self.ignore_compatibility_finder.find_best_candidate(
ireq.name, ireq.specifier
).iter_applicable()
return {
Expand Down
3 changes: 3 additions & 0 deletions pipenv/vendor/pip_shims/compat.py
Expand Up @@ -588,6 +588,7 @@ def get_package_finder(
ignore_requires_python=None, # type: Optional[bool]
target_python_builder=None, # type: Optional[TShimmedFunc]
install_cmd_provider=None, # type: Optional[TShimmedFunc]
ignore_compatibility=False,
):
# type: (...) -> TFinder
"""Shim for compatibility to generate package finders.
Expand Down Expand Up @@ -693,6 +694,8 @@ def get_package_finder(
and "ignore_requires_python" in builder_args.args
):
build_kwargs["ignore_requires_python"] = ignore_requires_python

build_kwargs['ignore_compatibility'] = ignore_compatibility
return install_cmd._build_package_finder(**build_kwargs) # type: ignore


Expand Down

0 comments on commit 0e4b1ac

Please sign in to comment.