Skip to content

Commit

Permalink
Merge pull request #8124 from NoahGorny/abort-cache-when-no-cache-dir
Browse files Browse the repository at this point in the history
  • Loading branch information
pradyunsg authored Apr 24, 2020
2 parents daff811 + 8c28b81 commit 6a7bf94
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions news/8124.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Abort pip cache commands early when cache is disabled.
5 changes: 5 additions & 0 deletions src/pip/_internal/commands/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,11 @@ def run(self, options, args):
"purge": self.purge_cache,
}

if not options.cache_dir:
logger.error("pip cache commands can not "
"function since cache is disabled.")
return ERROR

# Determine action
if not args or args[0] not in handlers:
logger.error("Need an action ({}) to perform.".format(
Expand Down
12 changes: 12 additions & 0 deletions tests/functional/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,15 @@ def test_cache_purge_too_many_args(script, wheel_cache_files):
# Make sure nothing was deleted.
for filename in wheel_cache_files:
assert os.path.exists(filename)


@pytest.mark.parametrize("command", ["info", "list", "remove", "purge"])
def test_cache_abort_when_no_cache_dir(script, command):
"""Running any pip cache command when cache is disabled should
abort and log an informative error"""
result = script.pip('cache', command, '--no-cache-dir',
expect_error=True)
assert result.stdout == ''

assert ('ERROR: pip cache commands can not function'
' since cache is disabled.' in result.stderr.splitlines())

0 comments on commit 6a7bf94

Please sign in to comment.