Skip to content

Commit 00bcaa3

Browse files
committed
Render schema in docs; update schema; update changelog
1 parent 8b3ad8c commit 00bcaa3

12 files changed

+214
-29
lines changed

CHANGELOG.md

+2
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2323

2424
### Changed
2525

26+
- Configuration validation to use a JSON schema. Partially **backward-incompatible** since configuration errors now raise exceptions rather than logging a message to the `error` level [#56](https://github.com/arup-group/osmox/pull/56).
2627
- Recommended installation instructions changed from using `pip` to creating a `mamba` environment [#38](https://github.com/arup-group/osmox/pull/38).
2728
- Supported and tested Python versions updated to py3.10 - py3.12 [#38](https://github.com/arup-group/osmox/pull/38).
2829
- Majority of documentation moved from README to dedicated documentation site: https://arup-group.github.io/osmox [#40](https://github.com/arup-group/osmox/pull/40).
2930
- Default output format changed from `.geojson` to `.gpkg` & support for multiple file formats (`.gpkg`, `.geojson`, `.parquet`) [#41](https://github.com/arup-group/osmox/issues/41)
3031

3132
### Added
3233

34+
- Rendered JSON schema in documentation [#56](https://github.com/arup-group/osmox/pull/56).
3335
- Activity infilling can use a geospatial point data source to fill OSM `landuse` areas, e.g. postcode data points.
3436
- Activity infilling can take place in target areas that have existing facilities, using the `max_existing_acts_fraction` argument to set the area that existing facilities can already take up in the target geometry while still allowing infilling.
3537

configs/config_UK.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "../src/osmox/schema.json",
23
"filter": {
34
"building": [
45
"apartments",

configs/config_UKfill.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "../src/osmox/schema.json",
23
"filter": {
34
"building": [
45
"apartments",

configs/config_UKno_transit.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "../src/osmox/schema.json",
23
"filter": {
34
"building": [
45
"apartments",
@@ -34,7 +35,7 @@
3435
"sports_hall",
3536
"stadium",
3637
"yes"
37-
]
38+
]
3839
},
3940

4041
"object_features": ["units", "levels", "area", "floor_area"],

configs/example.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"$schema": "../src/osmox/schema.json",
23
"filter": {
34
"building": [
45
"apartments",

docs/config.md

+4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ osmox validate <CONFIG PATH>
99

1010
OSMOX features and associated configurations are described in the sections below.
1111

12+
!!! info "See also"
13+
We use a configuration schema to validate the configuration files you input - malformed files will cause OSMOX to fail fast and early.
14+
You can read a detailed description of the configuration as described in the schema [here](schema.md).
15+
1216
!!! warning
1317
These configs get very long - see the full examples in the `configs` to get an idea.
1418

docs/static/hooks.py

+31-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import tempfile
22
from pathlib import Path
33

4+
import jsonschema2md
45
import mkdocs.plugins
56
from mkdocs.structure.files import File
7+
from osmox.config import SCHEMA
68

79
TEMPDIR = tempfile.TemporaryDirectory()
810
# Add to this list if you want to ignore any other source files from the documentation API reference
@@ -16,7 +18,7 @@ def on_files(files: list, config: dict, **kwargs):
1618
for file in Path("./resources").glob("**/*.*"):
1719
files.append(_new_file(file, config))
1820
files.append(_new_file(Path("./CHANGELOG.md"), config))
19-
21+
files.append(_schema_to_md(SCHEMA, config))
2022
api_nav = _api_gen(files, config)
2123
_update_nav(api_nav, config)
2224

@@ -137,6 +139,34 @@ def _get_nav_list(nav: list[dict | str], ref: str) -> list:
137139
return nav_ref[ref]
138140

139141

142+
def _schema_to_md(schema: dict, config: dict) -> File:
143+
"""Parse a JSON schema to Markdown, edit some lines, then dump to file
144+
145+
Args:
146+
schema (dict): Path to the YAML schema to be converted.
147+
"""
148+
output_file = "schema.md"
149+
output_full_filepath = Path(TEMPDIR.name) / output_file
150+
output_full_filepath.parent.mkdir(exist_ok=True, parents=True)
151+
152+
parser = jsonschema2md.Parser()
153+
parser.tab_size = 4
154+
155+
lines = parser.parse_schema(schema)
156+
157+
assert lines[2] == "## Properties\n\n"
158+
del lines[2]
159+
160+
output_full_filepath.write_text("\n".join(lines))
161+
162+
return File(
163+
path=output_file,
164+
src_dir=TEMPDIR.name,
165+
dest_dir=config["site_dir"],
166+
use_directory_urls=config["use_directory_urls"],
167+
)
168+
169+
140170
@mkdocs.plugins.event_priority(-100)
141171
def on_post_build(**kwargs):
142172
"""After mkdocs has finished building the docs, remove the temporary directory of markdown files.

mkdocs.yml

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ nav:
55
- quick_start.md
66
- osmox_run.md
77
- config.md
8+
- Configuration schema: schema.md
89
- Contributing: contributing.md
910
- Changelog: CHANGELOG.md
1011
- Reference:

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ where = ["src"]
6868
# Add file globs from the source code directory if they include non-py files that should be packaged
6969
# E.g. "fixtures/**/*"
7070
# "py.typed" is added by default. It allows `mypy` to register the package as having type hints.
71-
osmox = ["py.typed"]
71+
osmox = ["py.typed", "schema.json"]
7272

7373

7474
[build-system]

requirements/base.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
click < 9
2+
jsonschema >= 4, < 5
23
geopandas >= 0.13, < 0.15
34
osmium < 3.7
45
pandas >= 1.5, < 3

requirements/dev.txt

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
cruft >= 2, < 3
2+
jsonschema2md >= 1.1, < 2
23
mike >= 2, < 3
34
mkdocs < 2
45
mkdocs-material >= 9.4, < 10

0 commit comments

Comments
 (0)