Skip to content
Open
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
83 changes: 83 additions & 0 deletions config/config.schema.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"additionalProperties": false,
"properties": {
"countries": {
"default": [
"benin",
"togo"
],
"description": "tbd",
"items": {
"type": "string"
},
"minItems": 1,
"type": "array"
},
"retrieve": {
"additionalProperties": false,
"properties": {
"source": {
"default": "geofabrik",
"description": "tbd",
"enum": [
"geofabrik",
"overpass"
],
"type": "string"
},
"primary_name": {
"default": "power",
"description": "tbd",
"type": "string"
},
"features": {
"default": [
"substation",
"line"
],
"description": "tbd",
"items": {
"type": "string"
},
"minItems": 1,
"type": "array"
},
"force_redownload": {
"default": false,
"description": "tbd",
"type": "boolean"
},
"mp": {
"default": true,
"description": "tbd",
"type": "boolean"
},
"stream_backend": {
"default": true,
"description": "tbd",
"type": "boolean"
},
"cache_primary": {
"default": false,
"description": "tbd",
"type": "boolean"
},
"target_date": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "tbd"
}
},
"description": "tbd"
}
},
"title": "ConfigSchema",
"type": "object"
}
14 changes: 8 additions & 6 deletions config/config.yaml
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
%YAML 1.1
---
# yaml-language-server: $schema=./config.schema.json
countries:
- benin
- togo

- benin
- togo
retrieve:
source: geofabrik
primary_name: power
features:
- substation
- line
- substation
- line
force_redownload: false
mp: true
stream_backend: true
cache_primary: false
target_date: null
target_date:
4 changes: 3 additions & 1 deletion pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ clio-tools = ">=2026.03.30"
conda = ">=25.0.0"
ipdb = ">=0.13.13"
ipykernel = ">=6.29.5"
jsonschema = ">=4.0.0"
pydantic = ">=2.0"
"ruamel.yaml" = ">=0.18"
mypy = ">=1.15.0"
pytest = ">=8.3.5"
python = ">=3.12"
Expand All @@ -25,3 +26,4 @@ earth-osm = ">=3.0.2"

[tasks]
test-integration = {cmd = "pytest tests/integration_test.py"}
generate-config = {cmd = "python workflow/scripts/_schema.py"}
2 changes: 1 addition & 1 deletion tests/integration_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def test_interface_file(module_path):
"LICENSE",
"README.md",
"config/config.yaml",
"workflow/internal/config.schema.yaml",
"config/config.schema.json",
"tests/integration/Snakefile",
],
)
Expand Down
10 changes: 7 additions & 3 deletions workflow/Snakefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
import sys

import yaml
from snakemake.utils import min_version

from snakemake.utils import min_version, validate
sys.path.insert(0, workflow.basedir)
from scripts._schema import validate_config

min_version("9.19")

Expand All @@ -15,8 +19,8 @@ pathvars:
configfile: workflow.source_path("../config/config.yaml")


# Validate the configuration using the schema file.
validate(config, workflow.source_path("internal/config.schema.yaml"))
# Validate the configuration using the Pydantic schema.
config = validate_config(config)

# Load internal settings separately so users cannot modify them.
with open(workflow.source_path("internal/settings.yaml"), "r") as f:
Expand Down
56 changes: 0 additions & 56 deletions workflow/internal/config.schema.yaml

This file was deleted.

Loading
Loading