From 87a960c2d7ff9d13bc05736a9ba050412750f4a4 Mon Sep 17 00:00:00 2001 From: Hannah Lanzrath Date: Wed, 23 Jul 2025 16:25:12 +0200 Subject: [PATCH 1/3] Add Options to Repo Class And Prefix Co-authored-by: k.paul@fz-juelich.de Co-authored-by: Katharina Paul --- cadetrdm/repositories.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/cadetrdm/repositories.py b/cadetrdm/repositories.py index a85a7c0..595e79f 100644 --- a/cadetrdm/repositories.py +++ b/cadetrdm/repositories.py @@ -760,7 +760,7 @@ def add_list_of_remotes_in_readme_file(self, repo_identifier: str, remotes_url_l class ProjectRepo(BaseRepo): def __init__(self, path=None, output_folder=None, search_parent_directories=True, suppress_lfs_warning=False, - url=None, branch=None, + url=None, branch=None, options=None, *args, **kwargs): """ Class for Project-Repositories. Handles interaction between the project repo and @@ -780,6 +780,8 @@ def __init__(self, path=None, output_folder=None, from a system without git-lfs :param branch: Optional branch to check out upon initialization + :param options: + Options dictionary containing ... :param args: Additional args to be handed to BaseRepo. :param kwargs: @@ -805,6 +807,7 @@ def __init__(self, path=None, output_folder=None, self._project_uuid = self._metadata["project_uuid"] self._output_uuid = self._metadata["output_uuid"] self._output_folder = self._metadata["output_remotes"]["output_folder_name"] + self.options = options if not (self.path / self._output_folder).exists(): print("Output repository was missing, cloning now.") self._clone_output_repo() @@ -944,7 +947,13 @@ def get_new_output_branch_name(self): """ project_repo_hash = str(self.head.commit) timestamp = datetime.now().strftime("%Y-%m-%d_%H-%M-%S") - branch_name = "_".join([timestamp, str(self.active_branch), project_repo_hash[:7]]) + + if self.options and "branch_prefix" in self.options: + branch_prefix = self.options["branch_prefix"]+"_" + else: + branch_prefix = "" + + branch_name = branch_prefix+"_".join([timestamp, str(self.active_branch), project_repo_hash[:7]]) return branch_name def check_results_main(self): From 3fb125c98e63911a5294291f27b3dd5b582bd9d2 Mon Sep 17 00:00:00 2001 From: Hannah Lanzrath Date: Wed, 23 Jul 2025 16:25:07 +0200 Subject: [PATCH 2/3] Hand over Options to ProjectRepo Co-authored-by: Katharina Paul --- cadetrdm/wrapper.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cadetrdm/wrapper.py b/cadetrdm/wrapper.py index 584fcec..69248e0 100644 --- a/cadetrdm/wrapper.py +++ b/cadetrdm/wrapper.py @@ -29,7 +29,7 @@ def wrapper(options, repo_path='.'): if options.get_hash() != Options.load_json_str(options.dump_json_str()).get_hash(): raise ValueError("Options are not serializable. Please only use python natives and numpy ndarrays.") - project_repo = ProjectRepo(repo_path) + project_repo = ProjectRepo(repo_path, options=options) project_repo.options_hash = options.get_hash() From ff1104172f430a44e343794a6d1511f92d7bb336 Mon Sep 17 00:00:00 2001 From: Hannah Lanzrath Date: Wed, 23 Jul 2025 16:24:55 +0200 Subject: [PATCH 3/3] Add Branch Name Test to Options Co-authored-by: Katharina Paul --- tests/test_options.py | 45 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/tests/test_options.py b/tests/test_options.py index 7cb4666..b8108cf 100644 --- a/tests/test_options.py +++ b/tests/test_options.py @@ -1,8 +1,11 @@ import numpy as np +import re from cadetrdm import Options from cadetrdm.options import remove_invalid_keys - +from cadetrdm import process_example +from cadetrdm import ProjectRepo +from pathlib import Path def test_options_hash(): opt = Options() @@ -104,3 +107,43 @@ def test_explicit_invalid_keys(): } } assert remove_invalid_keys(input_dict, excluded_keys=["a"]) == expected + +def test_branch_name(): + options = Options() + options.commit_message = "Commit Message Test" + options.debug = True + options.push = False + options.source_directory = "src" + + repo = ProjectRepo(Path("./test_repo_cli"), options=options) + + hash = str(repo.head.commit)[:7] + active_branch = str(repo.active_branch) + new_branch = repo.get_new_output_branch_name() + + escaped_branch = re.escape(active_branch) + + pattern = rf"^\d{{4}}-\d{{2}}-\d{{2}}_\d{{2}}-\d{{2}}-\d{{2}}_{escaped_branch}_{hash}$" + + assert re.match(pattern, new_branch), f"Branch name '{new_branch}' does not match expected format" + +def test_branch_name_with_prefix(): + + options = Options() + options.commit_message = "Commit Message Test" + options.debug = True + options.push = False + options.source_directory = "src" + options.branch_prefix = "Test_Prefix" + + repo = ProjectRepo(Path("./test_repo_cli"), options=options) + + hash = str(repo.head.commit)[:7] + active_branch = str(repo.active_branch) + new_branch = repo.get_new_output_branch_name() + + escaped_branch = re.escape(active_branch) + + pattern = rf"^Test_Prefix_\d{{4}}-\d{{2}}-\d{{2}}_\d{{2}}-\d{{2}}-\d{{2}}_{escaped_branch}_{hash}$" + + assert re.match(pattern, new_branch), f"Branch name '{new_branch}' does not match expected format" \ No newline at end of file