Skip to content

Commit

Permalink
Merge pull request #3153 from pypa/bugfix/2848
Browse files Browse the repository at this point in the history
Respect --skip-lock option for uninstall
  • Loading branch information
techalchemy authored Nov 3, 2018
2 parents 4a49dfa + dbad4eb commit 5fa01a3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 9 deletions.
1 change: 1 addition & 0 deletions news/2848.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Updated ``pipenv uninstall`` to respect the ``--skip-lock`` argument.
6 changes: 3 additions & 3 deletions pipenv/cli/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -272,7 +272,7 @@ def install(
def uninstall(
ctx,
state,
lock=False,
skip_lock=False,
all_dev=False,
all=False,
**kwargs
Expand All @@ -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,
Expand Down
1 change: 1 addition & 0 deletions pipenv/cli/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
34 changes: 28 additions & 6 deletions pipenv/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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))
Expand All @@ -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
Expand Down

0 comments on commit 5fa01a3

Please sign in to comment.