50 lines
1.8 KiB
Python
50 lines
1.8 KiB
Python
"""Helpers for writing runtime configs and preprocessing bundles."""
|
|
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
from pathlib import Path
|
|
|
|
from python_app.file_io import atomic_write_json
|
|
from python_app.models.run_config_schema import RunConfigModel
|
|
from python_app.orchestration.preprocess_assets import (
|
|
PREPROCESS_ASSET_NAMES,
|
|
preprocess_asset_model,
|
|
runtime_preprocess_asset_keys,
|
|
)
|
|
from python_app.storage.npz.store import NpzStore
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
class ConfigWriter:
|
|
"""Write runtime artifacts consumed by C++ processes."""
|
|
|
|
def __init__(self, runtime_dir: Path) -> None:
|
|
"""Create writer rooted at runtime directory."""
|
|
self._runtime_dir = runtime_dir
|
|
self._runtime_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
def prepare_preprocess_bundles(
|
|
self,
|
|
store: NpzStore,
|
|
radar_key: str,
|
|
config: RunConfigModel,
|
|
) -> None:
|
|
"""Export selected preprocess sets into runtime bundles and update config paths."""
|
|
for key in PREPROCESS_ASSET_NAMES:
|
|
preprocess_asset_model(config, key).bundle_path = ""
|
|
|
|
for key in runtime_preprocess_asset_keys(config):
|
|
asset = preprocess_asset_model(config, key)
|
|
bundle_path = self._runtime_dir / f"{key}_bundle.bin"
|
|
logger.debug("Exporting preprocess bundle %s (set=%s) -> %s", key, asset.set_name, bundle_path)
|
|
store.export_set_bundle(key, radar_key, asset.set_name, bundle_path)
|
|
asset.bundle_path = str(bundle_path)
|
|
|
|
def write(self, config: RunConfigModel, output_path: Path) -> Path:
|
|
"""Atomically write and sync the run configuration JSON file."""
|
|
atomic_write_json(output_path, config.to_dict(), durable=True)
|
|
logger.debug("Wrote run config to %s", output_path)
|
|
return output_path
|