Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Abort pip cache commands when cache is disabled #8124

Merged
merged 2 commits into from
Apr 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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())