diff --git a/_viash.yaml b/_viash.yaml index f6472c608..1fd19f691 100644 --- a/_viash.yaml +++ b/_viash.yaml @@ -1,7 +1,7 @@ name: openproblems version: dev organization: openproblems-bio -viash_version: 0.9.4 +viash_version: 0.9.7 description: | Open Problems is a living, extensible, community-guided benchmarking platform. diff --git a/src/project/render_readme/config.vsh.yaml b/src/project/render_readme/config.vsh.yaml index f6a802f1e..c367f9b48 100644 --- a/src/project/render_readme/config.vsh.yaml +++ b/src/project/render_readme/config.vsh.yaml @@ -19,24 +19,17 @@ argument_groups: default: README.md required: false resources: - - type: r_script - path: script.R + - type: python_script + path: script.py test_resources: - - type: r_script - path: test.R + - type: python_script + path: test.py engines: - type: docker - image: openproblems/base_r:1 + image: openproblems/base_python:1 setup: - - type: r - cran: - - processx - github: - - openproblems-bio/core/packages/r/openproblems.utils - - openproblems-bio/core/packages/r/openproblems - - openproblems-bio/core/packages/r/openproblems.docs - type: apt - packages: [jq, curl] + packages: [jq, curl, git] - type: docker # download and install quarto-*-linux-amd64.deb from latest release run: | diff --git a/src/project/render_readme/script.R b/src/project/render_readme/script.R deleted file mode 100644 index dcd394df4..000000000 --- a/src/project/render_readme/script.R +++ /dev/null @@ -1,35 +0,0 @@ -requireNamespace("openproblems.docs", quietly = TRUE) -requireNamespace("processx", quietly = TRUE) - -## VIASH START -par <- list( - "input" = "path/to/input", - "output" = "path/to/input/README.md" -) -## VIASH END - -cat("Read task metadata\n") -metadata <- openproblems.docs::read_task_metadata(par$input) - -cat("Render README.qmd content\n") -qmd_content <- openproblems.docs::render_task_readme_qmd(metadata) - -cat("Write README.qmd to file\n") -if (!dir.exists(meta$temp_dir)) { - dir.create(meta$temp_dir, recursive = TRUE) -} -qmd_file <- tempfile( - pattern = "README_", - fileext = ".qmd", - tmpdir = meta$temp_dir -) -writeLines(qmd_content, qmd_file) - -cat("Render README.qmd to README.md\n") -out <- processx::run( - command = "quarto", - args = c("render", qmd_file, "--output", "-"), - echo = TRUE -) - -writeLines(out$stdout, par$output) diff --git a/src/project/render_readme/script.py b/src/project/render_readme/script.py new file mode 100644 index 000000000..7f66ba530 --- /dev/null +++ b/src/project/render_readme/script.py @@ -0,0 +1,47 @@ +from pathlib import Path +import subprocess + +from openproblems.project import read_task_metadata, render_task_readme_qmd + +## VIASH START +par = { + "input": "path/to/input", + "output": "path/to/input/README.md", +} +## VIASH END + +print("Read task metadata", flush=True) +metadata = read_task_metadata(par["input"]) + +print("Render README.qmd content", flush=True) +qmd_content = render_task_readme_qmd(metadata) + +output_path = Path(par["output"]) +output_path.parent.mkdir(parents=True, exist_ok=True) +qmd_path = output_path.with_suffix(".qmd") + +print("Write README.qmd to file", flush=True) +qmd_path.write_text(qmd_content) + +print("Render README.qmd to README.md", flush=True) +out = subprocess.run( + ["quarto", "render", str(qmd_path), "--output", "-"], + capture_output=True, + text=True, +) + +if out.returncode != 0: + stdout = (out.stdout or "").strip() + stderr = (out.stderr or "").strip() + details = [] + if stdout: + details.append(f"stdout:\n{stdout}") + if stderr: + details.append(f"stderr:\n{stderr}") + if not details: + details.append("No output captured from Quarto") + raise RuntimeError( + "Failed to render README.qmd with Quarto.\n\n" + "\n\n".join(details) + ) + +output_path.write_text(out.stdout) diff --git a/src/project/render_readme/test.R b/src/project/render_readme/test.R deleted file mode 100644 index 96b029d1c..000000000 --- a/src/project/render_readme/test.R +++ /dev/null @@ -1,27 +0,0 @@ -requireNamespace("assertthat", quietly = TRUE) - -## VIASH START -## VIASH END - -input <- system.file("extdata", "example_project", "api", package = "openproblems.docs") - -output_path <- "output.md" - -cat(">> Running the script as test\n") -out <- processx::run( - meta[["executable"]], - args = c("--input", input, "--output", output_path) -) - -cat(">> Checking whether output files exist\n") -assertthat::assert_that(file.exists(output_path)) - -cat(">> Checking file contents\n") -lines <- readLines(output_path) -assertthat::assert_that(any(grepl("# Template", lines))) -assertthat::assert_that(any(grepl("## Description", lines))) -# assertthat::assert_that(any(grepl("## Authors", lines))) -assertthat::assert_that(any(grepl("flowchart TB", lines))) -assertthat::assert_that(any(grepl("## File format:", lines))) - -cat("All checks succeeded!\n") diff --git a/src/project/render_readme/test.py b/src/project/render_readme/test.py new file mode 100644 index 000000000..74777fe57 --- /dev/null +++ b/src/project/render_readme/test.py @@ -0,0 +1,74 @@ +import subprocess +from pathlib import Path +from tempfile import TemporaryDirectory + +## VIASH START +meta = { + "executable": "foo", +} +## VIASH END + +task_template_repo = "https://github.com/openproblems-bio/task_template.git" + +with TemporaryDirectory() as tmpdir: + tmpdir_path = Path(tmpdir) + task_template_path = tmpdir_path / "task_template" + input_path = task_template_path / "src" / "api" + output_path = Path(tmpdir) / "README.md" + qmd_path = Path(tmpdir) / "README.qmd" + + clone_cmd = [ + "git", + "clone", + "--depth", + "1", + task_template_repo, + str(task_template_path), + ] + + print(">> Cloning task_template", flush=True) + clone_out = subprocess.run(clone_cmd, capture_output=True, text=True) + + if clone_out.stdout: + print(clone_out.stdout) + if clone_out.stderr: + print(clone_out.stderr) + + if clone_out.returncode: + print(f"script: '{' '.join(clone_cmd)}' exited with an error.") + exit(clone_out.returncode) + + cmd = [ + meta["executable"], + "--input", + str(input_path), + "--output", + str(output_path), + ] + + print(">> Running the script as test", flush=True) + out = subprocess.run(cmd, capture_output=True, text=True) + + if out.stdout: + print(out.stdout) + if out.stderr: + print(out.stderr) + + if out.returncode: + print(f"script: '{' '.join(cmd)}' exited with an error.") + exit(out.returncode) + + print(">> Checking whether output files exist", flush=True) + assert output_path.exists(), "README.md was not generated" + assert qmd_path.exists(), "README.qmd was not generated" + + print(">> Checking file contents", flush=True) + output_lines = output_path.read_text().splitlines() + qmd_lines = qmd_path.read_text().splitlines() + + assert any("## Description" in line for line in output_lines), "README.md is missing description section" + assert any("flowchart TB" in line for line in output_lines), "README.md is missing task graph" + assert any("## File format:" in line for line in output_lines), "README.md is missing file format section" + assert any("format: gfm" in line for line in qmd_lines), "README.qmd header is missing gfm format" + +print("All checks succeeded!", flush=True) diff --git a/src/reporting/render_report/config.vsh.yaml b/src/reporting/render_report/config.vsh.yaml index 8864c7978..0afbc251e 100644 --- a/src/reporting/render_report/config.vsh.yaml +++ b/src/reporting/render_report/config.vsh.yaml @@ -44,8 +44,10 @@ test_resources: engines: - type: docker - image: openproblems/base_r:1.0.0 + image: openproblems/base_r:1 setup: + - type: apt + packages: [wget] - type: docker run: | export QUARTO_VERSION="1.7.32" && \