Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make pip wheel cache what it built #7285

Merged
merged 1 commit into from
Nov 3, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions news/6852.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Cache wheels that ``pip wheel`` built locally, matching what
``pip install`` does. This particularly helps performance in workflows where
``pip wheel`` is used for `building before installing
<https://pip.pypa.io/en/stable/user_guide/#installing-from-local-packages>`_.
chrahunt marked this conversation as resolved.
Show resolved Hide resolved
Users desiring the original behavior can use ``pip wheel --no-cache-dir``.
45 changes: 28 additions & 17 deletions src/pip/_internal/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -1102,7 +1102,7 @@ def build(
:param should_unpack: If True, after building the wheel, unpack it
and replace the sdist with the unpacked version in preparation
for installation.
:return: True if all the wheels built correctly.
:return: The list of InstallRequirement that failed to build.
"""
# pip install uses should_unpack=True.
# pip install never provides a _wheel_dir.
Expand All @@ -1124,19 +1124,15 @@ def build(
):
continue

# Determine where the wheel should go.
if should_unpack:
if (
cache_available and
should_cache(req, self.check_binary_allowed)
):
output_dir = self.wheel_cache.get_path_for_link(req.link)
else:
output_dir = self.wheel_cache.get_ephem_path_for_link(
req.link
)
if (
cache_available and
should_cache(req, self.check_binary_allowed)
):
output_dir = self.wheel_cache.get_path_for_link(req.link)
else:
output_dir = self._wheel_dir
output_dir = self.wheel_cache.get_ephem_path_for_link(
req.link
)

buildset.append((req, output_dir))

Expand Down Expand Up @@ -1174,10 +1170,6 @@ def build(
python_tag=python_tag,
)
if wheel_file:
build_success.append(req)
self.wheel_filenames.append(
os.path.relpath(wheel_file, output_dir)
)
if should_unpack:
# XXX: This is mildly duplicative with prepare_files,
# but not close enough to pull out to a single common
Expand All @@ -1202,6 +1194,25 @@ def build(
assert req.link.is_wheel
# extract the wheel into the dir
unpack_file(req.link.file_path, req.source_dir)
else:
# copy from cache to target directory
try:
ensure_dir(self._wheel_dir)
shutil.copy(
os.path.join(output_dir, wheel_file),
self._wheel_dir,
)
except OSError as e:
logger.warning(
"Building wheel for %s failed: %s",
chrahunt marked this conversation as resolved.
Show resolved Hide resolved
req.name, e,
)
build_failure.append(req)
chrahunt marked this conversation as resolved.
Show resolved Hide resolved
continue
self.wheel_filenames.append(
os.path.relpath(wheel_file, output_dir)
)
build_success.append(req)
else:
build_failure.append(req)

Expand Down
24 changes: 24 additions & 0 deletions tests/functional/test_wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,30 @@ def test_pip_wheel_success(script, data):
assert "Successfully built simple" in result.stdout, result.stdout


def test_pip_wheel_build_cache(script, data):
"""
Test 'pip wheel' builds and caches.
"""
result = script.pip(
'wheel', '--no-index', '-f', data.find_links,
'simple==3.0',
)
wheel_file_name = 'simple-3.0-py%s-none-any.whl' % pyversion[0]
wheel_file_path = script.scratch / wheel_file_name
assert wheel_file_path in result.files_created, result.stdout
assert "Successfully built simple" in result.stdout, result.stdout
# remove target file
(script.scratch_path / wheel_file_name).unlink()
# pip wheel again and test that no build occurs since
# we get the wheel from cache
result = script.pip(
'wheel', '--no-index', '-f', data.find_links,
'simple==3.0',
)
assert wheel_file_path in result.files_created, result.stdout
assert "Successfully built simple" not in result.stdout, result.stdout


def test_basic_pip_wheel_downloads_wheels(script, data):
"""
Test 'pip wheel' downloads wheels
Expand Down