Skip to content

Commit cebac6a

Browse files
committed
Add 'pip cache dir' command to show the path to pip's cache directory
1 parent e40d267 commit cebac6a

File tree

3 files changed

+17
-0
lines changed

3 files changed

+17
-0
lines changed

news/7350.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Add ``pip cache dir`` to show the cache directory.

src/pip/_internal/commands/cache.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class CacheCommand(Command):
2424

2525
Subcommands:
2626

27+
dir: Show the cache directory.
2728
info: Show information about the cache.
2829
list: List filenames of packages stored in the cache.
2930
remove: Remove one or more package from the cache.
@@ -33,6 +34,7 @@ class CacheCommand(Command):
3334
"""
3435

3536
usage = """
37+
%prog dir
3638
%prog info
3739
%prog list [<pattern>]
3840
%prog remove <pattern>
@@ -42,6 +44,7 @@ class CacheCommand(Command):
4244
def run(self, options, args):
4345
# type: (Values, List[Any]) -> int
4446
handlers = {
47+
"dir": self.get_cache_dir,
4548
"info": self.get_cache_info,
4649
"list": self.list_cache_items,
4750
"remove": self.remove_cache_items,
@@ -66,6 +69,13 @@ def run(self, options, args):
6669

6770
return SUCCESS
6871

72+
def get_cache_dir(self, options, args):
73+
# type: (Values, List[Any]) -> None
74+
if args:
75+
raise CommandError('Too many arguments')
76+
77+
logger.info(options.cache_dir)
78+
6979
def get_cache_info(self, options, args):
7080
# type: (Values, List[Any]) -> None
7181
if args:

tests/functional/test_cache.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ def _remove_matches_wheel(wheel_name, result):
9595
return _remove_matches_wheel
9696

9797

98+
def test_cache_dir(script, cache_dir):
99+
result = script.pip('cache', 'dir')
100+
101+
assert os.path.normcase(cache_dir) == result.stdout.strip()
102+
103+
98104
@pytest.mark.usefixtures("populate_wheel_cache")
99105
def test_cache_info(script, wheel_cache_dir, wheel_cache_files):
100106
result = script.pip('cache', 'info')

0 commit comments

Comments
 (0)