diff --git a/HISTORY.txt b/HISTORY.txt index 1b08baa7..62c70842 100644 --- a/HISTORY.txt +++ b/HISTORY.txt @@ -1,5 +1,5 @@ 7.8.3: - - $ pipenv update --unused. + - $ pipenv check --unused. 7.8.2: - Fallback to toml parser for absurdly large files. 7.8.1: diff --git a/pipenv/cli.py b/pipenv/cli.py index c64a67c6..c5b83d98 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -2008,11 +2008,30 @@ def run(command, args, three=None, python=False): @click.command(help="Checks for security vulnerabilities and against PEP 508 markers provided in Pipfile.") @click.option('--three/--two', is_flag=True, default=None, help="Use Python 3/2 when creating virtualenv.") @click.option('--python', default=False, nargs=1, help="Specify which version of Python virtualenv should use.") -def check(three=None, python=False): +@click.option('--unused', nargs=1, default=False, help="Given a code path, show potentially unused dependencies.") +def check(three=None, python=False, unused=False): # Ensure that virtualenv is available. ensure_project(three=three, python=python, validate=False, warn=False) + if unused: + deps_required = [k for k in project.packages.keys()] + deps_needed = [k.lower() for k in import_from_code(unused)] + + for dep in deps_needed: + try: + deps_required.remove(dep) + except ValueError: + pass + + if deps_required: + click.echo(crayons.white('The following dependencies appear unused, and may be safe for removal:')) + for dep in deps_required: + click.echo(' - {0}'.format(crayons.green(dep))) + sys.exit(1) + else: + sys.exit(0) + click.echo( crayons.white(u'Checking PEP 508 requirements…', bold=True) ) @@ -2147,7 +2166,6 @@ def graph(bare=False, json=False): @click.option('--three/--two', is_flag=True, default=None, help="Use Python 3/2 when creating virtualenv.") @click.option('--python', default=False, nargs=1, help="Specify which version of Python virtualenv should use.") @click.option('--dry-run', is_flag=True, default=False, help="Just output outdated packages.") -@click.option('--unused', nargs=1, default=False, help="Given a code path, show potentially unused dependencies.") @click.option('--bare', is_flag=True, default=False, help="Minimal output.") @click.option('--clear', is_flag=True, default=False, help="Clear the dependency cache.") def update(dev=False, three=None, python=None, dry_run=False, bare=False, dont_upgrade=False, user=False, verbose=False, clear=False, unused=False): @@ -2155,24 +2173,6 @@ def update(dev=False, three=None, python=None, dry_run=False, bare=False, dont_u # Ensure that virtualenv is available. ensure_project(three=three, python=python, validate=False) - if unused: - deps_required = [k for k in project.packages.keys()] - deps_needed = [k.lower() for k in import_from_code(unused)] - - for dep in deps_needed: - try: - deps_required.remove(dep) - except ValueError: - pass - - if deps_required: - click.echo(crayons.white('The following dependencies appear unused, and may be safe for removal:')) - for dep in deps_required: - click.echo(' - {0}'.format(crayons.green(dep))) - sys.exit(1) - else: - sys.exit(0) - # --dry-run: if dry_run: # dont_upgrade = True