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])

clew/buildoptions.py:577

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
lines 587–587schema = MANIFEST_SCHEMAS.get(key)lines 588–588◇ if schema is Nonelines 589–589return valuelines 590–590unknown = sorted(str(k) for k in value if k not in schema.document)lines 591–591◇ if unknownlines 592–597raise 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." )lines 598–598◇ for entry_schema in schema.entrieslines 599–599_checked_entries(key, value, entry_schema)lines 600–600return dict(value)

Flows

_checked_entries

_checked_entries(key: str, document: dict[str, Any], schema: EntrySchema)

clew/buildoptions.py:630

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
lines 640–640entries = document.get(schema.list_key)lines 641–641◇ if entries is Nonelines 642–642returnlines 643–643◇ if not isinstance(entries, list)lines 644–647raise BuildOptionError( f"option {key!r}: {schema.list_key!r} must be a list of entries, got " f"{type(entries).__name__}" )lines 648–648◇ for position, entry in enumerate(entries, start=1)lines 649–649_checked_entry(key, f"{schema.list_key}[{position}]", entry, schema)

Flows

_checked_entry

_checked_entry(key: str, where: str, entry: Any, schema: EntrySchema)

clew/buildoptions.py:660

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
lines 664–664◇ if not isinstance(entry, dict)lines 665–667raise BuildOptionError( f"option {key!r}: {where} must be a mapping, got {type(entry).__name__}" )lines 668–668unknown = sorted(str(k) for k in entry if k not in schema.allowed)lines 669–669◇ if unknownlines 670–675raise 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." )lines 676–676missing = [name for name in schema.required if not entry.get(name)]lines 677–677◇ if missinglines 678–681raise BuildOptionError( f"option {key!r}: {where} is missing required key(s) " f"{', '.join(repr(m) for m in missing)}" )lines 682–682◇ if schema.any_of and not any(entry.get(name) for name in schema.any_of)lines 683–686raise BuildOptionError( f"option {key!r}: {where} declares none of " f"{', '.join(repr(name) for name in schema.any_of)} — it would match nothing" )

Flows

check_manifest_document

check_manifest_document(key: str, value: dict[str, Any])

clew/buildoptions.py:610

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)
Activity · 1 steps
lines 620–620return _checked_document(key, value)

Flows