Skip to content

Commit 436245b

Browse files
committed
Add arguments for benchcab clean
1 parent 3dbbbc6 commit 436245b

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

Diff for: benchcab/benchcab.py

+10-4
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,11 @@ def checkout(self, config_path: str):
227227
rev_number_log = ""
228228

229229
for model in self._get_models(config):
230-
model.repo.checkout()
230+
try:
231+
model.repo.checkout()
232+
except Exception:
233+
self.logger.error("Try using `benchcab clean realisations` first")
234+
sys.exit(1)
231235
rev_number_log += f"{model.name}: {model.repo.get_revision()}\n"
232236

233237
rev_number_log_path = next_path("rev_number-*.log")
@@ -317,10 +321,12 @@ def fluxsite(self, config_path: str, no_submit: bool, skip: list[str]):
317321
else:
318322
self.fluxsite_submit_job(config_path, skip)
319323

320-
def clean(self, config_path: str):
324+
def clean(self, config_path: str, clean_option: str):
321325
"""Endpoint for cleaning runs uirectory ig."""
322-
clean_realisation_files()
323-
clean_submission_files()
326+
if clean_option in ["all", "realisations"]:
327+
clean_realisation_files()
328+
if clean_option in ["all", "submissions"]:
329+
clean_submission_files()
324330

325331
def spatial_setup_work_directory(self, config_path: str):
326332
"""Endpoint for `benchcab spatial-setup-work-dir`."""

Diff for: benchcab/cli.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def generate_parser(app: Benchcab) -> argparse.ArgumentParser:
225225
parser_spatial_run_tasks.set_defaults(func=app.spatial_run_tasks)
226226

227227
# subcommand: 'benchcab clean'
228-
parser_spatial = subparsers.add_parser(
228+
parser_clean = subparsers.add_parser(
229229
"clean",
230230
parents=[args_help, args_subcommand],
231231
help="Cleanup files created by running benchcab.",
@@ -234,5 +234,9 @@ def generate_parser(app: Benchcab) -> argparse.ArgumentParser:
234234
add_help=False,
235235
)
236236

237-
parser_spatial.set_defaults(func=app.clean)
237+
parser_clean.add_argument(
238+
"clean_option", choices=["all", "realisations", "submissions"]
239+
)
240+
241+
parser_clean.set_defaults(func=app.clean)
238242
return main_parser

Diff for: benchcab/utils/repo.py

+7-3
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,16 @@ class LocalRepo(Repo):
5050
"""Concrete implementation of the `Repo` class using local path backend."""
5151

5252
def __init__(self, local_path: str, path: str) -> None:
53-
"""Return a LocalRepo instance.
53+
"""_summary_.
5454
5555
Parameters
5656
----------
57+
local_path : str
58+
Path for local checkout of CABLE
5759
path : str
58-
Path of local CABLE branch
59-
"""
60+
Directory where CABLE is symlinked
61+
62+
"""
6063
self.name = Path(local_path).name
6164
self.local_path = local_path
6265
self.path = path / self.name if path.is_dir() else path
@@ -89,6 +92,7 @@ def get_branch_name(self) -> str:
8992
"""
9093
return Path(self.path).absolute()
9194

95+
9296
class GitRepo(Repo):
9397
"""A concrete implementation of the `Repo` class using a Git backend.
9498

0 commit comments

Comments
 (0)