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
25 changes: 14 additions & 11 deletions cadetrdm/initialize_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,22 +233,25 @@ def create_environment_yml():


def create_readme():
readme_lines = ["# Project repo", "Your code goes in this repo.", "Please add a description here including: ",
"- authors", "- project", "- things we will find interesting later", "", "",
"Please update the environment.yml with your python environment requirements.", "", "",
"The output repository can be found at:",
"[output_repo]() (not actually set yet because no remote has been configured at this moment"]
readme_lines = ["## Output Repository",
"",
"The output data for this case study can be found here:",
"[Link to Output Repository]() (not actually set yet because no remote has been configured at this moment)"]
write_lines_to_file("README.md", readme_lines, open_type="a")


def create_output_readme():
readme_lines = ["# Output repo", "Your results will be stored here.", "Please add a description here including: ",
"- authors", "- project", "- things we will find interesting later", "", "",
"The project repository can be found at:",
"[project_repo]() (not actually set yet because no remote has been configured at this moment"]
readme_lines = ["# Output repository for Example Simulation with CADET",
"This repository stores the simulation results for RDM-Example. `CADET-RDM` automatically tracks all simulations that are started by running `main.py` from the corresponding project repository.",
"",
"Each simulation run creates a dedicated branch in this output repository. The results are saved within the `src` folder of the respective branch. Additionally, a `log.tsv` file in the main branch records metadata for all runs, uniquely linking each output branch to its originating run in the project repository.",
"",
"## Project Repository",
"",
"The project repository for this case study is available here: ",
"[Link to Project Repository]() (not actually set yet because no remote has been configured at this moment)"]
write_lines_to_file("README.md", readme_lines, open_type="a")


def create_dockerfile():
write_lines_to_file("Dockerfile", dockerfile_template, open_type="w")

write_lines_to_file("Dockerfile", dockerfile_template, open_type="w")
16 changes: 8 additions & 8 deletions cadetrdm/repositories.py
Original file line number Diff line number Diff line change
Expand Up @@ -562,14 +562,14 @@ def add_remote(self, remote_url, remote_name=None):
if output_repo.has_uncomitted_changes:
output_repo.stash_all_changes()
output_repo.checkout(output_repo.main_branch)
output_repo.add_list_of_remotes_in_readme_file("project_repo", self.remote_urls)
output_repo.add_list_of_remotes_in_readme_file("Link to Project Repository", self.remote_urls)
output_repo.add("README.md")
output_repo.commit("Add remote for project repo", verbosity=0, add_all=False)
if self._metadata["is_output_repo"]:
# This folder is an output repo
project_repo = ProjectRepo(self.path.parent)
project_repo.update_output_remotes_json()
project_repo.add_list_of_remotes_in_readme_file("output_repo", self.remote_urls)
project_repo.add_list_of_remotes_in_readme_file("Link to Output Repository", self.remote_urls)
project_repo.add(project_repo.data_json_path)
project_repo.add("README.md")
project_repo.commit("Add remote for output repo", verbosity=0, add_all=False)
Expand Down Expand Up @@ -737,15 +737,15 @@ def add_list_of_remotes_in_readme_file(self, repo_identifier: str, remotes_url_l
for output_repo_remote in remotes_url_list_http) + "\n"

readme_filepath = self.path / "README.md"
with open(readme_filepath, "r") as file_handle:
with open(readme_filepath, "r", encoding="utf-8") as file_handle:
filelines = file_handle.readlines()
filelines_giving_output_repo = [i for i in range(len(filelines))
if filelines[i].startswith(f"[{repo_identifier}](")]
if filelines[i].strip().startswith(f"[{repo_identifier}](")]
if len(filelines_giving_output_repo) == 1:
line_to_be_modified = filelines_giving_output_repo[0]
filelines[line_to_be_modified] = output_link_line
elif len(filelines_giving_output_repo) == 0:
filelines.append("The output repo can be found at:\n")
filelines.append("The output repository can be found at:\n") #method can be used for project and output repositories, "the corresponding repository can be found at... would be better"
filelines.append(output_link_line)
else:
raise RuntimeError(f"Multiple lines in the README.md at {readme_filepath}"
Expand Down Expand Up @@ -1157,13 +1157,13 @@ def check(self, commit=True):

# update urls in main branch of output_repo
self.output_repo._git.checkout(self.output_repo.main_branch)
self.output_repo.add_list_of_remotes_in_readme_file("project_repo", self.remote_urls)
self.output_repo.add_list_of_remotes_in_readme_file("Link to Project Repository", self.remote_urls)
if commit:
self.output_repo.commit(message="Update remote links", add_all=False, verbosity=1)

def update_output_remotes_json(self):
output_repo_remotes = self.output_repo.remote_urls
self.add_list_of_remotes_in_readme_file("output_repo", output_repo_remotes)
self.add_list_of_remotes_in_readme_file("Link to Output Repository", output_repo_remotes)

with open(self.data_json_path, "r") as file_handle:
metadata = json.load(file_handle)
Expand Down Expand Up @@ -1297,7 +1297,7 @@ def _get_new_output_branch(self, force=False):
# update urls in main branch of output_repo
output_repo._git.checkout(output_repo.main_branch)
project_repo_remotes = self.remote_urls
output_repo.add_list_of_remotes_in_readme_file("project_repo", project_repo_remotes)
output_repo.add_list_of_remotes_in_readme_file("Link to Project Repository", project_repo_remotes)
output_repo.commit("Update urls", verbosity=0)

# Create the new branch
Expand Down
4 changes: 2 additions & 2 deletions tests/test_git_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -277,10 +277,10 @@ def test_rdm_check():
repo.check()
with open(repo.path / "README.md", "r") as handle:
readme_lines = handle.readlines()
assert f'[output_repo]({ssh_url_to_http_url(new_output_url)})\n' in readme_lines
assert f'[Link to Output Repository]({ssh_url_to_http_url(new_output_url)})\n' in readme_lines
with open(repo.output_repo.path / "README.md", "r") as handle:
readme_lines = handle.readlines()
assert f'[project_repo]({ssh_url_to_http_url(new_project_url)})\n' in readme_lines
assert f'[Link to Project Repository]({ssh_url_to_http_url(new_project_url)})\n' in readme_lines


def test_copy_external_data():
Expand Down
Loading