Skip to content

Commit 6731ec0

Browse files
committed
Add arguments for benchcab clean
1 parent 3dbbbc6 commit 6731ec0

File tree

3 files changed

+26
-11
lines changed

3 files changed

+26
-11
lines changed

benchcab/benchcab.py

+11-5
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):
321-
"""Endpoint for cleaning runs uirectory ig."""
322-
clean_realisation_files()
323-
clean_submission_files()
324+
def clean(self, config_path: str, clean_option: str):
325+
"""Endpoint for `benchcab clean`."""
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`."""

benchcab/cli.py

+8-3
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,19 @@ 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.",
232232
description="""Removes src/ and runs/ directories, along with log files in the
233-
project root directory.""",
233+
project root directory. The user has to specify which stage of files to remove
234+
via \{all, realisations, submissions\} subcommand""",
234235
add_help=False,
235236
)
236237

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

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)