From e9e6b61eebb9bb27fdbf20ba524f913d8c994113 Mon Sep 17 00:00:00 2001 From: Robrecht Cannoodt Date: Wed, 20 Dec 2023 21:06:53 +0100 Subject: [PATCH] generate task info in R --- _openproblems-v2 | 2 +- documentation/create_task/define_task.qmd | 57 ++++------------------- 2 files changed, 10 insertions(+), 49 deletions(-) diff --git a/_openproblems-v2 b/_openproblems-v2 index 4e0449ae..6f6acccf 160000 --- a/_openproblems-v2 +++ b/_openproblems-v2 @@ -1 +1 @@ -Subproject commit 4e0449ae9d7779677357a3c8632f624d87a58ce0 +Subproject commit 6f6acccfdb7068a6c198b41e0d67d47552488b3b diff --git a/documentation/create_task/define_task.qmd b/documentation/create_task/define_task.qmd index 5255366c..e1f25761 100644 --- a/documentation/create_task/define_task.qmd +++ b/documentation/create_task/define_task.qmd @@ -39,55 +39,16 @@ knitr::asis_output(md) Now create a task info metadata file in the `src/tasks//api` directory. This file will be part of the automatic "readme" creation in the repo directory of this task. The task info file should be named `task_info.yaml` and should contain the following information: -```{r echo=FALSE, warning=TRUE, error=TRUE} -info <- read_and_merge_yaml("src/common/schemas/task_info.yaml") - -``` - - -```{python} -#| echo: false -#| output: asis -info = r.info - -task_info = open("task_info_template.yaml", "w") - -def process(info, prefix = ""): - for prop in info["properties"]: - if prop != "additionalProperties": - task_info.write(f"{prefix}{prop}: ") - if info["properties"][prop]["type"] == "string" and "description" in info["properties"][prop]: - task_info.write(f"\'{info['properties'][prop]['description'].strip()}\'\n" ) - elif info["properties"][prop]["type"] == "string" and "description" not in info["properties"][prop]: - task_info.write(f"{prefix}\n" ) - elif info["properties"][prop]["type"] == "object": - subinfo = info["properties"][prop] - task_info.write("\n") - process(subinfo, prefix = " ") - elif info["properties"][prop]["type"] == "array": - if "description" in info["properties"][prop]: - task_info.write(f"\'{info['properties'][prop]['description'].strip()}\'\n" ) - subinfo = info["properties"][prop]["items"] - if "properties" in subinfo: - task_info.write("\n - ") - process(subinfo, prefix = " ") - - - -process(info) - -task_info.close() -``` - -```` yaml -```{bash} -#| echo: false -#| output: asis -cat task_info_template.yaml +```{r echo=FALSE, warning=FALSE, error=FALSE} +json_schema <- read_and_merge_yaml("src/common/schemas/task_info.yaml") +yaml_example <- render_example(json_schema) + +knitr::asis_output(paste0( + "```yaml\n", + yaml_example, "\n", + "```\n" +)) ``` -```` - - ## Next steps