Skip to content

Commit

Permalink
Merge pull request #7697 from chrahunt/refactor/cleanup-wheel-cache-c…
Browse files Browse the repository at this point in the history
…leanup

Cleanup WheelCache cleanup
  • Loading branch information
xavfernandez authored Feb 5, 2020
2 parents 34d97cf + 0410535 commit f97e88f
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 23 deletions.
20 changes: 5 additions & 15 deletions src/pip/_internal/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -171,10 +171,6 @@ def get(
"""
raise NotImplementedError()

def cleanup(self):
# type: () -> None
pass


class SimpleWheelCache(Cache):
"""A cache of wheels for future installs.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()
6 changes: 5 additions & 1 deletion src/pip/_internal/cli/req_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
7 changes: 2 additions & 5 deletions src/pip/_internal/commands/freeze.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
1 change: 0 additions & 1 deletion src/pip/_internal/commands/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 0 additions & 1 deletion src/pip/_internal/commands/wheel.py
Original file line number Diff line number Diff line change
Expand Up @@ -194,4 +194,3 @@ def run(self, options, args):
finally:
if not options.no_clean:
requirement_set.cleanup_files()
wheel_cache.cleanup()
1 change: 1 addition & 0 deletions src/pip/_internal/utils/temp_dir.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# globally-managed.
tempdir_kinds = enum(
BUILD_ENV="build-env",
EPHEM_WHEEL_CACHE="ephem-wheel-cache",
REQ_BUILD="req-build",
)

Expand Down

0 comments on commit f97e88f

Please sign in to comment.