Skip to content

Commit

Permalink
Make pip wheel cache what it built
Browse files Browse the repository at this point in the history
Just like pip install.
  • Loading branch information
sbidoul committed Nov 2, 2019
1 parent 799596e commit a8395f0
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 12 deletions.
4 changes: 4 additions & 0 deletions news/6852.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
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>`_.
35 changes: 23 additions & 12 deletions src/pip/_internal/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 @@ -1202,6 +1198,21 @@ 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 durectory
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",
req.name, e,
)
build_failure.append(req)
continue
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

0 comments on commit a8395f0

Please sign in to comment.