Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds scripts for generating json schemas for humans #617

Merged
merged 7 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ jobs:
pip install -e .[dev]
- name: Generate spec docs
run: python scripts/generate_spec_documentation.py --dist dist/user_docs
- name: Generate JSON schemas
run: python scripts/generate_json_schemas.py
- name: Generate interactive documentation
env:
PYTHONPATH: "./scripts"
run: python -m interactive_docs
- name: Generate JSON schemas
run: python scripts/generate_json_schemas.py
- name: Generate JSON schema documentation
run: python scripts/generate_json_schema_documentation.py
- id: get_version
run: python -c 'import bioimageio.spec;print(f"version={bioimageio.spec.__version__}")' >> $GITHUB_OUTPUT
- name: Generate developer docs
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,10 @@ Simplified descriptions are available as [JSON schema](https://json-schema.org/)

| bioimageio.spec version | JSON schema |
| --- | --- |
| latest | [bioimageio_schema_latest.json](https://github.com/bioimage-io/spec-bioimage-io/blob/gh-pages/bioimageio_schema_latest.json) |
| 0.5 | [bioimageio_schema_v0-5.json](https://github.com/bioimage-io/spec-bioimage-io/blob/gh-pages/bioimageio_schema_v0-5.json) |
| latest | [bioimageio_schema_latest.json](https://github.com/bioimage-io/spec-bioimage-io/blob/gh-pages/bioimageio_schema_latest.json) ([documentation (WIP)](https://github.com/bioimage-io/spec-bioimage-io/blob/gh-pages/bioimageio_schema_latest/index.html))|
| 0.5 | [bioimageio_schema_v0-5.json](https://github.com/bioimage-io/spec-bioimage-io/blob/gh-pages/bioimageio_schema_v0-5.json) ([documentation (WIP)](https://github.com/bioimage-io/spec-bioimage-io/blob/gh-pages/bioimageio_schema_v0-5/index.html))|

These are primarily intended for syntax highlighting and form generation.
These are primarily intended for syntax highlighting.

## Flattened, interactive docs

Expand Down
2 changes: 2 additions & 0 deletions conda-recipe/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ test:
- example_descriptions
requires:
{% for dep in setup_py_data['extras_require']['dev'] %}
{% if dep not in ('json_schema_for_humans',): %}
- {{ dep.replace('torch', 'pytorch').lower() }}
{% endif %}
{% endfor %}
commands:
- pytest -n auto --capture=no
Expand Down
38 changes: 38 additions & 0 deletions scripts/generate_json_schema_documentation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import shutil
import sys
from pathlib import Path

from json_schema_for_humans.generate import generate_from_filename
from json_schema_for_humans.generation_configuration import GenerationConfiguration

if __name__ == "__main__":
glob_pattern = "dist/bioimageio_schema_*.json"
schema_paths = list(Path().glob(glob_pattern))
if not schema_paths:
raise FileNotFoundError(
f"no json schema files found with pattern '{glob_pattern}'"
)

for schema_file_path in schema_paths:
output_dir = Path() / f"dist/{schema_file_path.stem}"
if output_dir.exists():
shutil.rmtree(output_dir)

output_dir.mkdir(parents=True)

generate_from_filename(
schema_file_name=schema_file_path,
result_file_name=str(output_dir / "index.html"),
config=GenerationConfiguration(
link_to_reused_ref=False,
deprecated_from_description=True,
default_from_description=True,
examples_as_yaml=True,
expand_buttons=True,
description_is_markdown=True,
copy_css=True,
copy_js=True,
),
)

print(f"Generated json schema docs at {output_dir}", file=sys.stderr)
6 changes: 5 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
import json
from pathlib import Path

from setuptools import find_namespace_packages, setup
from setuptools import (
find_namespace_packages,
setup, # pyright: ignore[reportUnknownVariableType]
)

# Get the long description from the README file
ROOT_DIR = Path(__file__).parent.resolve()
Expand Down Expand Up @@ -55,6 +58,7 @@
"jupyter",
"lxml",
"pdoc",
"json_schema_for_humans",
"pre-commit",
"psutil", # parallel pytest with '-n auto'
"pyright==1.1.378",
Expand Down
Loading