Skip to content
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

Draft PR for the remove_step functionality in local workspaces #587

Closed
wants to merge 3 commits into from
Closed
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
25 changes: 25 additions & 0 deletions tango/workspace.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from datetime import datetime
from pathlib import Path
from tempfile import TemporaryDirectory
from sqlitedict import SqliteDict
import shutil
from typing import (
Any,
ContextManager,
Expand Down Expand Up @@ -419,6 +421,29 @@ def step_result(self, step_name: str) -> Any:
return self.step_cache[run.steps[step_name]]
raise KeyError(f"No step named '{step_name}' found in previous runs")


def remove_step(self, step_name: str) -> Any:
"""
Get Step name (Unique ID) from the user and remove the step information from cache
:raises KeyError: If no step with the unique name found in the cache dir
"""
# get path to dir dynamically
sqlite_path = self.dir / "stepinfo.sqlite"
with SqliteDict(sqlite_path) as d:
try:
step_location = d[step_name].result_location
# remove step info from the sqlite dict
del d[step_name]
d.commit()
# remove cache directory
try:
shutil.rmtree(step_location)
except OSError:
raise OSError('Step Cache folder not found')
return('Step deleted')
except KeyError:
raise KeyError(f"No step named '{step_name}' found")

def capture_logs_for_run(self, name: str) -> ContextManager[None]:
"""
Should return a context manager that can be used to capture the logs for a run.
Expand Down
Loading