mirror of https://github.com/pypa/pip
Remove dependence on PackageFinder in WheelBuilder.build
Merge pull request #6977 from chrahunt/refactor/wheel-build-progress
This commit is contained in:
commit
ebedce48c3
|
@ -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 = []
|
||||
|
@ -376,8 +393,9 @@ 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,
|
||||
)
|
||||
|
||||
build_failures = build_wheels(
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -53,11 +53,11 @@ 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
|
||||
from pip._internal.index import FormatControl, PackageFinder
|
||||
from pip._internal.operations.prepare import (
|
||||
RequirementPreparer
|
||||
)
|
||||
|
@ -66,6 +66,8 @@ if MYPY_CHECK_RUNNING:
|
|||
|
||||
InstalledCSVRow = Tuple[str, ...]
|
||||
|
||||
BinaryAllowedPredicate = Callable[[InstallRequirement], bool]
|
||||
|
||||
|
||||
VERSION_COMPATIBLE = (1, 0)
|
||||
|
||||
|
@ -775,9 +777,9 @@ def _contains_egg_info(
|
|||
|
||||
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,10 +811,9 @@ 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 bdist_wheel for %s, due to binaries "
|
||||
"Skipping wheel build for %s, due to binaries "
|
||||
"being disabled for it.", req.name,
|
||||
)
|
||||
return None
|
||||
|
@ -887,20 +888,27 @@ 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."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
finder, # type: PackageFinder
|
||||
preparer, # type: RequirementPreparer
|
||||
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 +916,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):
|
||||
|
@ -1058,15 +1067,14 @@ 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,
|
||||
)
|
||||
if ephem_cache is None:
|
||||
continue
|
||||
|
|
|
@ -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,10 +99,11 @@ 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,
|
||||
cache_available=cache_available,
|
||||
req, should_unpack=should_unpack,
|
||||
cache_available=cache_available, check_binary_allowed=always_true,
|
||||
)
|
||||
assert ephem_cache is expected
|
||||
|
||||
|
@ -138,14 +138,12 @@ 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,
|
||||
cache_available=True,
|
||||
req, should_unpack=True,
|
||||
cache_available=True, check_binary_allowed=check_binary_allowed,
|
||||
)
|
||||
assert ephem_cache is expected
|
||||
|
||||
|
@ -696,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),
|
||||
)
|
||||
|
|
Loading…
Reference in New Issue