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

Add 'pip cache dir' command to show cache directory #8095

Merged
merged 2 commits into from
Apr 27, 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/7350.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add ``pip cache dir`` to show the cache directory.
10 changes: 10 additions & 0 deletions src/pip/_internal/commands/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -33,6 +34,7 @@ class CacheCommand(Command):
"""

usage = """
%prog dir
%prog info
%prog list [<pattern>]
%prog remove <pattern>
Expand All @@ -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,
Expand All @@ -66,6 +69,13 @@ def run(self, options, args):

return SUCCESS

def get_cache_dir(self, options, args):
# type: (Values, List[Any]) -> None
if args:
raise CommandError('Too many arguments')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test hitting this branch would be great! :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 Test added in 6b640d1


logger.info(options.cache_dir)

def get_cache_info(self, options, args):
# type: (Values, List[Any]) -> None
if args:
Expand Down
18 changes: 17 additions & 1 deletion tests/functional/test_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ def _remove_matches_wheel(wheel_name, result):
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')
Expand Down Expand Up @@ -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()

Expand Down