From 92aed36e36f92f330abba33344cf98d8b3602840 Mon Sep 17 00:00:00 2001 From: Raphael Michel Date: Fri, 29 Nov 2024 09:16:11 +0100 Subject: [PATCH] - --keep and --queue together raise an InvalidArgumentError - added a test to check if the error is raised - fixed CLI message --- dvc/commands/experiments/__init__.py | 3 +-- dvc/repo/experiments/remove.py | 6 +++++- tests/func/experiments/test_remove.py | 7 +++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/dvc/commands/experiments/__init__.py b/dvc/commands/experiments/__init__.py index fc949e9e49..c604d8afe7 100644 --- a/dvc/commands/experiments/__init__.py +++ b/dvc/commands/experiments/__init__.py @@ -63,8 +63,7 @@ def add_keep_selection_flag(experiments_subcmd_parser): "--keep", action="store_true", default=False, - help="Keep the selected (committed, not queued) experiments " - "instead of removing them.", + help="Keep the selected experiments instead of removing them." ) diff --git a/dvc/repo/experiments/remove.py b/dvc/repo/experiments/remove.py index ecd7301ea9..bacbe69424 100644 --- a/dvc/repo/experiments/remove.py +++ b/dvc/repo/experiments/remove.py @@ -6,7 +6,7 @@ from dvc.repo.scm_context import scm_context from dvc.scm import Git, iter_revs -from .exceptions import UnresolvedExpNamesError +from .exceptions import UnresolvedExpNamesError, InvalidArgumentError from .utils import exp_refs, exp_refs_by_baseline, push_refspec if TYPE_CHECKING: @@ -34,8 +34,12 @@ def remove( # noqa: C901, PLR0912 ) -> list[str]: removed: list[str] = [] + if all([keep, queue]): + raise InvalidArgumentError("Cannot use both `--keep` and `--queue`.") + if not any([exp_names, queue, all_commits, rev]): return removed + celery_queue: LocalCeleryQueue = repo.experiments.celery_queue if queue: diff --git a/tests/func/experiments/test_remove.py b/tests/func/experiments/test_remove.py index 683980a2d0..e39dbf1572 100644 --- a/tests/func/experiments/test_remove.py +++ b/tests/func/experiments/test_remove.py @@ -255,3 +255,10 @@ def test_keep_selected_by_rev( for exp, ref in refs.items(): if exp not in expected_removed: assert scm.get_ref(str(ref)) is not None + +def test_remove_with_queue_and_keep(tmp_dir, scm, dvc, exp_stage): + # This should raise an exception, until decided otherwise + + with pytest.raises(InvalidArgumentError): + dvc.experiments.remove(queue=True, keep=True) +