mirror of
https://github.com/lllin000/PaperForge.git
synced 2026-07-22 17:00:23 +00:00
Milestone v2.1: Contract-Driven Architecture & Engineering Hardening - Stop the Bleeding: version sync checker, PyYAML hardening, install docs unification - Contract Layer: PFResult/PFError dataclasses, ErrorCode enum, --json wrapping - Service Extraction: sync.py decomposed into 3 adapters + SyncService - State Machine: PdfStatus/OcrStatus/Lifecycle enums, transitions, field registry - Setup Modularization: setup_wizard.py decomposed into 6 classes 173 tests passing, 0 regressions.
35 lines
1,002 B
Python
35 lines
1,002 B
Python
"""Field registry: schema definitions for all field-carrying structures."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from pathlib import Path
|
|
|
|
|
|
def load_field_registry(path: Path | None = None) -> dict:
|
|
"""Load field registry from YAML file.
|
|
|
|
Returns nested dict: {owner: {field: {type, required, public, description}}}
|
|
"""
|
|
import yaml
|
|
|
|
if path is None:
|
|
path = Path(__file__).resolve().parent / "field_registry.yaml"
|
|
|
|
if not path.exists():
|
|
return {}
|
|
|
|
with open(path, "r", encoding="utf-8") as f:
|
|
data = yaml.safe_load(f)
|
|
|
|
return data if isinstance(data, dict) else {}
|
|
|
|
|
|
def get_owner_fields(registry: dict, owner: str) -> dict:
|
|
"""Get all field definitions for a given owner."""
|
|
return registry.get(owner, {})
|
|
|
|
|
|
def get_field_info(registry: dict, owner: str, field_name: str) -> dict | None:
|
|
"""Get metadata for a specific field in an owner."""
|
|
owner_fields = get_owner_fields(registry, owner)
|
|
return owner_fields.get(field_name)
|