Files
docs/hexa/wiki/02_components/index.html

1255 lines
33 KiB
HTML
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<!doctype html>
<html lang="en" class="no-js">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="prev" href="../01_overview/">
<link rel="next" href="../03_use_cases/01_yaml_first/">
<link rel="icon" href="../assets/images/favicon.png">
<meta name="generator" content="mkdocs-1.6.1, mkdocs-material-9.6.23">
<title>Core Components - Hexa Documentation</title>
<link rel="stylesheet" href="../assets/stylesheets/main.84d31ad4.min.css">
<link rel="stylesheet" href="../assets/stylesheets/palette.06af60db.min.css">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Roboto:300,300i,400,400i,700,700i%7CJetBrains+Mono:400,400i,700,700i&display=fallback">
<style>:root{--md-text-font:"Roboto";--md-code-font:"JetBrains Mono"}</style>
<link rel="stylesheet" href="https://unpkg.com/dracula-prism/dist/css/dracula-prism.css">
<script>__md_scope=new URL("..",location),__md_hash=e=>[...e].reduce(((e,_)=>(e<<5)-e+_.charCodeAt(0)),0),__md_get=(e,_=localStorage,t=__md_scope)=>JSON.parse(_.getItem(t.pathname+"."+e)),__md_set=(e,_,t=localStorage,a=__md_scope)=>{try{t.setItem(a.pathname+"."+e,JSON.stringify(_))}catch(e){}}</script>
</head>
<body dir="ltr" data-md-color-scheme="slate" data-md-color-primary="blue-grey" data-md-color-accent="teal">
<input class="md-toggle" data-md-toggle="drawer" type="checkbox" id="__drawer" autocomplete="off">
<input class="md-toggle" data-md-toggle="search" type="checkbox" id="__search" autocomplete="off">
<label class="md-overlay" for="__drawer"></label>
<div data-md-component="skip">
<a href="#core-components" class="md-skip">
Skip to content
</a>
</div>
<div data-md-component="announce">
</div>
<header class="md-header" data-md-component="header">
<nav class="md-header__inner md-grid" aria-label="Header">
<a href=".." title="Hexa Documentation" class="md-header__button md-logo" aria-label="Hexa Documentation" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M10.25 2c.19 0 .36.11.44.26l2.22 3.96.09.28-.09.28-2.22 3.96c-.08.15-.25.26-.44.26h-4.5c-.19 0-.36-.11-.44-.26L3.09 6.78 3 6.5l.09-.28 2.22-3.96c.08-.15.25-.26.44-.26zm0 11c.19 0 .36.11.44.26l2.22 3.96.09.28-.09.28-2.22 3.96c-.08.15-.25.26-.44.26h-4.5c-.19 0-.36-.11-.44-.26l-2.22-3.96L3 17.5l.09-.28 2.22-3.96c.08-.15.25-.26.44-.26zm9.25-5.5c.19 0 .36.11.44.26l2.22 3.96.09.28-.09.28-2.22 3.96c-.08.15-.25.26-.44.26H15c-.19 0-.36-.11-.44-.26l-2.22-3.96-.09-.28.09-.28 2.22-3.96c.08-.15.25-.26.44-.26z"/></svg>
</a>
<label class="md-header__button md-icon" for="__drawer">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M3 6h18v2H3zm0 5h18v2H3zm0 5h18v2H3z"/></svg>
</label>
<div class="md-header__title" data-md-component="header-title">
<div class="md-header__ellipsis">
<div class="md-header__topic">
<span class="md-ellipsis">
Hexa Documentation
</span>
</div>
<div class="md-header__topic" data-md-component="header-topic">
<span class="md-ellipsis">
Core Components
</span>
</div>
</div>
</div>
<label class="md-header__button md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
</label>
<div class="md-search" data-md-component="search" role="dialog">
<label class="md-search__overlay" for="__search"></label>
<div class="md-search__inner" role="search">
<form class="md-search__form" name="search">
<input type="text" class="md-search__input" name="query" aria-label="Search" placeholder="Search" autocapitalize="off" autocorrect="off" autocomplete="off" spellcheck="false" data-md-component="search-query" required>
<label class="md-search__icon md-icon" for="__search">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M9.5 3A6.5 6.5 0 0 1 16 9.5c0 1.61-.59 3.09-1.56 4.23l.27.27h.79l5 5-1.5 1.5-5-5v-.79l-.27-.27A6.52 6.52 0 0 1 9.5 16 6.5 6.5 0 0 1 3 9.5 6.5 6.5 0 0 1 9.5 3m0 2C7 5 5 7 5 9.5S7 14 9.5 14 14 12 14 9.5 12 5 9.5 5"/></svg>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11z"/></svg>
</label>
<nav class="md-search__options" aria-label="Search">
<a href="javascript:void(0)" class="md-search__icon md-icon" title="Share" aria-label="Share" data-clipboard data-clipboard-text="" data-md-component="search-share" tabindex="-1">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M18 16.08c-.76 0-1.44.3-1.96.77L8.91 12.7c.05-.23.09-.46.09-.7s-.04-.47-.09-.7l7.05-4.11c.54.5 1.25.81 2.04.81a3 3 0 0 0 3-3 3 3 0 0 0-3-3 3 3 0 0 0-3 3c0 .24.04.47.09.7L8.04 9.81C7.5 9.31 6.79 9 6 9a3 3 0 0 0-3 3 3 3 0 0 0 3 3c.79 0 1.5-.31 2.04-.81l7.12 4.15c-.05.21-.08.43-.08.66 0 1.61 1.31 2.91 2.92 2.91s2.92-1.3 2.92-2.91A2.92 2.92 0 0 0 18 16.08"/></svg>
</a>
<button type="reset" class="md-search__icon md-icon" title="Clear" aria-label="Clear" tabindex="-1">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M19 6.41 17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/></svg>
</button>
</nav>
<div class="md-search__suggest" data-md-component="search-suggest"></div>
</form>
<div class="md-search__output">
<div class="md-search__scrollwrap" tabindex="0" data-md-scrollfix>
<div class="md-search-result" data-md-component="search-result">
<div class="md-search-result__meta">
Initializing search
</div>
<ol class="md-search-result__list" role="presentation"></ol>
</div>
</div>
</div>
</div>
</div>
</nav>
</header>
<div class="md-container" data-md-component="container">
<nav class="md-tabs" aria-label="Tabs" data-md-component="tabs">
<div class="md-grid">
<ul class="md-tabs__list">
<li class="md-tabs__item">
<a href=".." class="md-tabs__link">
Home
</a>
</li>
<li class="md-tabs__item">
<a href="../01_overview/" class="md-tabs__link">
Overview
</a>
</li>
<li class="md-tabs__item md-tabs__item--active">
<a href="./" class="md-tabs__link">
Core Components
</a>
</li>
<li class="md-tabs__item">
<a href="../03_use_cases/01_yaml_first/" class="md-tabs__link">
Use Cases
</a>
</li>
<li class="md-tabs__item">
<a href="../04_design/" class="md-tabs__link">
Design
</a>
</li>
<li class="md-tabs__item">
<a href="../05_philosophy/" class="md-tabs__link">
Philosophy
</a>
</li>
<li class="md-tabs__item">
<a href="../06_best_practices/" class="md-tabs__link">
Best Practices
</a>
</li>
<li class="md-tabs__item">
<a href="../07_error_handling/" class="md-tabs__link">
Error Handling
</a>
</li>
<li class="md-tabs__item">
<a href="../08_testing_example/" class="md-tabs__link">
Testing
</a>
</li>
</ul>
</div>
</nav>
<main class="md-main" data-md-component="main">
<div class="md-main__inner md-grid">
<div class="md-sidebar md-sidebar--primary" data-md-component="sidebar" data-md-type="navigation" >
<div class="md-sidebar__scrollwrap">
<div class="md-sidebar__inner">
<nav class="md-nav md-nav--primary md-nav--lifted md-nav--integrated" aria-label="Navigation" data-md-level="0">
<label class="md-nav__title" for="__drawer">
<a href=".." title="Hexa Documentation" class="md-nav__button md-logo" aria-label="Hexa Documentation" data-md-component="logo">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M10.25 2c.19 0 .36.11.44.26l2.22 3.96.09.28-.09.28-2.22 3.96c-.08.15-.25.26-.44.26h-4.5c-.19 0-.36-.11-.44-.26L3.09 6.78 3 6.5l.09-.28 2.22-3.96c.08-.15.25-.26.44-.26zm0 11c.19 0 .36.11.44.26l2.22 3.96.09.28-.09.28-2.22 3.96c-.08.15-.25.26-.44.26h-4.5c-.19 0-.36-.11-.44-.26l-2.22-3.96L3 17.5l.09-.28 2.22-3.96c.08-.15.25-.26.44-.26zm9.25-5.5c.19 0 .36.11.44.26l2.22 3.96.09.28-.09.28-2.22 3.96c-.08.15-.25.26-.44.26H15c-.19 0-.36-.11-.44-.26l-2.22-3.96-.09-.28.09-.28 2.22-3.96c.08-.15.25-.26.44-.26z"/></svg>
</a>
Hexa Documentation
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href=".." class="md-nav__link">
<span class="md-ellipsis">
Home
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../01_overview/" class="md-nav__link">
<span class="md-ellipsis">
Overview
</span>
</a>
</li>
<li class="md-nav__item md-nav__item--active">
<input class="md-nav__toggle md-toggle" type="checkbox" id="__toc">
<label class="md-nav__link md-nav__link--active" for="__toc">
<span class="md-ellipsis">
Core Components
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<a href="./" class="md-nav__link md-nav__link--active">
<span class="md-ellipsis">
Core Components
</span>
</a>
<nav class="md-nav md-nav--secondary" aria-label="Table of contents">
<label class="md-nav__title" for="__toc">
<span class="md-nav__icon md-icon"></span>
Table of contents
</label>
<ul class="md-nav__list" data-md-component="toc" data-md-scrollfix>
<li class="md-nav__item">
<a href="#1-the-shared-model-portnode-and-methodspec" class="md-nav__link">
<span class="md-ellipsis">
1. The Shared Model — PortNode and MethodSpec
</span>
</a>
<nav class="md-nav" aria-label="1. The Shared Model — PortNode and MethodSpec">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#11-portnode" class="md-nav__link">
<span class="md-ellipsis">
1.1 PortNode
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#12-methodspec" class="md-nav__link">
<span class="md-ellipsis">
1.2 MethodSpec
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#13-configvalue" class="md-nav__link">
<span class="md-ellipsis">
1.3 ConfigValue
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#2-converters-yaml-abc" class="md-nav__link">
<span class="md-ellipsis">
2. Converters — YAML ⇄ ABC
</span>
</a>
<nav class="md-nav" aria-label="2. Converters — YAML ⇄ ABC">
<ul class="md-nav__list">
<li class="md-nav__item">
<a href="#21-parse_yamlpath-portnode" class="md-nav__link">
<span class="md-ellipsis">
2.1 parse_yaml(path) -&gt; PortNode
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#22-generate_abcnode-out_pathnone-str" class="md-nav__link">
<span class="md-ellipsis">
2.2 generate_abc(node, out_path=None) -&gt; str
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#23-parse_abcmodule_or_path-portnode" class="md-nav__link">
<span class="md-ellipsis">
2.3 parse_abc(module_or_path) -&gt; PortNode
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#24-generate_yamlnode-out_pathnone-str" class="md-nav__link">
<span class="md-ellipsis">
2.4 generate_yaml(node, out_path=None) -&gt; str
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="#3-verification-check_matchesa-b" class="md-nav__link">
<span class="md-ellipsis">
3. Verification — check_matches(a, b)
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#4-container-build" class="md-nav__link">
<span class="md-ellipsis">
4. Container — build
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#5-cli" class="md-nav__link">
<span class="md-ellipsis">
5. CLI
</span>
</a>
</li>
<li class="md-nav__item">
<a href="#related" class="md-nav__link">
<span class="md-ellipsis">
Related
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle md-toggle--indeterminate" type="checkbox" id="__nav_4" >
<label class="md-nav__link" for="__nav_4" id="__nav_4_label" tabindex="0">
<span class="md-ellipsis">
Use Cases
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="1" aria-labelledby="__nav_4_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_4">
<span class="md-nav__icon md-icon"></span>
Use Cases
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle md-toggle--indeterminate" type="checkbox" id="__nav_4_1" >
<label class="md-nav__link" for="__nav_4_1" id="__nav_4_1_label" tabindex="0">
<span class="md-ellipsis">
Contract Authoring
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_4_1_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_4_1">
<span class="md-nav__icon md-icon"></span>
Contract Authoring
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../03_use_cases/01_yaml_first/" class="md-nav__link">
<span class="md-ellipsis">
YAML First
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../03_use_cases/02_abc_first/" class="md-nav__link">
<span class="md-ellipsis">
ABC First
</span>
</a>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item md-nav__item--nested">
<input class="md-nav__toggle md-toggle md-toggle--indeterminate" type="checkbox" id="__nav_4_2" >
<label class="md-nav__link" for="__nav_4_2" id="__nav_4_2_label" tabindex="0">
<span class="md-ellipsis">
Wiring
</span>
<span class="md-nav__icon md-icon"></span>
</label>
<nav class="md-nav" data-md-level="2" aria-labelledby="__nav_4_2_label" aria-expanded="false">
<label class="md-nav__title" for="__nav_4_2">
<span class="md-nav__icon md-icon"></span>
Wiring
</label>
<ul class="md-nav__list" data-md-scrollfix>
<li class="md-nav__item">
<a href="../03_use_cases/03_wiring_runtime/" class="md-nav__link">
<span class="md-ellipsis">
Wiring & Runtime
</span>
</a>
</li>
</ul>
</nav>
</li>
</ul>
</nav>
</li>
<li class="md-nav__item">
<a href="../04_design/" class="md-nav__link">
<span class="md-ellipsis">
Design
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../05_philosophy/" class="md-nav__link">
<span class="md-ellipsis">
Philosophy
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../06_best_practices/" class="md-nav__link">
<span class="md-ellipsis">
Best Practices
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../07_error_handling/" class="md-nav__link">
<span class="md-ellipsis">
Error Handling
</span>
</a>
</li>
<li class="md-nav__item">
<a href="../08_testing_example/" class="md-nav__link">
<span class="md-ellipsis">
Testing
</span>
</a>
</li>
</ul>
</nav>
</div>
</div>
</div>
<div class="md-content" data-md-component="content">
<article class="md-content__inner md-typeset">
<h1 id="core-components">Core Components<a class="headerlink" href="#core-components" title="Permanent link">&para;</a></h1>
<p>A validated reference to the public API of <code>hexa</code> (package root exports from <code>hexa/__init__.py</code>). Signatures match the code exactly. For runnable recipes see the <a href="../03_use_cases/01_yaml_first/">Use Cases</a>. Exact parameter contracts live in the API reference under <code>docs/lib/</code> — this page is usage-level.</p>
<hr />
<h2 id="1-the-shared-model-portnode-and-methodspec">1. The Shared Model — <code>PortNode</code> and <code>MethodSpec</code><a class="headerlink" href="#1-the-shared-model-portnode-and-methodspec" title="Permanent link">&para;</a></h2>
<p>Every parser and generator serializes through one neutral tree. It is not tied to any sample — <strong>any</strong> port tree fits.</p>
<h3 id="11-portnode">1.1 <code>PortNode</code><a class="headerlink" href="#11-portnode" title="Permanent link">&para;</a></h3>
<p>A node in a hexa port tree. Three kinds:</p>
<table>
<thead>
<tr>
<th>Kind</th>
<th>Meaning</th>
<th>Example</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>parent</code></td>
<td>The root of the tree</td>
<td><code>ExtractionPipeline</code></td>
</tr>
<tr>
<td><code>port</code></td>
<td>Has nested port slots (children)</td>
<td><code>TransactionParserPort</code></td>
</tr>
<tr>
<td><code>leaf</code></td>
<td>No children</td>
<td><code>NumberPort</code></td>
</tr>
</tbody>
</table>
<p>Fields:</p>
<table>
<thead>
<tr>
<th>Field</th>
<th>Type</th>
<th>Meaning</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>name</code></td>
<td><code>str</code></td>
<td>Slot name, e.g. <code>"parser"</code>, <code>"amount_balance"</code></td>
</tr>
<tr>
<td><code>port_cls</code></td>
<td><code>str</code></td>
<td>ABC class name that gives this port its shape</td>
</tr>
<tr>
<td><code>kind</code></td>
<td><code>str</code></td>
<td><code>"leaf"</code> | <code>"port"</code> | <code>"parent"</code></td>
</tr>
<tr>
<td><code>attributes</code></td>
<td><code>dict[str, ConfigValue]</code></td>
<td><code>name → type_expr</code> for scalars, or a nested dict of sub-attributes for grouped values</td>
</tr>
<tr>
<td><code>children</code></td>
<td><code>list[PortNode]</code></td>
<td>Nested port slots</td>
</tr>
<tr>
<td><code>methods</code></td>
<td><code>dict[str, MethodSpec]</code></td>
<td>Abstract methods keyed by method name</td>
</tr>
</tbody>
</table>
<p>Tree helpers (used internally and handy for inspection):</p>
<ul>
<li><code>node.find(name) -&gt; PortNode | None</code> — direct child by slot name.</li>
<li><code>node.walk() -&gt; list[PortNode]</code> — all nodes, depth-first, self first.</li>
<li><code>node.diff(other, path="") -&gt; list[str]</code> — human-readable difference strings; empty list means equal.</li>
</ul>
<h3 id="12-methodspec">1.2 <code>MethodSpec</code><a class="headerlink" href="#12-methodspec" title="Permanent link">&para;</a></h3>
<p>Specification of a single abstract method: <code>name</code>, positional <code>args: list[str]</code>, and keyword-only <code>kwargs: dict[str, str]</code> (name → type expression). Supports equality (<code>==</code>/<code>!=</code>).</p>
<h3 id="13-configvalue">1.3 <code>ConfigValue</code><a class="headerlink" href="#13-configvalue" title="Permanent link">&para;</a></h3>
<p><code>str | NestedConfig</code>, where <code>NestedConfig = dict[str, ConfigValue]</code>. An attribute is either a scalar type expression (e.g. <code>"str"</code>) or a nested structure of sub-attributes. Nesting is recursive.</p>
<hr />
<h2 id="2-converters-yaml-abc">2. Converters — YAML ⇄ ABC<a class="headerlink" href="#2-converters-yaml-abc" title="Permanent link">&para;</a></h2>
<p>All converters are <strong>pure</strong> (they operate on the model) and <strong>optional</strong>: you never have to touch them if you hand-write a single representation.</p>
<h3 id="21-parse_yamlpath-portnode">2.1 <code>parse_yaml(path) -&gt; PortNode</code><a class="headerlink" href="#21-parse_yamlpath-portnode" title="Permanent link">&para;</a></h3>
<p>Parses a hexa YAML spec into a <code>PortNode</code> tree. The grammar uses three member kinds:</p>
<ul>
<li><strong>attribute</strong><code>name: type</code> scalar (e.g. <code>source_type: str</code>)</li>
<li><strong>nested struct</strong><code>name:</code> mapping of sub-attributes (e.g. <code>source:</code>)</li>
<li><strong>port</strong><code>name:</code> mapping whose single key is a class whose value is a body (e.g. <code>ingest: IngestPort: ...</code>)</li>
</ul>
<p>Disambiguation rule: a mapping with <strong>exactly one key whose value is a non-scalar body</strong> is a port; any other mapping is a nested struct of attributes. Raises <code>ValueError</code> on structural errors (see <a href="../07_error_handling/">Error Handling</a>).</p>
<h3 id="22-generate_abcnode-out_pathnone-str">2.2 <code>generate_abc(node, out_path=None) -&gt; str</code><a class="headerlink" href="#22-generate_abcnode-out_pathnone-str" title="Permanent link">&para;</a></h3>
<p>Generates <code>_abc.py</code> source from a <code>PortNode</code> tree. Emits <code>class X(ABC)</code> per node, synthesized <code>@dataclass</code>es for nested structs, port-slot annotations, and <code>@abstractmethod</code> stubs. Deterministic (walk order) so output is idempotent. When <code>out_path</code> is given the source is also written there; the source string is always returned.</p>
<h3 id="23-parse_abcmodule_or_path-portnode">2.3 <code>parse_abc(module_or_path) -&gt; PortNode</code><a class="headerlink" href="#23-parse_abcmodule_or_path-portnode" title="Permanent link">&para;</a></h3>
<p>Reflects an ABC Python module into a <code>PortNode</code> tree. Accepts a <code>.py</code> file path, a module import string, or an already-loaded module. ABC classes become nodes; a <code>@dataclass</code> annotation on a port expands into a nested <code>attributes</code> entry. The root is auto-detected (the class not referenced as any other slot, preferring names containing <code>Pipeline</code>/<code>Root</code>/<code>Parent</code>).</p>
<h3 id="24-generate_yamlnode-out_pathnone-str">2.4 <code>generate_yaml(node, out_path=None) -&gt; str</code><a class="headerlink" href="#24-generate_yamlnode-out_pathnone-str" title="Permanent link">&para;</a></h3>
<p>Generates a YAML spec (nested mapping form) from a <code>PortNode</code> tree — the reverse of <code>generate_abc</code>. A deferred/empty slot renders as <code>slot: Class: ...</code>.</p>
<hr />
<h2 id="3-verification-check_matchesa-b">3. Verification — <code>check_matches(a, b)</code><a class="headerlink" href="#3-verification-check_matchesa-b" title="Permanent link">&para;</a></h2>
<p><code>check_matches(path_a, path_b) -&gt; bool | list[str]</code> parses two representations (one <code>.yaml</code>/<code>.yml</code> and one <code>.py</code>, either direction) and compares the trees with <code>PortNode.diff</code>. Returns <code>True</code> when they describe the same tree, otherwise a list of human-readable difference strings. Inequality checks cover <code>port_cls</code>, <code>kind</code>, attributes (including nested structs), methods (args/kwargs), and children.</p>
<hr />
<h2 id="4-container-build">4. Container — <code>build</code><a class="headerlink" href="#4-container-build" title="Permanent link">&para;</a></h2>
<p><code>build(cls, *, instances=None, config=None) -&gt; T</code> recursively instantiates the port tree implied by a root class's annotations.</p>
<p>Algorithm:</p>
<ol>
<li>Merge <code>__annotations__</code> across the MRO (reverse order) so inherited slot annotations are visible.</li>
<li>Instantiate the parent class (<code>cls()</code>; if that raises <code>TypeError</code>, retry passing <code>None</code> for every <code>__init__</code> parameter after <code>self</code>).</li>
<li>For each annotation:</li>
<li>A name in <code>instances</code> wins — the provided object is <code>setattr</code>ed verbatim, never reconstructed.</li>
<li>Builtin / <code>typing</code> / PEP 604-union types are <strong>config fields</strong> — applied from <code>config</code> by name.</li>
<li>Abstract classes are skipped (but take a <code>config</code> value when provided).</li>
<li>Any other concrete type is a <strong>port slot</strong><code>build</code> recurses and the child is <code>setattr</code>ed onto the parent.</li>
<li>Config defaults: any annotated attribute still unset is defaulted to its <code>config</code> value (or <code>None</code>) so methods can safely reference it.</li>
</ol>
<blockquote>
<p>Runtime values (repos, handlers, clients) go in <code>instances=</code>; plain config values go in <code>config=</code>. Both propagate <strong>by name across the whole tree</strong>.</p>
</blockquote>
<hr />
<h2 id="5-cli">5. CLI<a class="headerlink" href="#5-cli" title="Permanent link">&para;</a></h2>
<table>
<thead>
<tr>
<th>Command</th>
<th>Behavior</th>
</tr>
</thead>
<tbody>
<tr>
<td><code>hexa parse-yaml PATH</code></td>
<td>Print the parsed <code>PortNode</code> tree.</td>
</tr>
<tr>
<td><code>hexa generate-abc PATH [--out FILE]</code></td>
<td>Emit ABC source from a YAML spec.</td>
</tr>
<tr>
<td><code>hexa parse-abc PATH</code></td>
<td>Print the tree reflected from an ABC module.</td>
</tr>
<tr>
<td><code>hexa generate-yaml PATH [--out FILE]</code></td>
<td>Emit a YAML spec from an ABC module.</td>
</tr>
<tr>
<td><code>hexa check PATH_A PATH_B</code></td>
<td>Print <code>Matches.</code>/<code>Differences found:</code> and exit 0/1.</td>
</tr>
</tbody>
</table>
<p>Errors print <code>Error: &lt;message&gt;</code> to stderr and exit 1.</p>
<hr />
<h2 id="related">Related<a class="headerlink" href="#related" title="Permanent link">&para;</a></h2>
<ul>
<li><a href="../03_use_cases/01_yaml_first/">01 YAML first</a> · <a href="../03_use_cases/03_wiring_runtime/">03 Wiring &amp; runtime</a> · <a href="../01_overview/">Overview</a></li>
</ul>
</article>
</div>
<script>var tabs=__md_get("__tabs");if(Array.isArray(tabs))e:for(var set of document.querySelectorAll(".tabbed-set")){var labels=set.querySelector(".tabbed-labels");for(var tab of tabs)for(var label of labels.getElementsByTagName("label"))if(label.innerText.trim()===tab){var input=document.getElementById(label.htmlFor);input.checked=!0;continue e}}</script>
<script>var target=document.getElementById(location.hash.slice(1));target&&target.name&&(target.checked=target.name.startsWith("__tabbed_"))</script>
</div>
<button type="button" class="md-top md-icon" data-md-component="top" hidden>
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M13 20h-2V8l-5.5 5.5-1.42-1.42L12 4.16l7.92 7.92-1.42 1.42L13 8z"/></svg>
Back to top
</button>
</main>
<footer class="md-footer">
<nav class="md-footer__inner md-grid" aria-label="Footer" >
<a href="../01_overview/" class="md-footer__link md-footer__link--prev" aria-label="Previous: Overview">
<div class="md-footer__button md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M20 11v2H8l5.5 5.5-1.42 1.42L4.16 12l7.92-7.92L13.5 5.5 8 11z"/></svg>
</div>
<div class="md-footer__title">
<span class="md-footer__direction">
Previous
</span>
<div class="md-ellipsis">
Overview
</div>
</div>
</a>
<a href="../03_use_cases/01_yaml_first/" class="md-footer__link md-footer__link--next" aria-label="Next: YAML First">
<div class="md-footer__title">
<span class="md-footer__direction">
Next
</span>
<div class="md-ellipsis">
YAML First
</div>
</div>
<div class="md-footer__button md-icon">
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path d="M4 11v2h12l-5.5 5.5 1.42 1.42L19.84 12l-7.92-7.92L10.5 5.5 16 11z"/></svg>
</div>
</a>
</nav>
<div class="md-footer-meta md-typeset">
<div class="md-footer-meta__inner md-grid">
<div class="md-copyright">
Made with
<a href="https://squidfunk.github.io/mkdocs-material/" target="_blank" rel="noopener">
Material for MkDocs
</a>
</div>
</div>
</div>
</footer>
</div>
<div class="md-dialog" data-md-component="dialog">
<div class="md-dialog__inner md-typeset"></div>
</div>
<script id="__config" type="application/json">{"base": "..", "features": ["navigation.tabs", "navigation.expand", "navigation.sections", "navigation.footer", "navigation.top", "navigation.instant", "toc.integrate", "content.code.annotate", "content.code.copy", "content.code.select", "content.code.line_numbers", "content.tabs.link", "content.tooltips", "content.action.edit", "search.suggest", "search.highlight", "search.share", "header.autohide", "announce.dismiss", "footer.social"], "search": "../assets/javascripts/workers/search.973d3a69.min.js", "tags": null, "translations": {"clipboard.copied": "Copied to clipboard", "clipboard.copy": "Copy to clipboard", "search.result.more.one": "1 more on this page", "search.result.more.other": "# more on this page", "search.result.none": "No matching documents", "search.result.one": "1 matching document", "search.result.other": "# matching documents", "search.result.placeholder": "Type to start searching", "search.result.term.missing": "Missing", "select.version": "Select version"}, "version": null}</script>
<script src="../assets/javascripts/bundle.f55a23d4.min.js"></script>
</body>
</html>