Skip to content

Commit 2c04ed7

Browse files
author
Noah Gorny
committed
cache: Do not raise error when there are no files to remove
Instead log a warning and continue (to log that we removed 0 files)
1 parent 48dc9f4 commit 2c04ed7

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

news/10459.feature.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Do not raise error when there are no files to remove with ``pip cache purge/remove``.
2+
Instead log a warning and continue (to log that we removed 0 files).

src/pip/_internal/commands/cache.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,12 +170,16 @@ def remove_cache_items(self, options: Values, args: List[Any]) -> None:
170170

171171
files = self._find_wheels(options, args[0])
172172

173-
# Only fetch http files if no specific pattern given
173+
no_matching_msg = "No matching packages"
174174
if args[0] == "*":
175+
# Only fetch http files if no specific pattern given
175176
files += self._find_http_files(options)
177+
else:
178+
# Add the pattern to the log message
179+
no_matching_msg += ' for pattern "{}"'.format(args[0])
176180

177181
if not files:
178-
raise CommandError("No matching packages")
182+
logger.warning(no_matching_msg)
179183

180184
for filename in files:
181185
os.unlink(filename)

0 commit comments

Comments
 (0)