diff --git a/news/2848.bugfix.rst b/news/2848.bugfix.rst new file mode 100644 index 0000000000..f88c030dc3 --- /dev/null +++ b/news/2848.bugfix.rst @@ -0,0 +1 @@ +Updated ``pipenv uninstall`` to respect the ``--skip-lock`` argument. diff --git a/pipenv/cli/command.py b/pipenv/cli/command.py index 40d3f0fe4e..74f66d7ebe 100644 --- a/pipenv/cli/command.py +++ b/pipenv/cli/command.py @@ -253,7 +253,7 @@ def install( @cli.command(short_help="Un-installs a provided package and removes it from Pipfile.") -@option("--lock", is_flag=True, default=True, help="Lock afterwards.") +@option("--skip-lock/--lock", is_flag=True, default=False, help="Lock afterwards.") @option( "--all-dev", is_flag=True, @@ -272,7 +272,7 @@ def install( def uninstall( ctx, state, - lock=False, + skip_lock=False, all_dev=False, all=False, **kwargs @@ -286,7 +286,7 @@ def uninstall( three=state.three, python=state.python, system=state.system, - lock=lock, + lock=not skip_lock, all_dev=all_dev, all=all, keep_outdated=state.installstate.keep_outdated, diff --git a/pipenv/cli/options.py b/pipenv/cli/options.py index 99fc5344bf..dcdc1d9f45 100644 --- a/pipenv/cli/options.py +++ b/pipenv/cli/options.py @@ -353,6 +353,7 @@ def uninstall_options(f): def lock_options(f): f = install_base_options(f) f = requirements_flag(f) + f = skip_lock_option(f) f = pre_option(f) return f diff --git a/pipenv/core.py b/pipenv/core.py index b97b1a73ee..bf4145e532 100644 --- a/pipenv/core.py +++ b/pipenv/core.py @@ -920,7 +920,7 @@ def do_create_virtualenv(python=None, site_packages=False, pypi_mirror=None): pip_config = {} # Actually create the virtualenv. - nospin = os.environ.get("PIPENV_ACTIVE", environments.PIPENV_NOSPIN) + nospin = environments.PIPENV_NOSPIN c = vistir.misc.run(cmd, verbose=False, return_object=True, spinner_name=environments.PIPENV_SPINNER, combine_stderr=False, block=False, nospin=nospin, env=pip_config) @@ -935,7 +935,7 @@ def do_create_virtualenv(python=None, site_packages=False, pypi_mirror=None): project_file_name = os.path.join(project.virtualenv_location, ".project") with open(project_file_name, "w") as f: f.write(vistir.misc.fs_str(project.project_directory)) - + fix_venv_site(project.env_paths["lib"]) # Say where the virtualenv is. do_where(virtualenv=True, bare=False) @@ -2040,6 +2040,7 @@ def do_uninstall( ): from .environments import PIPENV_USE_SYSTEM from .vendor.requirementslib.models.requirements import Requirement + from .vendor.requirementslib.models.lockfile import Lockfile from .vendor.packaging.utils import canonicalize_name # Automatically use an activated virtualenv. @@ -2118,9 +2119,17 @@ def do_uninstall( ) do_purge(allow_global=system) removed = package_names - bad_pkgs - project.remove_packages_from_pipfile(removed) - if lock: - do_lock(system=system, keep_outdated=keep_outdated, pypi_mirror=pypi_mirror) + if pipfile_remove: + project.remove_packages_from_pipfile(removed) + if lock: + do_lock(system=system, keep_outdated=keep_outdated, pypi_mirror=pypi_mirror) + else: + lockfile = project.get_or_create_lockfile() + for key in lockfile.default.keys(): + del lockfile.default[key] + for key in lockfile.develop.keys(): + del lockfile.develop[key] + lockfile.write() return if all_dev: package_names = develop @@ -2142,7 +2151,7 @@ def do_uninstall( # Uninstall the package. if package_name in packages_to_remove: cmd = "{0} uninstall {1} -y".format( - escape_grouped_arguments(which_pip()), package_name + escape_grouped_arguments(which_pip(allow_global=system)), package_name ) if environments.is_verbose(): click.echo("$ {0}".format(cmd)) @@ -2155,6 +2164,19 @@ def do_uninstall( in_dev_packages = project.get_package_name_in_pipfile( package_name, dev=True ) + if normalized in lockfile_packages: + click.echo("{0} {1} {2} {3}".format( + crayons.blue("Removing"), + crayons.green(package_name), + crayons.blue("from"), + crayons.white(fix_utf8("Pipfile.lockā€¦"))) + ) + lockfile = project.get_or_create_lockfile() + if normalized in lockfile.default: + del lockfile.default[normalized] + if normalized in lockfile.develop: + del lockfile.develop[normalized] + lockfile.write() if not (in_dev_packages or in_packages): if normalized in lockfile_packages: continue