Skip to content

Add simple confirmation before removing artifacts #269

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

Merged
merged 1 commit into from
Feb 22, 2025
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
8 changes: 7 additions & 1 deletion cascade/cli/artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class RemoveResult:

FAIL - something went wrong when removing a file
"""

status: Literal["OKAY", "MISS", "FAIL"]
path: Optional[str] = None
traceback: Optional[str] = None
Expand Down Expand Up @@ -101,11 +102,16 @@ def artifact(ctx):


@artifact.command("rm")
@click.option("-y", is_flag=True, expose_value=True, help="Confirm")
@click.pass_context
def artifact_rm(ctx):
def artifact_rm(ctx, y):
"""
Remove artifacts from the whole container recursively
"""

if not y:
click.confirm("Confirm?", abort=True)

results_list = []
flat_results = []
if ctx.obj["type"] == "model":
Expand Down
22 changes: 7 additions & 15 deletions cascade/tests/cli/test_artifact.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,12 @@ def test_rm_model(tmp_path_str):
model.save_artifact(artifact_path)
MetaHandler.write_dir(td, model.get_meta())

assert os.path.exists(
os.path.join(td, "artifacts", "artifact.txt")
)
assert os.path.exists(os.path.join(td, "artifacts", "artifact.txt"))

result = runner.invoke(cli, args=["artifact", "rm"])
result = runner.invoke(cli, args=["artifact", "rm", "-y"])
assert result.exit_code == 0

assert not os.path.exists(
os.path.join(td, "artifacts", "artifact.txt")
)
assert not os.path.exists(os.path.join(td, "artifacts", "artifact.txt"))


def test_rm_model_error(tmp_path_str):
Expand All @@ -63,18 +59,14 @@ def test_rm_model_error(tmp_path_str):
model.save_artifact(artifact_path)
MetaHandler.write_dir(td, model.get_meta())

assert os.path.exists(
os.path.join(td, "artifacts", "artifact.txt")
)
assert os.path.exists(os.path.join(td, "artifacts", "artifact.txt"))

with patch('os.remove') as mocked_remove:
with patch("os.remove") as mocked_remove:
mocked_remove.side_effect = OSError()

result = runner.invoke(cli, args=["artifact", "rm"])
result = runner.invoke(cli, args=["artifact", "rm", "-y"])
assert result.exit_code == 0

mocked_remove.assert_called_once_with(os.path.join(td, "artifacts", "artifact.txt"))

assert os.path.exists(
os.path.join(td, "artifacts", "artifact.txt")
)
assert os.path.exists(os.path.join(td, "artifacts", "artifact.txt"))