From 30030ef11ef7f4f65511abafeaddb4d269cef947 Mon Sep 17 00:00:00 2001 From: Kenneth Reitz Date: Thu, 28 Sep 2017 13:35:59 -0400 Subject: [PATCH] upgrades to update Signed-off-by: Kenneth Reitz --- pipenv/cli.py | 60 ++++++++++++++++++++++++++++++++++++++++------- pipenv/project.py | 7 ++++++ 2 files changed, 58 insertions(+), 9 deletions(-) diff --git a/pipenv/cli.py b/pipenv/cli.py index 6b28ae5371..3e04bbee8d 100644 --- a/pipenv/cli.py +++ b/pipenv/cli.py @@ -2314,6 +2314,7 @@ def run_open(module, three=None, python=None): @click.command(help="Uninstalls all packages, and re-installs package(s) in [packages] to latest compatible versions.") +@click.argument('package_name', default=False) @click.option('--verbose', '-v', is_flag=True, default=False, help="Verbose mode.") @click.option('--dev', '-d', is_flag=True, default=False, help="Additionally install package(s) in [dev-packages].") @click.option('--three/--two', is_flag=True, default=None, help="Use Python 3/2 when creating virtualenv.") @@ -2321,7 +2322,8 @@ def run_open(module, three=None, python=None): @click.option('--dry-run', is_flag=True, default=False, help="Just output outdated packages.") @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): +@click.pass_context +def update(ctx, dev=False, three=None, python=None, dry_run=False, bare=False, dont_upgrade=False, user=False, verbose=False, clear=False, unused=False, package_name=None): # Ensure that virtualenv is available. ensure_project(three=three, python=python, validate=False) @@ -2379,16 +2381,56 @@ def update(dev=False, three=None, python=None, dry_run=False, bare=False, dont_u sys.exit(int(updates)) - click.echo( - crayons.normal(u'Updating all dependencies from Pipfile…', bold=True) - ) + if not package_name: + click.echo( + crayons.normal(u'Updating all dependencies from Pipfile…', bold=True) + ) - do_purge() - do_init(dev=dev, verbose=verbose) + pre = project.settings.get('allow_prereleases') + + # Purge. + do_purge() + + # Lock. + do_lock(pre=pre) + + # Install everything. + do_init(dev=dev, verbose=verbose) + + click.echo( + crayons.green('All dependencies are now up-to-date!') + ) + else: + + if package_name in project.all_packages: + + click.echo( + u'Uninstalling {0}…'.format( + crayons.green(package_name) + ) + ) + + cmd = '"{0}" uninstall {1} -y'.format(which_pip(), package_name) + c = delegator.run(cmd) + + try: + assert c.return_code == 0 + except AssertionError: + click.echo() + click.echo(crayons.blue(c.err)) + # sys.exit(1) + + p_name = convert_deps_to_pip({package_name: project.all_packages[package_name]}, r=False) + ctx.invoke(install, package_name=p_name[0]) + + else: + click.echo( + '{0} was not found in your {1}!'.format( + crayons.green(package_name), + crayons.normal('Pipfile', bold=True) + ) + ) - click.echo( - crayons.green('All dependencies are now up-to-date!') - ) # Install click commands. diff --git a/pipenv/project.py b/pipenv/project.py index 1d24551487..297a75abf2 100644 --- a/pipenv/project.py +++ b/pipenv/project.py @@ -314,6 +314,13 @@ def vcs_dev_packages(self): ps.update({k: v}) return ps + @property + def all_packages(self): + """Returns a list of all packages.""" + p = dict(self.parsed_pipfile.get('dev-packages', {})) + p.update(self.parsed_pipfile.get('packages', {})) + return p + @property def packages(self): """Returns a list of packages, for pip-tools to consume."""