From d6dd412f40195ceffa2f521155c0c70d75d29f4e Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Tue, 3 Jul 2018 12:01:35 -0400 Subject: [PATCH] clear the caches --- pipenv/cli.py | 13 +++++++++++-- pipenv/core.py | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/pipenv/cli.py b/pipenv/cli.py index 86eb9866..e3134714 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -136,6 +136,7 @@ def validate_pypi_mirror(ctx, param, value): is_flag=True, help="Output diagnostic information for use in Github issues.", ) +@option("--clear", is_flag=True, help="Clears caches (pipenv, pip, and pip-tools).") @version_option(prog_name=crayons.normal("pipenv", bold=True), version=__version__) @pass_context def cli( @@ -154,6 +155,7 @@ def cli( completion=False, pypi_mirror=None, support=None, + clear=False, ): if completion: # Handle this ASAP to make shell startup fast. from . import shells @@ -180,6 +182,7 @@ def cli( cleanup_virtualenv, ensure_project, format_help, + do_clear, ) if man: @@ -203,19 +206,24 @@ def cli( sys.exit(0) warn_in_virtualenv() if ctx.invoked_subcommand is None: - # --where was passed... + # --where was passed… if where: do_where(bare=True) sys.exit(0) elif py: do_py() sys.exit() - # --support was passed... + # --support was passed… elif support: from .help import get_pipenv_diagnostics get_pipenv_diagnostics() sys.exit(0) + # --clear was passed… + elif clear: + do_clear() + sys.exit(0) + # --venv was passed... elif venv: # There is no virtualenv yet. @@ -270,6 +278,7 @@ def cli( warn=True, site_packages=site_packages, pypi_mirror=pypi_mirror, + clear=clear, ) # Check this again before exiting for empty ``pipenv`` command. elif ctx.invoked_subcommand is None: diff --git a/pipenv/core.py b/pipenv/core.py index 3838c7f8..6c943b91 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -122,6 +122,18 @@ def which(command, location=None, allow_global=False): project = Project(which=which) +def do_clear(): + click.echo(crayons.white("Clearing caches…", bold=True)) + import pip._internal.locations + import piptools + + try: + shutil.rmtree(PIPENV_CACHE_DIR) + shutil.rmtree(pip._internal.locations.USER_CACHE_DIR) + except FileNotFoundError: + pass + + def load_dot_env(): """Loads .env file into sys.environ.""" if not PIPENV_DONT_LOAD_ENV: @@ -582,10 +594,16 @@ def ensure_project( deploy=False, skip_requirements=False, pypi_mirror=None, + clear=False, ): """Ensures both Pipfile and virtualenv exist for the project.""" from .environments import PIPENV_USE_SYSTEM + # Clear the caches, if appropriate. + if clear: + print("clearing") + sys.exit(1) + # Automatically use an activated virtualenv. if PIPENV_USE_SYSTEM: system = True