Skip to content

Commit

Permalink
Merge pull request #968 from atugushev/cleanup-wheel-cache
Browse files Browse the repository at this point in the history
Cleanup ephemeral wheel cache properly
  • Loading branch information
atugushev authored Nov 25, 2019
2 parents 71a5948 + 40d74a6 commit e1b86a1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 4 additions & 4 deletions piptools/repositories/pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,10 +274,10 @@ def get_dependencies(self, ireq):
os.environ["PIP_REQ_TRACKER"] = prev_tracker
else:
del os.environ["PIP_REQ_TRACKER"]
try:
self.wheel_cache.cleanup()
except AttributeError:
pass

# WheelCache.cleanup() introduced in pip==10.0.0
if PIP_VERSION >= (10,):
wheel_cache.cleanup()
return self._dependencies_cache[ireq]

def get_hashes(self, ireq):
Expand Down
16 changes: 16 additions & 0 deletions tests/test_repository_pypi.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,3 +174,19 @@ def test_pypirepo_calls_reqset_with_str_paths(pypi_repository, from_line):
assert isinstance(called_with_finder, PackageFinder)
assert called_with_ireq == ireq
assert not pf_call_kwargs


@pytest.mark.skipif(
PIP_VERSION < (10,), reason="WheelCache.cleanup() introduced in pip==10.0.0"
)
@mock.patch("piptools.repositories.pypi.PyPIRepository.resolve_reqs") # to run offline
@mock.patch("piptools.repositories.pypi.WheelCache")
def test_wheel_cache_cleanup_called(
WheelCache, resolve_reqs, pypi_repository, from_line
):
"""
Test WheelCache.cleanup() called once after dependency resolution.
"""
ireq = from_line("six==1.10.0")
pypi_repository.get_dependencies(ireq)
WheelCache.return_value.cleanup.assert_called_once_with()

0 comments on commit e1b86a1

Please sign in to comment.