diff --git a/src/pip/_internal/cache.py b/src/pip/_internal/cache.py index abecd78f8d9..d4398ba8f88 100644 --- a/src/pip/_internal/cache.py +++ b/src/pip/_internal/cache.py @@ -15,7 +15,7 @@ from pip._internal.exceptions import InvalidWheelFilename from pip._internal.models.link import Link from pip._internal.models.wheel import Wheel -from pip._internal.utils.temp_dir import TempDirectory +from pip._internal.utils.temp_dir import TempDirectory, tempdir_kinds from pip._internal.utils.typing import MYPY_CHECK_RUNNING from pip._internal.utils.urls import path_to_url @@ -171,10 +171,6 @@ def get( """ raise NotImplementedError() - def cleanup(self): - # type: () -> None - pass - class SimpleWheelCache(Cache): """A cache of wheels for future installs. @@ -264,16 +260,15 @@ class EphemWheelCache(SimpleWheelCache): def __init__(self, format_control): # type: (FormatControl) -> None - self._temp_dir = TempDirectory(kind="ephem-wheel-cache") + self._temp_dir = TempDirectory( + kind=tempdir_kinds.EPHEM_WHEEL_CACHE, + globally_managed=True, + ) super(EphemWheelCache, self).__init__( self._temp_dir.path, format_control ) - def cleanup(self): - # type: () -> None - self._temp_dir.cleanup() - class WheelCache(Cache): """Wraps EphemWheelCache and SimpleWheelCache into a single Cache @@ -322,8 +317,3 @@ def get( package_name=package_name, supported_tags=supported_tags, ) - - def cleanup(self): - # type: () -> None - self._wheel_cache.cleanup() - self._ephem_cache.cleanup() diff --git a/src/pip/_internal/cli/req_command.py b/src/pip/_internal/cli/req_command.py index 58fe49dc772..377e05a6378 100644 --- a/src/pip/_internal/cli/req_command.py +++ b/src/pip/_internal/cli/req_command.py @@ -156,7 +156,11 @@ def handle_pip_version_check(self, options): pip_self_version_check(session, options) -KEEPABLE_TEMPDIR_TYPES = [tempdir_kinds.BUILD_ENV, tempdir_kinds.REQ_BUILD] +KEEPABLE_TEMPDIR_TYPES = [ + tempdir_kinds.BUILD_ENV, + tempdir_kinds.EPHEM_WHEEL_CACHE, + tempdir_kinds.REQ_BUILD, +] def with_cleanup(func): diff --git a/src/pip/_internal/commands/freeze.py b/src/pip/_internal/commands/freeze.py index 41fea20ca5e..4758e30343f 100644 --- a/src/pip/_internal/commands/freeze.py +++ b/src/pip/_internal/commands/freeze.py @@ -96,8 +96,5 @@ def run(self, options, args): exclude_editable=options.exclude_editable, ) - try: - for line in freeze(**freeze_kwargs): - sys.stdout.write(line + '\n') - finally: - wheel_cache.cleanup() + for line in freeze(**freeze_kwargs): + sys.stdout.write(line + '\n') diff --git a/src/pip/_internal/commands/install.py b/src/pip/_internal/commands/install.py index cf629c81c0b..ce0aa9d86fa 100644 --- a/src/pip/_internal/commands/install.py +++ b/src/pip/_internal/commands/install.py @@ -447,7 +447,6 @@ def run(self, options, args): # Clean up if not options.no_clean: requirement_set.cleanup_files() - wheel_cache.cleanup() if options.target_dir: self._handle_target_dir( diff --git a/src/pip/_internal/commands/wheel.py b/src/pip/_internal/commands/wheel.py index d9308b152a4..35ba2d9c268 100644 --- a/src/pip/_internal/commands/wheel.py +++ b/src/pip/_internal/commands/wheel.py @@ -194,4 +194,3 @@ def run(self, options, args): finally: if not options.no_clean: requirement_set.cleanup_files() - wheel_cache.cleanup() diff --git a/src/pip/_internal/utils/temp_dir.py b/src/pip/_internal/utils/temp_dir.py index 428173d8c96..201ba6d9811 100644 --- a/src/pip/_internal/utils/temp_dir.py +++ b/src/pip/_internal/utils/temp_dir.py @@ -25,6 +25,7 @@ # globally-managed. tempdir_kinds = enum( BUILD_ENV="build-env", + EPHEM_WHEEL_CACHE="ephem-wheel-cache", REQ_BUILD="req-build", )