Skip to content

Commit

Permalink
Merge pull request #2150 from awgymer/schema-docs-fix-output
Browse files Browse the repository at this point in the history
Schema docs fix output
  • Loading branch information
awgymer authored Jan 10, 2023
2 parents 5a7a98a + 1350a1b commit 681ccf3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
3 changes: 1 addition & 2 deletions nf_core/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1446,8 +1446,7 @@ def docs(schema_path, output, format, force, columns):
# Assume we're in a pipeline dir root if schema path not set
schema_obj.get_schema_path(schema_path)
schema_obj.load_schema()
if not output:
stdout.print(schema_obj.print_documentation(output, format, force, columns.split(",")))
schema_obj.print_documentation(output, format, force, columns.split(","))


# nf-core bump-version
Expand Down
27 changes: 20 additions & 7 deletions nf_core/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,20 @@
import json
import logging
import os
import tempfile
import webbrowser

import jinja2
import jsonschema
import markdown
import rich.console
import yaml
from rich.prompt import Confirm
from rich.syntax import Syntax

import nf_core.list
import nf_core.utils
from nf_core.lint_utils import dump_json_with_prettier
from nf_core.lint_utils import dump_json_with_prettier, run_prettier_on_file

log = logging.getLogger(__name__)

Expand Down Expand Up @@ -464,13 +467,21 @@ def print_documentation(
if format == "html":
output = self.markdown_to_html(output)

# Print to file
if output_fn:
with tempfile.NamedTemporaryFile(mode="w+") as fh:
fh.write(output)
run_prettier_on_file(fh.name)
fh.seek(0)
prettified_docs = fh.read()

if not output_fn:
console = rich.console.Console()
console.print("\n", Syntax(prettified_docs, format), "\n")
else:
if os.path.exists(output_fn) and not force:
log.error(f"File '{output_fn}' exists! Please delete first, or use '--force'")
return
with open(output_fn, "w") as file:
file.write(output)
with open(output_fn, "w") as fh:
fh.write(prettified_docs)
log.info(f"Documentation written to '{output_fn}'")

# Return as a string
Expand All @@ -495,9 +506,11 @@ def schema_to_markdown(self, columns):
if column == "parameter":
out += f"| `{p_key}` "
elif column == "description":
out += f"| {param.get('description', '')} "
desc = param.get("description", "").replace("\n", "<br>")
out += f"| {desc} "
if param.get("help_text", "") != "":
out += f"<details><summary>Help</summary><small>{param['help_text']}</small></details>"
help_txt = param["help_text"].replace("\n", "<br>")
out += f"<details><summary>Help</summary><small>{help_txt}</small></details>"
elif column == "type":
out += f"| `{param.get('type', '')}` "
else:
Expand Down

0 comments on commit 681ccf3

Please sign in to comment.