Skip to content

Commit 6a7bf94

Browse files
authored
Merge pull request #8124 from NoahGorny/abort-cache-when-no-cache-dir
2 parents daff811 + 8c28b81 commit 6a7bf94

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

news/8124.bugfix

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Abort pip cache commands early when cache is disabled.

src/pip/_internal/commands/cache.py

+5
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ def run(self, options, args):
4848
"purge": self.purge_cache,
4949
}
5050

51+
if not options.cache_dir:
52+
logger.error("pip cache commands can not "
53+
"function since cache is disabled.")
54+
return ERROR
55+
5156
# Determine action
5257
if not args or args[0] not in handlers:
5358
logger.error("Need an action ({}) to perform.".format(

tests/functional/test_cache.py

+12
Original file line numberDiff line numberDiff line change
@@ -216,3 +216,15 @@ def test_cache_purge_too_many_args(script, wheel_cache_files):
216216
# Make sure nothing was deleted.
217217
for filename in wheel_cache_files:
218218
assert os.path.exists(filename)
219+
220+
221+
@pytest.mark.parametrize("command", ["info", "list", "remove", "purge"])
222+
def test_cache_abort_when_no_cache_dir(script, command):
223+
"""Running any pip cache command when cache is disabled should
224+
abort and log an informative error"""
225+
result = script.pip('cache', command, '--no-cache-dir',
226+
expect_error=True)
227+
assert result.stdout == ''
228+
229+
assert ('ERROR: pip cache commands can not function'
230+
' since cache is disabled.' in result.stderr.splitlines())

0 commit comments

Comments
 (0)