mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
Merge pull request #6303 from cjerdonek/issue-5749-no-cache-dir
Whether to build wheels is no longer affected by --no-cache-dir.
This commit is contained in:
commit
df80be3591
3 changed files with 113 additions and 22 deletions
2
news/5749.feature
Normal file
2
news/5749.feature
Normal file
|
@ -0,0 +1,2 @@
|
|||
For consistency, passing ``--no-cache-dir`` no longer affects whether wheels
|
||||
will be built. In this case, a temporary directory is used.
|
|
@ -33,6 +33,43 @@ from pip._internal.wheel import WheelBuilder
|
|||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def is_wheel_installed():
|
||||
"""
|
||||
Return whether the wheel package is installed.
|
||||
"""
|
||||
try:
|
||||
import wheel # noqa: F401
|
||||
except ImportError:
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
def build_wheels(builder, pep517_requirements, legacy_requirements, session):
|
||||
"""
|
||||
Build wheels for requirements, depending on whether wheel is installed.
|
||||
"""
|
||||
# We don't build wheels for legacy requirements if wheel is not installed.
|
||||
should_build_legacy = is_wheel_installed()
|
||||
|
||||
# Always build PEP 517 requirements
|
||||
build_failures = builder.build(
|
||||
pep517_requirements,
|
||||
session=session, autobuilding=True
|
||||
)
|
||||
|
||||
if should_build_legacy:
|
||||
# We don't care about failures building legacy
|
||||
# requirements, as we'll fall through to a direct
|
||||
# install for those.
|
||||
builder.build(
|
||||
legacy_requirements,
|
||||
session=session, autobuilding=True
|
||||
)
|
||||
|
||||
return build_failures
|
||||
|
||||
|
||||
class InstallCommand(RequirementCommand):
|
||||
"""
|
||||
Install packages from:
|
||||
|
@ -327,34 +364,18 @@ class InstallCommand(RequirementCommand):
|
|||
else:
|
||||
legacy_requirements.append(req)
|
||||
|
||||
# We don't build wheels for legacy requirements if we
|
||||
# don't have wheel installed or we don't have a cache dir
|
||||
try:
|
||||
import wheel # noqa: F401
|
||||
build_legacy = bool(options.cache_dir)
|
||||
except ImportError:
|
||||
build_legacy = False
|
||||
|
||||
wb = WheelBuilder(
|
||||
wheel_builder = WheelBuilder(
|
||||
finder, preparer, wheel_cache,
|
||||
build_options=[], global_options=[],
|
||||
)
|
||||
|
||||
# Always build PEP 517 requirements
|
||||
build_failures = wb.build(
|
||||
pep517_requirements,
|
||||
session=session, autobuilding=True
|
||||
build_failures = build_wheels(
|
||||
builder=wheel_builder,
|
||||
pep517_requirements=pep517_requirements,
|
||||
legacy_requirements=legacy_requirements,
|
||||
session=session,
|
||||
)
|
||||
|
||||
if build_legacy:
|
||||
# We don't care about failures building legacy
|
||||
# requirements, as we'll fall through to a direct
|
||||
# install for those.
|
||||
wb.build(
|
||||
legacy_requirements,
|
||||
session=session, autobuilding=True
|
||||
)
|
||||
|
||||
# If we're using PEP 517, we cannot do a direct install
|
||||
# so we fail here.
|
||||
if build_failures:
|
||||
|
|
68
tests/unit/test_command_install.py
Normal file
68
tests/unit/test_command_install.py
Normal file
|
@ -0,0 +1,68 @@
|
|||
from mock import Mock, call, patch
|
||||
|
||||
from pip._internal.commands.install import build_wheels
|
||||
|
||||
|
||||
class TestWheelCache:
|
||||
|
||||
def check_build_wheels(
|
||||
self,
|
||||
pep517_requirements,
|
||||
legacy_requirements,
|
||||
session,
|
||||
):
|
||||
"""
|
||||
Return: (mock_calls, return_value).
|
||||
"""
|
||||
def build(reqs, **kwargs):
|
||||
# Fail the first requirement.
|
||||
return [reqs[0]]
|
||||
|
||||
builder = Mock()
|
||||
builder.build.side_effect = build
|
||||
|
||||
build_failures = build_wheels(
|
||||
builder=builder,
|
||||
pep517_requirements=pep517_requirements,
|
||||
legacy_requirements=legacy_requirements,
|
||||
# A session value isn't needed.
|
||||
session='<session>',
|
||||
)
|
||||
|
||||
return (builder.build.mock_calls, build_failures)
|
||||
|
||||
@patch('pip._internal.commands.install.is_wheel_installed')
|
||||
def test_build_wheels__wheel_installed(self, is_wheel_installed):
|
||||
is_wheel_installed.return_value = True
|
||||
|
||||
mock_calls, build_failures = self.check_build_wheels(
|
||||
pep517_requirements=['a', 'b'],
|
||||
legacy_requirements=['c', 'd'],
|
||||
session='<session>',
|
||||
)
|
||||
|
||||
# Legacy requirements were built.
|
||||
assert mock_calls == [
|
||||
call(['a', 'b'], autobuilding=True, session='<session>'),
|
||||
call(['c', 'd'], autobuilding=True, session='<session>'),
|
||||
]
|
||||
|
||||
# Legacy build failures are not included in the return value.
|
||||
assert build_failures == ['a']
|
||||
|
||||
@patch('pip._internal.commands.install.is_wheel_installed')
|
||||
def test_build_wheels__wheel_not_installed(self, is_wheel_installed):
|
||||
is_wheel_installed.return_value = False
|
||||
|
||||
mock_calls, build_failures = self.check_build_wheels(
|
||||
pep517_requirements=['a', 'b'],
|
||||
legacy_requirements=['c', 'd'],
|
||||
session='<session>',
|
||||
)
|
||||
|
||||
# Legacy requirements were not built.
|
||||
assert mock_calls == [
|
||||
call(['a', 'b'], autobuilding=True, session='<session>'),
|
||||
]
|
||||
|
||||
assert build_failures == ['a']
|
Loading…
Reference in a new issue