buildoptions.py¶
clew/buildoptions.py
TIER 1, REACHABLE — one structured `options` argument for an embedding caller.
_checked_document
_checked_document(key: str, value: dict[str, Any])
Source · 24 lines
def _checked_document(key: str, value: dict[str, Any]) -> dict[str, Any]:
"""The DOCUMENT half of the two-level gate. A manifest with no schema here is one whose
own loader refuses unknown keys at both levels (`dispatch`), so it passes through — but
it passes through NAMED, rather than by falling off the end of a lookup, because "no
schema" and "not checked" must not share a code path.
@brief Check an inline manifest's top-level keys.
@return The validated document.
@version 1
"""
schema = MANIFEST_SCHEMAS.get(key)
if schema is None:
return value # dispatch: validated wholly by load_dispatch_manifest
unknown = sorted(str(k) for k in value if k not in schema.document)
if unknown:
raise BuildOptionError(
f"option {key!r} names unknown key(s) {', '.join(repr(k) for k in unknown)} "
f"— allowed: {', '.join(sorted(schema.document))}. Nothing reads an unknown "
f"key, so the build would have used built-in defaults while reporting that "
f"your statement was honoured."
)
for entry_schema in schema.entries:
_checked_entries(key, value, entry_schema)
return dict(value)Activity · 9 steps
Flows
_checked_entries
_checked_entries(key: str, document: dict[str, Any], schema: EntrySchema)
Source · 20 lines
def _checked_entries(key: str, document: dict[str, Any], schema: EntrySchema) -> None:
"""THE QUIET LEVEL, and the whole reason the inline route is validated harder than the
file route. `key_arg_idx` for `key_arg_index` is a valid mapping that every loader reads
as "absent", so the dataflow is keyed off argument 0 and the build reports success —
this repo's recorded example of an entry-level slip. Same family as
`entry.get("name")` returning None and the loader skipping the entry silently.
@brief Check one manifest list's entries.
@version 1
"""
entries = document.get(schema.list_key)
if entries is None:
return
if not isinstance(entries, list):
raise BuildOptionError(
f"option {key!r}: {schema.list_key!r} must be a list of entries, got "
f"{type(entries).__name__}"
)
for position, entry in enumerate(entries, start=1):
_checked_entry(key, f"{schema.list_key}[{position}]", entry, schema)Activity · 7 steps
Flows
_checked_entry
_checked_entry(key: str, where: str, entry: Any, schema: EntrySchema)
Source · 27 lines
def _checked_entry(key: str, where: str, entry: Any, schema: EntrySchema) -> None:
"""@brief Check one manifest entry's keys against the allowed and required sets.
@version 1
"""
if not isinstance(entry, dict):
raise BuildOptionError(
f"option {key!r}: {where} must be a mapping, got {type(entry).__name__}"
)
unknown = sorted(str(k) for k in entry if k not in schema.allowed)
if unknown:
raise BuildOptionError(
f"option {key!r}: {where} names unknown key(s) "
f"{', '.join(repr(k) for k in unknown)} — allowed: "
f"{', '.join(sorted(schema.allowed))}. A misspelled field reads as an absent "
f"one, so it would silently take its default."
)
missing = [name for name in schema.required if not entry.get(name)]
if missing:
raise BuildOptionError(
f"option {key!r}: {where} is missing required key(s) "
f"{', '.join(repr(m) for m in missing)}"
)
if schema.any_of and not any(entry.get(name) for name in schema.any_of):
raise BuildOptionError(
f"option {key!r}: {where} declares none of "
f"{', '.join(repr(name) for name in schema.any_of)} — it would match nothing"
)Activity · 10 steps
Flows
check_manifest_document
check_manifest_document(key: str, value: dict[str, Any])
Source · 11 lines
def check_manifest_document(key: str, value: dict[str, Any]) -> dict[str, Any]:
"""THE IN-TREE `.clew.yaml` CALLS THIS TOO (R5-CFG F1, 2.0.0). Before, only tier 1 (`--declare`,
MCP `options`) reached `MANIFEST_SCHEMAS`; the repository's own file — the human's main way to
configure clew — went straight to loaders that read `entry.get(key, default)`, so the same
misspelling was refused on one route and silently defaulted on the other.
@brief Validate a manifest document against MANIFEST_SCHEMAS.
@return The document.
@version 1
"""
return _checked_document(key, value)