Skip to content

Commit

Permalink
Add arguments for benchcab clean
Browse files Browse the repository at this point in the history
  • Loading branch information
abhaasgoyal committed Mar 4, 2024
1 parent 3dbbbc6 commit 6731ec0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 11 deletions.
16 changes: 11 additions & 5 deletions benchcab/benchcab.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,11 @@ def checkout(self, config_path: str):
rev_number_log = ""

for model in self._get_models(config):
model.repo.checkout()
try:
model.repo.checkout()
except Exception:
self.logger.error("Try using `benchcab clean realisations` first")
sys.exit(1)

Check warning on line 234 in benchcab/benchcab.py

View check run for this annotation

Codecov / codecov/patch

benchcab/benchcab.py#L230-L234

Added lines #L230 - L234 were not covered by tests
rev_number_log += f"{model.name}: {model.repo.get_revision()}\n"

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

def clean(self, config_path: str):
"""Endpoint for cleaning runs uirectory ig."""
clean_realisation_files()
clean_submission_files()
def clean(self, config_path: str, clean_option: str):
"""Endpoint for `benchcab clean`."""
if clean_option in ["all", "realisations"]:
clean_realisation_files()
if clean_option in ["all", "submissions"]:
clean_submission_files()

Check warning on line 329 in benchcab/benchcab.py

View check run for this annotation

Codecov / codecov/patch

benchcab/benchcab.py#L326-L329

Added lines #L326 - L329 were not covered by tests

def spatial_setup_work_directory(self, config_path: str):
"""Endpoint for `benchcab spatial-setup-work-dir`."""
Expand Down
11 changes: 8 additions & 3 deletions benchcab/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -225,14 +225,19 @@ def generate_parser(app: Benchcab) -> argparse.ArgumentParser:
parser_spatial_run_tasks.set_defaults(func=app.spatial_run_tasks)

# subcommand: 'benchcab clean'
parser_spatial = subparsers.add_parser(
parser_clean = subparsers.add_parser(
"clean",
parents=[args_help, args_subcommand],
help="Cleanup files created by running benchcab.",
description="""Removes src/ and runs/ directories, along with log files in the
project root directory.""",
project root directory. The user has to specify which stage of files to remove
via \{all, realisations, submissions\} subcommand""",
add_help=False,
)

parser_spatial.set_defaults(func=app.clean)
parser_clean.add_argument(
"clean_option", choices=["all", "realisations", "submissions"]
)

parser_clean.set_defaults(func=app.clean)
return main_parser
10 changes: 7 additions & 3 deletions benchcab/utils/repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,16 @@ class LocalRepo(Repo):
"""Concrete implementation of the `Repo` class using local path backend."""

def __init__(self, local_path: str, path: str) -> None:
"""Return a LocalRepo instance.
"""_summary_.
Parameters
----------
local_path : str
Path for local checkout of CABLE
path : str
Path of local CABLE branch
"""
Directory where CABLE is symlinked
"""
self.name = Path(local_path).name
self.local_path = local_path
self.path = path / self.name if path.is_dir() else path
Expand Down Expand Up @@ -89,6 +92,7 @@ def get_branch_name(self) -> str:
"""
return Path(self.path).absolute()

Check warning on line 93 in benchcab/utils/repo.py

View check run for this annotation

Codecov / codecov/patch

benchcab/utils/repo.py#L93

Added line #L93 was not covered by tests


class GitRepo(Repo):
"""A concrete implementation of the `Repo` class using a Git backend.
Expand Down

0 comments on commit 6731ec0

Please sign in to comment.