From ec4f59c8aa926e6a31b6e011ebf0bb190680f7e4 Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Wed, 4 Sep 2019 20:13:42 -0400 Subject: [PATCH 1/3] Change 'bdist_wheel' to 'wheel build'. --- src/pip/_internal/wheel.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pip/_internal/wheel.py b/src/pip/_internal/wheel.py index bc0cdd260..fabfc2dae 100644 --- a/src/pip/_internal/wheel.py +++ b/src/pip/_internal/wheel.py @@ -812,7 +812,7 @@ def should_use_ephemeral_cache( if "binary" not in format_control.get_allowed_formats( canonicalize_name(req.name)): logger.info( - "Skipping bdist_wheel for %s, due to binaries " + "Skipping wheel build for %s, due to binaries " "being disabled for it.", req.name, ) return None From a4102d179aeb3fadd8945edc911622722e55f4c9 Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Wed, 4 Sep 2019 20:55:11 -0400 Subject: [PATCH 2/3] Don't check allowed format in wheel.py, pass function to do check. --- src/pip/_internal/commands/install.py | 18 ++++++++++++++++++ src/pip/_internal/wheel.py | 22 ++++++++++++++++++---- tests/unit/test_wheel.py | 9 +++++++-- 3 files changed, 43 insertions(+), 6 deletions(-) diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py index bd8a2a26d..4637f030c 100644 --- a/src/pip/_internal/commands/install.py +++ b/src/pip/_internal/commands/install.py @@ -15,6 +15,7 @@ import shutil from optparse import SUPPRESS_HELP from pip._vendor import pkg_resources +from pip._vendor.packaging.utils import canonicalize_name from pip._internal.cache import WheelCache from pip._internal.cli import cmdoptions @@ -46,7 +47,9 @@ if MYPY_CHECK_RUNNING: from optparse import Values from typing import Any, List + from pip._internal.models.format_control import FormatControl from pip._internal.req.req_install import InstallRequirement + from pip._internal.wheel import BinaryAllowedPredicate logger = logging.getLogger(__name__) @@ -94,6 +97,17 @@ def build_wheels( return build_failures +def get_check_binary_allowed(format_control): + # type: (FormatControl) -> BinaryAllowedPredicate + def check_binary_allowed(req): + # type: (InstallRequirement) -> bool + canonical_name = canonicalize_name(req.name) + allowed_formats = format_control.get_allowed_formats(canonical_name) + return "binary" in allowed_formats + + return check_binary_allowed + + class InstallCommand(RequirementCommand): """ Install packages from: @@ -366,6 +380,9 @@ class InstallCommand(RequirementCommand): modifying_pip=requirement_set.has_requirement("pip") ) + check_binary_allowed = get_check_binary_allowed( + finder.format_control + ) # Consider legacy and PEP517-using requirements separately legacy_requirements = [] pep517_requirements = [] @@ -378,6 +395,7 @@ class InstallCommand(RequirementCommand): wheel_builder = WheelBuilder( finder, preparer, wheel_cache, build_options=[], global_options=[], + check_binary_allowed=check_binary_allowed, ) build_failures = build_wheels( diff --git a/src/pip/_internal/wheel.py b/src/pip/_internal/wheel.py index fabfc2dae..27fb4bd73 100644 --- a/src/pip/_internal/wheel.py +++ b/src/pip/_internal/wheel.py @@ -53,7 +53,8 @@ from pip._internal.utils.ui import open_spinner if MYPY_CHECK_RUNNING: from typing import ( - Dict, List, Optional, Sequence, Mapping, Tuple, IO, Text, Any, Iterable + Dict, List, Optional, Sequence, Mapping, Tuple, IO, Text, Any, + Iterable, Callable, ) from pip._vendor.packaging.requirements import Requirement from pip._internal.req.req_install import InstallRequirement @@ -66,6 +67,8 @@ if MYPY_CHECK_RUNNING: InstalledCSVRow = Tuple[str, ...] + BinaryAllowedPredicate = Callable[[InstallRequirement], bool] + VERSION_COMPATIBLE = (1, 0) @@ -777,7 +780,8 @@ def should_use_ephemeral_cache( req, # type: InstallRequirement format_control, # type: FormatControl should_unpack, # type: bool - cache_available # type: bool + cache_available, # type: bool + check_binary_allowed, # type: BinaryAllowedPredicate ): # type: (...) -> Optional[bool] """ @@ -809,8 +813,7 @@ def should_use_ephemeral_cache( if req.editable or not req.source_dir: return None - if "binary" not in format_control.get_allowed_formats( - canonicalize_name(req.name)): + if not check_binary_allowed(req): logger.info( "Skipping wheel build for %s, due to binaries " "being disabled for it.", req.name, @@ -887,6 +890,10 @@ def get_legacy_build_wheel_path( return os.path.join(temp_dir, names[0]) +def _always_true(_): + return True + + class WheelBuilder(object): """Build wheels from a RequirementSet.""" @@ -897,10 +904,15 @@ class WheelBuilder(object): wheel_cache, # type: WheelCache build_options=None, # type: Optional[List[str]] global_options=None, # type: Optional[List[str]] + check_binary_allowed=None, # type: Optional[BinaryAllowedPredicate] no_clean=False # type: bool ): # type: (...) -> None self.finder = finder + if check_binary_allowed is None: + # Binaries allowed by default. + check_binary_allowed = _always_true + self.preparer = preparer self.wheel_cache = wheel_cache @@ -908,6 +920,7 @@ class WheelBuilder(object): self.build_options = build_options or [] self.global_options = global_options or [] + self.check_binary_allowed = check_binary_allowed self.no_clean = no_clean def _build_one(self, req, output_dir, python_tag=None): @@ -1067,6 +1080,7 @@ class WheelBuilder(object): format_control=format_control, should_unpack=should_unpack, cache_available=cache_available, + check_binary_allowed=self.check_binary_allowed, ) if ephem_cache is None: continue diff --git a/tests/unit/test_wheel.py b/tests/unit/test_wheel.py index 449da28c1..982529bd7 100644 --- a/tests/unit/test_wheel.py +++ b/tests/unit/test_wheel.py @@ -101,9 +101,12 @@ def test_should_use_ephemeral_cache__issue_6197( assert req.link.is_artifact format_control = FormatControl() + + always_true = Mock(return_value=True) + ephem_cache = wheel.should_use_ephemeral_cache( req, format_control=format_control, should_unpack=should_unpack, - cache_available=cache_available, + cache_available=cache_available, check_binary_allowed=always_true, ) assert ephem_cache is expected @@ -142,10 +145,12 @@ def test_should_use_ephemeral_cache__disallow_binaries_and_vcs_checkout( if disallow_binaries: format_control.disallow_binaries() + check_binary_allowed = Mock(return_value=not disallow_binaries) + # The cache_available value doesn't matter for this test. ephem_cache = wheel.should_use_ephemeral_cache( req, format_control=format_control, should_unpack=True, - cache_available=True, + cache_available=True, check_binary_allowed=check_binary_allowed, ) assert ephem_cache is expected From b63ea9cd08a5ced1f061aef36cac470ecddce815 Mon Sep 17 00:00:00 2001 From: Chris Hunt Date: Wed, 4 Sep 2019 21:10:34 -0400 Subject: [PATCH 3/3] Remove now-unused finder and format_control from WheelBuilder. --- src/pip/_internal/commands/install.py | 2 +- src/pip/_internal/commands/wheel.py | 2 +- src/pip/_internal/wheel.py | 6 ------ tests/unit/test_wheel.py | 12 ++---------- 4 files changed, 4 insertions(+), 18 deletions(-) diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py index 4637f030c..b1acee94a 100644 --- a/src/pip/_internal/commands/install.py +++ b/src/pip/_internal/commands/install.py @@ -393,7 +393,7 @@ class InstallCommand(RequirementCommand): legacy_requirements.append(req) wheel_builder = WheelBuilder( - finder, preparer, wheel_cache, + preparer, wheel_cache, build_options=[], global_options=[], check_binary_allowed=check_binary_allowed, ) diff --git a/src/pip/_internal/commands/wheel.py b/src/pip/_internal/commands/wheel.py index 7b0c799b2..635dedca6 100644 --- a/src/pip/_internal/commands/wheel.py +++ b/src/pip/_internal/commands/wheel.py @@ -154,7 +154,7 @@ class WheelCommand(RequirementCommand): # build wheels wb = WheelBuilder( - finder, preparer, wheel_cache, + preparer, wheel_cache, build_options=options.build_options or [], global_options=options.global_options or [], no_clean=options.no_clean, diff --git a/src/pip/_internal/wheel.py b/src/pip/_internal/wheel.py index 27fb4bd73..e90799a1d 100644 --- a/src/pip/_internal/wheel.py +++ b/src/pip/_internal/wheel.py @@ -58,7 +58,6 @@ if MYPY_CHECK_RUNNING: ) from pip._vendor.packaging.requirements import Requirement from pip._internal.req.req_install import InstallRequirement - from pip._internal.index import FormatControl, PackageFinder from pip._internal.operations.prepare import ( RequirementPreparer ) @@ -778,7 +777,6 @@ def _contains_egg_info( def should_use_ephemeral_cache( req, # type: InstallRequirement - format_control, # type: FormatControl should_unpack, # type: bool cache_available, # type: bool check_binary_allowed, # type: BinaryAllowedPredicate @@ -899,7 +897,6 @@ class WheelBuilder(object): def __init__( self, - finder, # type: PackageFinder preparer, # type: RequirementPreparer wheel_cache, # type: WheelCache build_options=None, # type: Optional[List[str]] @@ -908,7 +905,6 @@ class WheelBuilder(object): no_clean=False # type: bool ): # type: (...) -> None - self.finder = finder if check_binary_allowed is None: # Binaries allowed by default. check_binary_allowed = _always_true @@ -1071,13 +1067,11 @@ class WheelBuilder(object): ) buildset = [] - format_control = self.finder.format_control cache_available = bool(self.wheel_cache.cache_dir) for req in requirements: ephem_cache = should_use_ephemeral_cache( req, - format_control=format_control, should_unpack=should_unpack, cache_available=cache_available, check_binary_allowed=self.check_binary_allowed, diff --git a/tests/unit/test_wheel.py b/tests/unit/test_wheel.py index 982529bd7..6d21980f0 100644 --- a/tests/unit/test_wheel.py +++ b/tests/unit/test_wheel.py @@ -10,7 +10,6 @@ from pip._vendor.packaging.requirements import Requirement from pip._internal import pep425tags, wheel from pip._internal.exceptions import InvalidWheelFilename, UnsupportedWheel -from pip._internal.index import FormatControl from pip._internal.models.link import Link from pip._internal.req.req_install import InstallRequirement from pip._internal.utils.compat import WINDOWS @@ -100,12 +99,10 @@ def test_should_use_ephemeral_cache__issue_6197( assert not req.is_wheel assert req.link.is_artifact - format_control = FormatControl() - always_true = Mock(return_value=True) ephem_cache = wheel.should_use_ephemeral_cache( - req, format_control=format_control, should_unpack=should_unpack, + req, should_unpack=should_unpack, cache_available=cache_available, check_binary_allowed=always_true, ) assert ephem_cache is expected @@ -141,15 +138,11 @@ def test_should_use_ephemeral_cache__disallow_binaries_and_vcs_checkout( assert not req.is_wheel assert req.link.is_vcs - format_control = FormatControl() - if disallow_binaries: - format_control.disallow_binaries() - check_binary_allowed = Mock(return_value=not disallow_binaries) # The cache_available value doesn't matter for this test. ephem_cache = wheel.should_use_ephemeral_cache( - req, format_control=format_control, should_unpack=True, + req, should_unpack=True, cache_available=True, check_binary_allowed=check_binary_allowed, ) assert ephem_cache is expected @@ -701,7 +694,6 @@ class TestWheelBuilder(object): as mock_build_one: wheel_req = Mock(is_wheel=True, editable=False, constraint=False) wb = wheel.WheelBuilder( - finder=Mock(), preparer=Mock(), wheel_cache=Mock(cache_dir=None), )