Skip to content
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
14 changes: 13 additions & 1 deletion conda_self/cli/main_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,18 @@


def configure_parser(parser: argparse.ArgumentParser) -> None:
from conda.cli.helpers import add_output_and_prompt_options

parser.description = HELP
add_output_and_prompt_options(parser)
parser.add_argument("specs", nargs="+", help="Plugins to remove/uninstall")
parser.set_defaults(func=execute)


def execute(args: argparse.Namespace) -> int:
from conda.base.context import context
from conda.reporters import confirm_yn

from ..exceptions import SpecsCanNotBeRemoved
from ..install import uninstall_specs_in_protected_env
from ..query import permanent_dependencies
Expand All @@ -30,5 +36,11 @@ def execute(args: argparse.Namespace) -> int:

print("Removing plugins:", *args.specs)

uninstall_specs_in_protected_env(args.specs, yes=False)
confirm_yn(
"Proceed with removing plugins?[y/n]:\n",
default="no",
dry_run=context.dry_run,
)

uninstall_specs_in_protected_env(args.specs, json=context.json, yes=True)
return 0
13 changes: 6 additions & 7 deletions conda_self/cli/main_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,10 @@


def configure_parser(parser: argparse.ArgumentParser) -> None:
from conda.cli.helpers import add_output_and_prompt_options

parser.description = HELP
parser.add_argument(
"-d",
"--dry-run",
action="store_true",
help="Only report available updates, do not install.",
)
add_output_and_prompt_options(parser)
parser.add_argument(
"--force-reinstall",
action="store_true",
Expand Down Expand Up @@ -76,7 +73,7 @@ def execute(args: argparse.Namespace) -> int:
)
updates[package_name] = latest.version

if args.dry_run:
if context.dry_run:
raise DryRunExit()
elif not updates:
return 0
Expand All @@ -86,4 +83,6 @@ def execute(args: argparse.Namespace) -> int:
channel=channel,
force_reinstall=args.force_reinstall,
update_dependencies=args.all,
json=context.json,
yes=context.always_yes,
)
2 changes: 2 additions & 0 deletions conda_self/install.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def install_package_list_in_protected_env(
force_reinstall: bool = False,
update_dependencies: bool = False,
json: bool = False,
yes: bool = False,
) -> int:
specs = [f"{name}={version}" for name, version in packages.items()]
process = run(
Expand All @@ -43,6 +44,7 @@ def install_package_list_in_protected_env(
),
*(("--force-reinstall",) if force_reinstall else ()),
*(("--json",) if json else ()),
*(("--yes",) if yes else ()),
"--all" if update_dependencies else "--update-specs",
"--override-channels",
f"--channel={channel}",
Expand Down
14 changes: 12 additions & 2 deletions tests/test_cli_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,9 @@ def test_help(conda_cli):
("conda", SpecsCanNotBeRemoved),
("conda-libmamba-solver", SpecsCanNotBeRemoved),
("python", SpecsCanNotBeRemoved),
("flask", None),
),
)
def test_remove_plugin(conda_cli, spec, error):
def test_remove_protected_plugin(conda_cli, spec, error):
conda_cli(
"self",
"remove",
Expand All @@ -35,6 +34,16 @@ def test_remove_plugin(conda_cli, spec, error):
)


def test_remove_unprotected_plugin_passes_validation(conda_cli):
"""Verify non-essential specs pass validation and reach the confirmation prompt."""
conda_cli(
"self",
"remove",
"--yes",
"flask",
)


def test_remove_nonessential_plugin(
monkeypatch: MonkeyPatch,
tmp_env: TmpEnvFixture,
Expand All @@ -52,6 +61,7 @@ def test_remove_nonessential_plugin(
prefix,
"self",
"remove",
"--yes",
"conda-index",
)
assert not is_installed(prefix, "conda-index")
2 changes: 1 addition & 1 deletion tests/test_cli_reset.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def test_reset_migrate(
assert is_installed(prefix, "conda-index")

# Update conda and install an unrelated package
conda_cli_subprocess(prefix, "self", "update")
conda_cli_subprocess(prefix, "self", "update", "--yes")
assert is_installed(prefix, "conda")
assert not is_installed(prefix, f"conda={conda_version}"), "conda not updated"
conda_cli(
Expand Down