From 0e4b1ace07b369466c0efe240efa9b584c8415ce Mon Sep 17 00:00:00 2001 From: Jeremy Fleischman Date: Thu, 6 Jan 2022 02:34:39 -0800 Subject: [PATCH] RFC: Use a PackageFinder with `ignore_compatibility` when collecting hashes This fixes https://github.com/pypa/pipenv/issues/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. --- .../patched/notpip/_internal/cli/req_command.py | 2 ++ .../notpip/_internal/index/package_finder.py | 2 ++ pipenv/utils.py | 15 ++++++++++++++- pipenv/vendor/pip_shims/compat.py | 3 +++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pipenv/patched/notpip/_internal/cli/req_command.py b/pipenv/patched/notpip/_internal/cli/req_command.py index 17c2209ff6..cab06fb8b4 100644 --- a/pipenv/patched/notpip/_internal/cli/req_command.py +++ b/pipenv/patched/notpip/_internal/cli/req_command.py @@ -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. @@ -450,4 +451,5 @@ def _build_package_finder( link_collector=link_collector, selection_prefs=selection_prefs, target_python=target_python, + ignore_compatibility=ignore_compatibility, ) diff --git a/pipenv/patched/notpip/_internal/index/package_finder.py b/pipenv/patched/notpip/_internal/index/package_finder.py index ab48628c87..9bb1626d31 100644 --- a/pipenv/patched/notpip/_internal/index/package_finder.py +++ b/pipenv/patched/notpip/_internal/index/package_finder.py @@ -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. @@ -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 diff --git a/pipenv/utils.py b/pipenv/utils.py index cb2cecd1d0..a3c9519380 100644 --- a/pipenv/utils.py +++ b/pipenv/utils.py @@ -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 @@ -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 @@ -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 { diff --git a/pipenv/vendor/pip_shims/compat.py b/pipenv/vendor/pip_shims/compat.py index f01f5feaec..67c995d23e 100644 --- a/pipenv/vendor/pip_shims/compat.py +++ b/pipenv/vendor/pip_shims/compat.py @@ -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. @@ -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