diff --git a/news/12176.feature.rst b/news/12176.feature.rst new file mode 100644 index 00000000000..5ff3b31f891 --- /dev/null +++ b/news/12176.feature.rst @@ -0,0 +1 @@ +Pip now returns the size, along with the number, of files cleared on ``pip cache purge`` and ``pip cache remove`` diff --git a/src/pip/_internal/commands/cache.py b/src/pip/_internal/commands/cache.py index 328336152cc..ad65641edb2 100644 --- a/src/pip/_internal/commands/cache.py +++ b/src/pip/_internal/commands/cache.py @@ -8,6 +8,7 @@ from pip._internal.exceptions import CommandError, PipError from pip._internal.utils import filesystem from pip._internal.utils.logging import getLogger +from pip._internal.utils.misc import format_size logger = getLogger(__name__) @@ -180,10 +181,12 @@ def remove_cache_items(self, options: Values, args: List[Any]) -> None: if not files: logger.warning(no_matching_msg) + bytes_removed = 0 for filename in files: + bytes_removed += os.stat(filename).st_size os.unlink(filename) logger.verbose("Removed %s", filename) - logger.info("Files removed: %s", len(files)) + logger.info("Files removed: %s (%s)", len(files), format_size(bytes_removed)) def purge_cache(self, options: Values, args: List[Any]) -> None: if args: diff --git a/tests/functional/test_cache.py b/tests/functional/test_cache.py index 5b7e585260d..247bfcd4be0 100644 --- a/tests/functional/test_cache.py +++ b/tests/functional/test_cache.py @@ -256,7 +256,7 @@ def test_cache_purge_with_empty_cache(script: PipTestEnvironment) -> None: and exit without an error code.""" result = script.pip("cache", "purge", allow_stderr_warning=True) assert result.stderr == "WARNING: No matching packages\n" - assert result.stdout == "Files removed: 0\n" + assert result.stdout == "Files removed: 0 (0 bytes)\n" @pytest.mark.usefixtures("populate_wheel_cache") @@ -265,7 +265,7 @@ def test_cache_remove_with_bad_pattern(script: PipTestEnvironment) -> None: and exit without an error code.""" result = script.pip("cache", "remove", "aaa", allow_stderr_warning=True) assert result.stderr == 'WARNING: No matching packages for pattern "aaa"\n' - assert result.stdout == "Files removed: 0\n" + assert result.stdout == "Files removed: 0 (0 bytes)\n" def test_cache_list_too_many_args(script: PipTestEnvironment) -> None: