Source code for pyxel_config_core._data
from __future__ import annotations
import hashlib
import json
from functools import lru_cache
from pathlib import Path
from typing import Any
DATA_DIR = Path(__file__).parent / "data"
SCHEMA_PATH = DATA_DIR / "pyxel_schema.json"
PARAMS_PATH = DATA_DIR / "modelParameters.json"
BUNDLE_PATH = DATA_DIR / "BUNDLE.json"
TUTORIALS_DIR = DATA_DIR / "tutorials"
@lru_cache(maxsize=1)
def load_schema() -> dict[str, Any]:
data: dict[str, Any] = json.loads(SCHEMA_PATH.read_text(encoding="utf-8"))
return data
@lru_cache(maxsize=1)
def load_model_parameters() -> dict[str, Any]:
data: dict[str, Any] = json.loads(PARAMS_PATH.read_text(encoding="utf-8"))
return data
@lru_cache(maxsize=1)
def load_bundle() -> dict[str, Any]:
"""The bundle manifest: which Pyxel release the data files came from.
Written by scripts/refresh_bundle.py at the repo root, never by hand. The
schema digest lets a test prove the manifest describes the schema that
actually shipped, rather than the one that was current when someone last
remembered to update a version string.
"""
data: dict[str, Any] = json.loads(BUNDLE_PATH.read_text(encoding="utf-8"))
return data
[docs]
def schema_version() -> str:
"""The Pyxel release the bundled schema was generated from, e.g. "3.0.2"."""
return str(load_bundle()["pyxel_version"])
[docs]
def schema_sha256() -> str:
"""Digest of the schema file as shipped, for comparing against the manifest."""
return hashlib.sha256(SCHEMA_PATH.read_bytes()).hexdigest()