Skip to content

Commit

Permalink
Make fields variable width in project list of ModelCard (#809)
Browse files Browse the repository at this point in the history
  • Loading branch information
juhoinkinen authored Oct 2, 2024
1 parent 4dcece7 commit 4e171cf
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
34 changes: 22 additions & 12 deletions annif/hfh_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from flask import current_app

import annif
from annif import cli_util
from annif.config import AnnifConfigCFG
from annif.exception import OperationFailedException
from annif.project import Access, AnnifProject
Expand Down Expand Up @@ -349,18 +350,27 @@ def _update_projects_section(text, configs):


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

template = "{0:<19} {1:<23} {2:<15} {3:<8}\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(
column_headings = (
"Project ID",
"Project Name",
"Vocabulary ID",
"Language",
)
table = [
(
proj_id,
project["name"],
project["vocab"],
project["language"],
configs[proj_id]["name"],
configs[proj_id]["vocab"],
configs[proj_id]["language"],
)
for proj_id in configs.project_ids
]
template = cli_util.make_list_template(column_headings, *table) + "\n"

header = template.format(*column_headings)

content = f"{AUTOUPDATING_START}\n## Projects\n"
content += "```\n" + header + "-" * len(header.strip()) + "\n"
for row in table:
content += template.format(*row)
return content + "```\n" + AUTOUPDATING_END
19 changes: 9 additions & 10 deletions tests/test_hfh_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,8 @@ def test_upsert_modelcard_update_existing(read_text, glob, load, push_to_hub, pr
load.assert_called_once_with(repo_id)

card = load.return_value
retained_project_list_content = (
"dummy-en Dummy English dummy en"
)
retained_project_list_content = "dummy-en Dummy English dummy en "

assert retained_project_list_content in card.text
assert sorted(card.data.language) == ["en", "fi"]
card.push_to_hub.assert_called_once_with(
Expand All @@ -227,8 +226,8 @@ def test_update_modelcard_projects_section_append_new():
<!--- start-of-autoupdating-part --->
## Projects
```
Project ID Project Name Vocabulary ID Language
--------------------------------------------------------------------
Project ID Project Name Vocabulary ID Language
-------------------------------------------------
```
<!--- end-of-autoupdating-part --->"""

Expand All @@ -250,8 +249,8 @@ def test_update_modelcard_projects_section_update_existing():
<!--- start-of-autoupdating-part --->
## Projects
```
Project ID Project Name Vocabulary ID Language
--------------------------------------------------------------------
Project ID Project Name Vocabulary ID Language
-------------------------------------------------
```
<!--- end-of-autoupdating-part --->\n"""

Expand All @@ -266,9 +265,9 @@ def test_update_modelcard_projects_section_update_existing():
<!--- start-of-autoupdating-part --->
## Projects
```
Project ID Project Name Vocabulary ID Language
--------------------------------------------------------------------
dummy-fi Dummy Finnish dummy fi \n```
Project ID Project Name Vocabulary ID Language
--------------------------------------------------
dummy-fi Dummy Finnish dummy fi \n```
<!--- end-of-autoupdating-part --->
"""

Expand Down

0 comments on commit 4e171cf

Please sign in to comment.