diff --git a/news/7350.feature b/news/7350.feature new file mode 100644 index 000000000..1b57d7b19 --- /dev/null +++ b/news/7350.feature @@ -0,0 +1 @@ +Add ``pip cache dir`` to show the cache directory. diff --git a/src/pip/_internal/commands/cache.py b/src/pip/_internal/commands/cache.py index 7e3f72e08..0625adb0f 100644 --- a/src/pip/_internal/commands/cache.py +++ b/src/pip/_internal/commands/cache.py @@ -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 [] %prog remove @@ -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, @@ -66,6 +69,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: diff --git a/tests/functional/test_cache.py b/tests/functional/test_cache.py index a464ece79..623378760 100644 --- a/tests/functional/test_cache.py +++ b/tests/functional/test_cache.py @@ -95,6 +95,12 @@ 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() + + @pytest.mark.usefixtures("populate_wheel_cache") def test_cache_info(script, wheel_cache_dir, wheel_cache_files): result = script.pip('cache', 'info')