From 988af6a1095310ea2ed54b82d293b197eb7923c4 Mon Sep 17 00:00:00 2001 From: Vincent Philippon Date: Wed, 4 Oct 2017 17:00:07 -0400 Subject: [PATCH] Updating the patched pip-tools with the wheel dependency bugifx. Aligned with pip-tools commit ef0aa2d62bd5499b328e5f3c9b26130d07be16dd plus pipenv patching. --- pipenv/patched/piptools/repositories/base.py | 8 +++ pipenv/patched/piptools/repositories/local.py | 7 +++ pipenv/patched/piptools/repositories/pypi.py | 51 ++++++++++++------- pipenv/patched/piptools/resolver.py | 4 +- 4 files changed, 49 insertions(+), 21 deletions(-) diff --git a/pipenv/patched/piptools/repositories/base.py b/pipenv/patched/piptools/repositories/base.py index b791eab2..57e85fda 100755 --- a/pipenv/patched/piptools/repositories/base.py +++ b/pipenv/patched/piptools/repositories/base.py @@ -3,6 +3,7 @@ from __future__ import (absolute_import, division, print_function, unicode_literals) from abc import ABCMeta, abstractmethod +from contextlib import contextmanager from six import add_metaclass @@ -38,3 +39,10 @@ class BaseRepository(object): all of the files for a given requirement. It is not acceptable for an editable or unpinned requirement to be passed to this function. """ + + @abstractmethod + @contextmanager + def allow_all_wheels(self): + """ + Monkey patches pip.Wheel to allow wheels from all platforms and Python versions. + """ diff --git a/pipenv/patched/piptools/repositories/local.py b/pipenv/patched/piptools/repositories/local.py index ea3a39b9..8b30052e 100755 --- a/pipenv/patched/piptools/repositories/local.py +++ b/pipenv/patched/piptools/repositories/local.py @@ -2,6 +2,8 @@ from __future__ import (absolute_import, division, print_function, unicode_literals) +from contextlib import contextmanager + from piptools.utils import as_tuple, key_from_req, make_install_requirement from .base import BaseRepository @@ -63,3 +65,8 @@ class LocalRequirementsRepository(BaseRepository): def get_hashes(self, ireq): return self.repository.get_hashes(ireq) + + @contextmanager + def allow_all_wheels(self): + with self.repository.allow_all_wheels(): + yield diff --git a/pipenv/patched/piptools/repositories/pypi.py b/pipenv/patched/piptools/repositories/pypi.py index ee804b1a..fbf33047 100755 --- a/pipenv/patched/piptools/repositories/pypi.py +++ b/pipenv/patched/piptools/repositories/pypi.py @@ -28,24 +28,6 @@ except ImportError: from .._compat import TemporaryDirectory -# Monkey patch pip's Wheel class to support all platform tags. This allows -# pip-tools to generate hashes for all available distributions, not only the -# one for the current platform. - -def _wheel_supported(self, tags=None): - # Ignore current platform. Support everything. - return True - - -def _wheel_support_index_min(self, tags=None): - # All wheels are equal priority for sorting. - return 0 - - -Wheel.supported = _wheel_supported -Wheel.support_index_min = _wheel_support_index_min - - class PyPIRepository(BaseRepository): DEFAULT_INDEX_URL = 'https://pypi.python.org/simple' @@ -184,7 +166,7 @@ class PyPIRepository(BaseRepository): # We need to get all of the candidates that match our current version # pin, these will represent all of the files that could possibly - # satisify this constraint. + # satisfy this constraint. all_candidates = self.find_all_candidates(ireq.name) candidates_by_version = lookup_table(all_candidates, key=lambda c: c.version) matching_versions = list( @@ -203,6 +185,37 @@ class PyPIRepository(BaseRepository): h.update(chunk) return ":".join([FAVORITE_HASH, h.hexdigest()]) + @contextmanager + def allow_all_wheels(self): + """ + Monkey patches pip.Wheel to allow wheels from all platforms and Python versions. + + This also saves the candidate cache and set a new one, or else the results from the + previous non-patched calls will interfere. + """ + def _wheel_supported(self, tags=None): + # Ignore current platform. Support everything. + return True + + def _wheel_support_index_min(self, tags=None): + # All wheels are equal priority for sorting. + return 0 + + original_wheel_supported = Wheel.supported + original_support_index_min = Wheel.support_index_min + original_cache = self._available_candidates_cache + + Wheel.supported = _wheel_supported + Wheel.support_index_min = _wheel_support_index_min + self._available_candidates_cache = {} + + try: + yield + finally: + Wheel.supported = original_wheel_supported + Wheel.support_index_min = original_support_index_min + self._available_candidates_cache = original_cache + @contextmanager def open_local_or_remote_file(link, session): diff --git a/pipenv/patched/piptools/resolver.py b/pipenv/patched/piptools/resolver.py index 021f9014..99f37f48 100755 --- a/pipenv/patched/piptools/resolver.py +++ b/pipenv/patched/piptools/resolver.py @@ -68,7 +68,8 @@ class Resolver(object): """ Finds acceptable hashes for all of the given InstallRequirements. """ - return {ireq: self.repository.get_hashes(ireq) for ireq in ireqs} + with self.repository.allow_all_wheels(): + return {ireq: self.repository.get_hashes(ireq) for ireq in ireqs} def resolve(self, max_rounds=12): """ @@ -248,7 +249,6 @@ class Resolver(object): # NOTE: it's much quicker to immediately return instead of # hitting the index server best_match = ireq - elif is_pinned_requirement(ireq): # NOTE: it's much quicker to immediately return instead of # hitting the index server