Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions cadetrdm/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand All @@ -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()
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion cadetrdm/wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
45 changes: 44 additions & 1 deletion tests/test_options.py
Original file line number Diff line number Diff line change
@@ -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()
Expand Down Expand Up @@ -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"
Loading