Skip to content

Commit

Permalink
- --keep and --queue together raise an InvalidArgumentError
Browse files Browse the repository at this point in the history
    - added a test to check if the error is raised
    - fixed CLI message
  • Loading branch information
rmic committed Nov 29, 2024
1 parent 286b465 commit 92aed36
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
3 changes: 1 addition & 2 deletions dvc/commands/experiments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."
)


Expand Down
6 changes: 5 additions & 1 deletion dvc/repo/experiments/remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
7 changes: 7 additions & 0 deletions tests/func/experiments/test_remove.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 92aed36

Please sign in to comment.