Skip to content

Commit

Permalink
Use markdown comments to detect part to update
Browse files Browse the repository at this point in the history
  • Loading branch information
juhoinkinen committed Sep 19, 2024
1 parent afe4e3d commit 8df3bff
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions annif/hfh_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,28 +302,35 @@ def _create_modelcard(repo_id):
return card


AUTOGEN_START = "<!--- start-of-autogenerated-part --->"
AUTOGEN_END = "<!--- end-of-autogenerated-part --->"


def _update_projects_section(text, configs):
section_startind = text.find("## Projects\n")
section_endind = text.rfind("```") + 3 # end of code formatted block
section_start_ind = text.find(AUTOGEN_START)
section_end_ind = text.rfind(AUTOGEN_END) + len(AUTOGEN_END)

projects_section = _create_projects_section(configs)
if section_startind == -1: # no existing projects section, append it now

if section_start_ind == -1: # no existing projects section, append it now
return text + projects_section

Check warning on line 316 in annif/hfh_util.py

View check run for this annotation

Codecov / codecov/patch

annif/hfh_util.py#L316

Added line #L316 was not covered by tests
else:
return text[:section_startind] + projects_section + text[section_endind:]
return text[:section_start_ind] + projects_section + text[section_end_ind:]


def _create_projects_section(configs):
content = "## Projects\n"
content = f"{AUTOGEN_START}\n## Projects\n"

template = "{0:<19} {1:<23} {2:<15} {3:<11}\n"
header = template.format("Project ID", "Project Name", "Vocabulary ID", "Language")
content += "```\n" + header + "-" * len(header.strip()) + "\n"

for proj_id in configs.project_ids:
project = configs[proj_id]
content += template.format(

Check warning on line 330 in annif/hfh_util.py

View check run for this annotation

Codecov / codecov/patch

annif/hfh_util.py#L329-L330

Added lines #L329 - L330 were not covered by tests
proj_id,
configs[proj_id]["name"],
configs[proj_id]["vocab"],
configs[proj_id]["language"],
project["name"],
project["vocab"],
project["language"],
)
return content + "```"
return content + "```\n" + AUTOGEN_END

0 comments on commit 8df3bff

Please sign in to comment.