Skip to content

Commit

Permalink
generate task info in R
Browse files Browse the repository at this point in the history
  • Loading branch information
rcannood committed Dec 20, 2023
1 parent e11307b commit e9e6b61
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 49 deletions.
2 changes: 1 addition & 1 deletion _openproblems-v2
57 changes: 9 additions & 48 deletions documentation/create_task/define_task.qmd
Original file line number Diff line number Diff line change
Expand Up @@ -39,55 +39,16 @@ knitr::asis_output(md)
Now create a task info metadata file in the `src/tasks/<task_id>/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
Expand Down

0 comments on commit e9e6b61

Please sign in to comment.