Merge pull request #8095 from hugovk/pip-cache-dir2

This commit is contained in:
Pradyun Gedam 2020-04-28 00:57:10 +05:30 committed by GitHub
commit 22bd8add95
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 1 deletions

1
news/7350.feature Normal file
View File

@ -0,0 +1 @@
Add ``pip cache dir`` to show the cache directory.

View File

@ -24,6 +24,7 @@ class CacheCommand(Command):
Subcommands:
dir: Show the cache directory.
info: Show information about the cache.
list: List filenames of packages stored in the cache.
remove: Remove one or more package from the cache.
@ -33,6 +34,7 @@ class CacheCommand(Command):
"""
usage = """
%prog dir
%prog info
%prog list [<pattern>]
%prog remove <pattern>
@ -42,6 +44,7 @@ class CacheCommand(Command):
def run(self, options, args):
# type: (Values, List[Any]) -> int
handlers = {
"dir": self.get_cache_dir,
"info": self.get_cache_info,
"list": self.list_cache_items,
"remove": self.remove_cache_items,
@ -71,6 +74,13 @@ class CacheCommand(Command):
return SUCCESS
def get_cache_dir(self, options, args):
# type: (Values, List[Any]) -> None
if args:
raise CommandError('Too many arguments')
logger.info(options.cache_dir)
def get_cache_info(self, options, args):
# type: (Values, List[Any]) -> None
if args:

View File

@ -95,6 +95,22 @@ def remove_matches_wheel(wheel_cache_dir):
return _remove_matches_wheel
def test_cache_dir(script, cache_dir):
result = script.pip('cache', 'dir')
assert os.path.normcase(cache_dir) == result.stdout.strip()
def test_cache_dir_too_many_args(script, cache_dir):
result = script.pip('cache', 'dir', 'aaa', expect_error=True)
assert result.stdout == ''
# This would be `result.stderr == ...`, but pip prints deprecation
# warnings on Python 2.7, so we check if the _line_ is in stderr.
assert 'ERROR: Too many arguments' in result.stderr.splitlines()
@pytest.mark.usefixtures("populate_wheel_cache")
def test_cache_info(script, wheel_cache_dir, wheel_cache_files):
result = script.pip('cache', 'info')
@ -209,7 +225,7 @@ def test_cache_purge_too_many_args(script, wheel_cache_files):
expect_error=True)
assert result.stdout == ''
# This would be `result.stderr == ...`, but Pip prints deprecation
# This would be `result.stderr == ...`, but pip prints deprecation
# warnings on Python 2.7, so we check if the _line_ is in stderr.
assert 'ERROR: Too many arguments' in result.stderr.splitlines()