Skip to content

Commit

Permalink
Cleanup wheel cache properly
Browse files Browse the repository at this point in the history
Attribute `self.wheel_cache` has been removed in f6de247,
thus `self.wheel_cache.cleanup()` will allways throw the AttributeError
and `wheel_cache.cleanup()` will never be called as supposed to be.

WheelCache.cleanup() has been introduced in `pip==10.0.0`.
It's better to check pip version explicitly (LBYL) rather than ask for
forgiveness (EAFP).
  • Loading branch information
atugushev committed Nov 16, 2019
1 parent 5efb2de commit 40d74a6
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 40d74a6

Please sign in to comment.