Skip to content

Commit c6f43e2

Browse files
authored
Add --yes support to self remove and self update subcommands (#108)
1 parent 6fa3acf commit c6f43e2

File tree

5 files changed

+34
-11
lines changed

5 files changed

+34
-11
lines changed

conda_self/cli/main_remove.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,18 @@
99

1010

1111
def configure_parser(parser: argparse.ArgumentParser) -> None:
12+
from conda.cli.helpers import add_output_and_prompt_options
13+
1214
parser.description = HELP
15+
add_output_and_prompt_options(parser)
1316
parser.add_argument("specs", nargs="+", help="Plugins to remove/uninstall")
1417
parser.set_defaults(func=execute)
1518

1619

1720
def execute(args: argparse.Namespace) -> int:
21+
from conda.base.context import context
22+
from conda.reporters import confirm_yn
23+
1824
from ..exceptions import SpecsCanNotBeRemoved
1925
from ..install import uninstall_specs_in_protected_env
2026
from ..query import permanent_dependencies
@@ -30,5 +36,11 @@ def execute(args: argparse.Namespace) -> int:
3036

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

33-
uninstall_specs_in_protected_env(args.specs, yes=False)
39+
confirm_yn(
40+
"Proceed with removing plugins?[y/n]:\n",
41+
default="no",
42+
dry_run=context.dry_run,
43+
)
44+
45+
uninstall_specs_in_protected_env(args.specs, json=context.json, yes=True)
3446
return 0

conda_self/cli/main_update.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,10 @@
99

1010

1111
def configure_parser(parser: argparse.ArgumentParser) -> None:
12+
from conda.cli.helpers import add_output_and_prompt_options
13+
1214
parser.description = HELP
13-
parser.add_argument(
14-
"-d",
15-
"--dry-run",
16-
action="store_true",
17-
help="Only report available updates, do not install.",
18-
)
15+
add_output_and_prompt_options(parser)
1916
parser.add_argument(
2017
"--force-reinstall",
2118
action="store_true",
@@ -76,7 +73,7 @@ def execute(args: argparse.Namespace) -> int:
7673
)
7774
updates[package_name] = latest.version
7875

79-
if args.dry_run:
76+
if context.dry_run:
8077
raise DryRunExit()
8178
elif not updates:
8279
return 0
@@ -86,4 +83,6 @@ def execute(args: argparse.Namespace) -> int:
8683
channel=channel,
8784
force_reinstall=args.force_reinstall,
8885
update_dependencies=args.all,
86+
json=context.json,
87+
yes=context.always_yes,
8988
)

conda_self/install.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ def install_package_list_in_protected_env(
2727
force_reinstall: bool = False,
2828
update_dependencies: bool = False,
2929
json: bool = False,
30+
yes: bool = False,
3031
) -> int:
3132
specs = [f"{name}={version}" for name, version in packages.items()]
3233
process = run(
@@ -43,6 +44,7 @@ def install_package_list_in_protected_env(
4344
),
4445
*(("--force-reinstall",) if force_reinstall else ()),
4546
*(("--json",) if json else ()),
47+
*(("--yes",) if yes else ()),
4648
"--all" if update_dependencies else "--update-specs",
4749
"--override-channels",
4850
f"--channel={channel}",

tests/test_cli_remove.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ def test_help(conda_cli):
2323
("conda", SpecsCanNotBeRemoved),
2424
("conda-libmamba-solver", SpecsCanNotBeRemoved),
2525
("python", SpecsCanNotBeRemoved),
26-
("flask", None),
2726
),
2827
)
29-
def test_remove_plugin(conda_cli, spec, error):
28+
def test_remove_protected_plugin(conda_cli, spec, error):
3029
conda_cli(
3130
"self",
3231
"remove",
@@ -35,6 +34,16 @@ def test_remove_plugin(conda_cli, spec, error):
3534
)
3635

3736

37+
def test_remove_unprotected_plugin_passes_validation(conda_cli):
38+
"""Verify non-essential specs pass validation and reach the confirmation prompt."""
39+
conda_cli(
40+
"self",
41+
"remove",
42+
"--yes",
43+
"flask",
44+
)
45+
46+
3847
def test_remove_nonessential_plugin(
3948
monkeypatch: MonkeyPatch,
4049
tmp_env: TmpEnvFixture,
@@ -52,6 +61,7 @@ def test_remove_nonessential_plugin(
5261
prefix,
5362
"self",
5463
"remove",
64+
"--yes",
5565
"conda-index",
5666
)
5767
assert not is_installed(prefix, "conda-index")

tests/test_cli_reset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def test_reset_migrate(
8585
assert is_installed(prefix, "conda-index")
8686

8787
# Update conda and install an unrelated package
88-
conda_cli_subprocess(prefix, "self", "update")
88+
conda_cli_subprocess(prefix, "self", "update", "--yes")
8989
assert is_installed(prefix, "conda")
9090
assert not is_installed(prefix, f"conda={conda_version}"), "conda not updated"
9191
conda_cli(

0 commit comments

Comments
 (0)