dispatch.py¶
clew/dispatch.py
The indirect-dispatch DECLARATION — a repo's own map of its indirections.
empty_manifest
DispatchManifest clew.dispatch.empty_manifest()
An empty manifest, for the (universal, today) undeclared case.
Source · 11 lines
def empty_manifest() -> DispatchManifest:
"""Constructed rather than shared as a module constant: the sections are
mutable lists, and a shared instance is one accidental `.append` away from
leaking one build's declaration into the next.
@brief Build a fresh empty manifest.
@version 1
"""
return DispatchManifest([], [], [], ())
Activity · 1 steps
Requirements
is_empty
bool clew.dispatch.DispatchManifest.is_empty(self)
True when the declaration would produce nothing.
Source · 8 lines
def is_empty(self) -> bool:
"""@brief True when nothing was declared.
@version 1
"""
return not (self.interfaces or self.tables or self.wrappers)
Activity · 1 steps
Requirements
load_dispatch_manifest
DispatchManifest clew.dispatch.load_dispatch_manifest(Path|dict|None source)
Parse a repo's declared indirect-dispatch conventions.
Called by _build_stages, _wrapper_manifest
Tested by 25 tests
test_a_declared_boundary_is_recorded_even_from_a_fuzzy_call_site, test_a_manifest_file_that_is_not_a_mapping_refuses_the_build, test_a_missing_required_endpoint_refuses_the_build, test_a_misspelled_entry_field_refuses_the_build, test_a_misspelled_section_refuses_the_build, test_a_section_that_is_not_a_list_of_mappings_refuses_the_build, test_a_standalone_manifest_file_and_a_declaration_section_share_one_parser, test_a_typod_direction_refuses_instead_of_filing_the_opposite_role, test_ambiguous_handler_name_records_NOTHING_rather_than_guessing, test_ambiguous_or_absent_class_is_skipped_not_guessed, test_boundary_flag_records_the_second_terminus_kind, test_declared_dispatch_table_connects_the_dispatcher_to_its_handlers 13 more
test_declared_interface_binding_continues_the_chain_to_the_implementor, test_declared_key_wrapper_produces_the_dataflow_edge, test_declared_wrapper_direction_selects_the_matcher_list, test_dispatch_is_validated_by_its_own_loader_not_a_second_copy, test_inherited_members_do_not_pair_the_interface_with_itself, test_method_filter_narrows_the_binding, test_no_declaration_writes_nothing_at_all, test_registration_site_is_harvested_but_is_not_itself_a_call_edge, test_shared_key_document_is_none_when_nothing_contributes, test_synthetic_edge_inherits_the_weakest_link_from_a_fuzzy_premise, test_the_declaration_route_reaches_the_stage_and_the_flag_wins, test_the_dispatch_manifest_participates_in_the_stage_cache_key, test_unresolvable_dispatch_via_leaves_the_handlers_unconnected
Calls _document, _entries, _interface_entry, _reject_unknown, _table_entry, _wrapper_entry, declaration_origin, empty_manifest
Source · 34 lines
def load_dispatch_manifest(source: Path | dict | None) -> DispatchManifest:
"""Undeclared is the norm: no repo has written a dispatch declaration yet, so
this returns an empty manifest and the pipeline emits nothing. Anything
malformed RAISES rather than degrading, because a silently-ignored
declaration is indistinguishable from never having written one — including a
misspelled SECTION name, which is the shape that would otherwise slip
through (see `_reject_unknown`).
@brief Load and validate the dispatch declaration.
@version 2
"""
doc = _document(source)
if doc is None:
return empty_manifest()
origin = declaration_origin(source, SECTION_DISPATCH)
_reject_unknown(doc, _DOCUMENT_KEYS, origin)
manifest = DispatchManifest(
[_interface_entry(e, origin) for e in _entries(doc, KEY_INTERFACES, origin)],
[_table_entry(e, origin) for e in _entries(doc, KEY_TABLES, origin)],
[_wrapper_entry(e, origin) for e in _entries(doc, KEY_WRAPPERS, origin)],
tuple(str(p) for p in (doc.get(KEY_ALIAS_PREFIXES) or []) if str(p)),
)
if not manifest.is_empty():
logger.info(
"dispatch: %s declares %d interface binding(s), %d dispatch table(s), "
"%d key wrapper(s)",
origin,
len(manifest.interfaces),
len(manifest.tables),
len(manifest.wrappers),
)
return manifest