From cf2c7d55193f415ed513b28ab2fdd085070a0cf8 Mon Sep 17 00:00:00 2001 From: charwick <1117120+charwick@users.noreply.github.com> Date: Sun, 8 Dec 2024 19:14:19 -0500 Subject: [PATCH 1/8] Cache purge returns file size rather than file count --- src/pip/_internal/commands/cache.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pip/_internal/commands/cache.py b/src/pip/_internal/commands/cache.py index 328336152cc..c01025289b3 100644 --- a/src/pip/_internal/commands/cache.py +++ b/src/pip/_internal/commands/cache.py @@ -180,10 +180,12 @@ def remove_cache_items(self, options: Values, args: List[Any]) -> None: if not files: logger.warning(no_matching_msg) + size = 0 for filename in files: + size += os.stat(filename).st_size os.unlink(filename) logger.verbose("Removed %s", filename) - logger.info("Files removed: %s", len(files)) + logger.info("%s bytes of files removed", f"{size:,}") def purge_cache(self, options: Values, args: List[Any]) -> None: if args: From 72069f890d2cb04139e6693342a8f71c76e3631b Mon Sep 17 00:00:00 2001 From: charwick <1117120+charwick@users.noreply.github.com> Date: Sun, 8 Dec 2024 19:19:00 -0500 Subject: [PATCH 2/8] News item for cache size fix --- news/12176.feature.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/12176.feature.rst diff --git a/news/12176.feature.rst b/news/12176.feature.rst new file mode 100644 index 00000000000..a80aa156edb --- /dev/null +++ b/news/12176.feature.rst @@ -0,0 +1 @@ +Pip now returns the size, rather than the number, of files cleared on `cache purge` From df888a8282596d5cbcd556ff0f0dbcb6608fe6fc Mon Sep 17 00:00:00 2001 From: charwick <1117120+charwick@users.noreply.github.com> Date: Sun, 8 Dec 2024 19:30:44 -0500 Subject: [PATCH 3/8] Fix rst formatting to pass checks --- news/12176.feature.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/12176.feature.rst b/news/12176.feature.rst index a80aa156edb..cbfe37e56d9 100644 --- a/news/12176.feature.rst +++ b/news/12176.feature.rst @@ -1 +1 @@ -Pip now returns the size, rather than the number, of files cleared on `cache purge` +Pip now returns the size, rather than the number, of files cleared on ``pip cache purge`` From eb6b00cae29c4e3169c4a65731b9dea322aa3e09 Mon Sep 17 00:00:00 2001 From: charwick <1117120+charwick@users.noreply.github.com> Date: Sun, 8 Dec 2024 19:43:44 -0500 Subject: [PATCH 4/8] Update cache tests with new wording --- tests/functional/test_cache.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional/test_cache.py b/tests/functional/test_cache.py index 5b7e585260d..201a4f133f6 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 == "0 bytes of files removed\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 == "0 bytes of files removed\n" def test_cache_list_too_many_args(script: PipTestEnvironment) -> None: From 2e2d5f23c96f320ea2bd0da08234b5759b15ae70 Mon Sep 17 00:00:00 2001 From: charwick <1117120+charwick@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:51:36 -0500 Subject: [PATCH 5/8] =?UTF-8?q?=C2=BFPorque=20no=20los=20dos=3F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Restore file count to cache purge message --- src/pip/_internal/commands/cache.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/pip/_internal/commands/cache.py b/src/pip/_internal/commands/cache.py index c01025289b3..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,12 +181,12 @@ def remove_cache_items(self, options: Values, args: List[Any]) -> None: if not files: logger.warning(no_matching_msg) - size = 0 + bytes_removed = 0 for filename in files: - size += os.stat(filename).st_size + bytes_removed += os.stat(filename).st_size os.unlink(filename) logger.verbose("Removed %s", filename) - logger.info("%s bytes of files removed", f"{size:,}") + logger.info("Files removed: %s (%s)", len(files), format_size(bytes_removed)) def purge_cache(self, options: Values, args: List[Any]) -> None: if args: From fe92216d73d5c9c9d7d18d0aa27c763ca4be574a Mon Sep 17 00:00:00 2001 From: charwick <1117120+charwick@users.noreply.github.com> Date: Tue, 10 Dec 2024 16:52:49 -0500 Subject: [PATCH 6/8] Update tests with count (size) wording --- tests/functional/test_cache.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/functional/test_cache.py b/tests/functional/test_cache.py index 201a4f133f6..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 == "0 bytes of files removed\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 == "0 bytes of files removed\n" + assert result.stdout == "Files removed: 0 (0 bytes)\n" def test_cache_list_too_many_args(script: PipTestEnvironment) -> None: From a1b22b26290eaa38ebeda275b2d092a656704789 Mon Sep 17 00:00:00 2001 From: charwick <1117120+charwick@users.noreply.github.com> Date: Wed, 11 Dec 2024 18:14:00 -0500 Subject: [PATCH 7/8] Update news item --- news/12176.feature.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/12176.feature.rst b/news/12176.feature.rst index cbfe37e56d9..a4e74a15db2 100644 --- a/news/12176.feature.rst +++ b/news/12176.feature.rst @@ -1 +1 @@ -Pip now returns the size, rather than the number, of files cleared on ``pip cache purge`` +Pip now returns the size, along with the number, of files cleared on ``pip cache purge`` From 832cb5a52d26e579b74ebcedbaafc97cd206c3bc Mon Sep 17 00:00:00 2001 From: charwick <1117120+charwick@users.noreply.github.com> Date: Wed, 11 Dec 2024 18:16:16 -0500 Subject: [PATCH 8/8] One last news item wording change --- news/12176.feature.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/news/12176.feature.rst b/news/12176.feature.rst index a4e74a15db2..5ff3b31f891 100644 --- a/news/12176.feature.rst +++ b/news/12176.feature.rst @@ -1 +1 @@ -Pip now returns the size, along with the number, of files cleared on ``pip cache purge`` +Pip now returns the size, along with the number, of files cleared on ``pip cache purge`` and ``pip cache remove``