Skip to content

Commit

Permalink
clean up print for DatabaseStudy and add -k option to delete all-studies
Browse files Browse the repository at this point in the history
  • Loading branch information
bgunnar5 committed Feb 21, 2025
1 parent 0aa3ea6 commit 4fa3e13
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
2 changes: 1 addition & 1 deletion merlin/db_scripts/db_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ def database_delete(args: Namespace):
if args.delete_type == "study":
merlin_db.delete_study(args.study, remove_associated_runs=(not args.keep_associated_runs))
elif args.delete_type == "all-studies":
merlin_db.delete_all_studies()
merlin_db.delete_all_studies(remove_associated_runs=(not args.keep_associated_runs))
elif args.delete_type == "run":
merlin_db.delete_run(args.run)
elif args.delete_type == "all-runs":
Expand Down
8 changes: 7 additions & 1 deletion merlin/db_scripts/db_study.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,17 @@ def __str__(self) -> str:
A human-readable string representation of the `DatabaseStudy` instance.
"""
study_id = self.get_id()
runs_str = "Runs:\n"
for run in self.get_all_runs():
runs_str += (
f" - ID: {run.get_id()}\n"
f" Workspace: {run.get_workspace()}\n"
)
return (
f"Study with ID {study_id}\n"
f"------------{'-' * len(study_id)}\n"
f"Name: {self.get_name()}\n"
f"Runs: {self.get_all_runs()}\n"
f"{runs_str}"
f"Additional Data: {self.get_additional_data()}\n\n"
)

Expand Down
27 changes: 19 additions & 8 deletions merlin/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -879,11 +879,12 @@ def setup_argparse() -> None: # pylint: disable=R0915
# Add subcommands for delete
delete_subcommands = db_delete.add_subparsers(dest="delete_type", required=True)

# TODO enable support for deletion of study by name, ID, or passing in spec file
# Subcommand: delete study
delete_study = (
delete_subcommands.add_parser( # TODO perhaps this should just take in a spec file instead of the study name?
delete_subcommands.add_parser(
"study",
help="Delete a specific study by name.", # TODO add option to delete by ID here as well
help="Delete a specific study by name.",
formatter_class=ArgumentDefaultsHelpFormatter,
)
)
Expand All @@ -899,30 +900,37 @@ def setup_argparse() -> None: # pylint: disable=R0915
help="Keep runs associated with the study.",
)

# TODO enable support for deletion of run by workspace or ID
# Subcommand: delete run
delete_run = delete_subcommands.add_parser(
"run",
help="Delete a specific run by ID.", # TODO add option to delete by workspace here as well
help="Delete a specific run by ID.",
formatter_class=ArgumentDefaultsHelpFormatter,
)
delete_run.add_argument(
"run",
type=str,
help="The ID of the run to delete.",
)
# TODO implement the below option
# TODO implement the below option; this removes the output workspace from file system
# delete_run.add_argument(
# "--delete-workspace",
# action="store_true",
# help="Delete the output workspace for the run.",
# )

# Subcommand: delete all-studies
delete_subcommands.add_parser(
delete_all_studies = delete_subcommands.add_parser(
"all-studies",
help="Delete all studies from the database.",
formatter_class=ArgumentDefaultsHelpFormatter,
)
delete_all_studies.add_argument(
"-k",
"--keep-associated-runs",
action="store_true",
help="Keep runs associated with the studies.",
)

# Subcommand: delete all-runs
delete_subcommands.add_parser(
Expand All @@ -949,9 +957,11 @@ def setup_argparse() -> None: # pylint: disable=R0915
# Add subcommands for get
get_subcommands = db_get.add_subparsers(dest="get_type", required=True)

get_study = get_subcommands.add_parser( # TODO perhaps this should just take in a spec file instead of the study name?
# TODO enable support for retrieval of study by name, ID, or passing in spec file
# Subcommand: get study
get_study = get_subcommands.add_parser(
"study",
help="Get a specific study by name.", # TODO add option to get by ID here as well
help="Get a specific study by name.",
formatter_class=ArgumentDefaultsHelpFormatter,
)
get_study.add_argument(
Expand All @@ -960,10 +970,11 @@ def setup_argparse() -> None: # pylint: disable=R0915
help="The name of the study to get.",
)

# TODO enable support for retrieval of run by workspace or ID
# Subcommand: get run
get_run = get_subcommands.add_parser(
"run",
help="Get a specific run by ID.", # TODO add option to get by workspace here as well
help="Get a specific run by ID.",
formatter_class=ArgumentDefaultsHelpFormatter,
)
get_run.add_argument(
Expand Down

0 comments on commit 4fa3e13

Please sign in to comment.