Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect --skip-lock option for uninstall #3153

Merged
merged 2 commits into from
Nov 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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