harvest_plan.py¶
clew/harvest_plan.py
The eleven per-file AST stages of one build, assembled before any of them runs.
active
list[Harvester] clew.harvest_plan.HarvestPlan.active(self)
The stages the shared parse pass should warm.
Called by _current_active, active_repo, adopt, build_or_refresh, cull, ensure_target, invalidate_roots_target, staleness_notices
Calls none
Source · 39 lines
def active(self) -> list[Harvester]:
"""Order is irrelevant to the shared pass — it warms cache rows and emits
nothing — so this is simply "all of them that will run".
A HARVESTER OMITTED HERE STILL WORKS, and that is what makes the omission
expensive rather than loud: it falls back to its own full-tree parse and
produces identical rows, so the only symptom is the build getting slower.
`test_every_harvester_subclass_is_reachable_from_the_plan` enumerates the
package's `Harvester` subclasses instead of trusting this tuple.
@brief The plan's live harvesters.
@version 3
"""
return [
h
for h in (
self.kconfig_gates,
self.ast_symbols,
self.call_edges,
self.callback_edges,
self.locks,
self.threads,
self.shared_key,
self.py_entrypoints,
self.macro_refs,
self.blocking,
self.script_symbols,
self.config_defaults,
self.includes,
self.property_keys,
self.js_symbols,
self.py_docstrings,
self.dispatch,
self.subscribe,
)
if h is not None
]
Activity · 1 steps
Requirements
build_harvest_plan
HarvestPlan clew.harvest_plan.build_harvest_plan(Path|dict|None lock_patterns=None, Path|dict|None thread_patterns=None, Path|dict|None shared_key_patterns=None, Path|dict|None shared_key_wrappers=None, DispatchManifest|None dispatch=None, str dispatch_key="", Path|dict|None mqtt_dispatch=None, dict|None blocking=None)
Build the per-file harvester for every stage this build will run.
Called by _build_stages
Tested by
Calls blocking_harvester, call_site_harvester, callback_harvester, defaults_harvester, dispatch_harvester, docstring_harvester, function_definition_harvester, gate_harvester, includes_harvester, js_symbol_harvester, lock_harvester, main_guard_harvester
Source · 44 lines
def build_harvest_plan(
lock_patterns: Path | dict | None = None,
thread_patterns: Path | dict | None = None,
shared_key_patterns: Path | dict | None = None,
shared_key_wrappers: Path | dict | None = None,
dispatch: DispatchManifest | None = None,
dispatch_key: str = "",
mqtt_dispatch: Path | dict | None = None,
blocking: dict | None = None,
) -> HarvestPlan:
"""Every declaration is resolved HERE, once, and a `DeclarationError` in any of
them now refuses the build before doxygen's output is augmented rather than
part-way down the stage list. That is the right direction for a refusal, and it
is a behaviour change worth naming: the same bad declaration used to fail later.
@brief Resolve every declaration and construct all eleven harvesters.
@version 3
"""
return HarvestPlan(
kconfig_gates=gate_harvester(),
ast_symbols=function_definition_harvester(),
call_edges=call_site_harvester(),
callback_edges=callback_harvester(),
locks=lock_harvester(lock_patterns),
threads=spawn_harvester(thread_patterns),
shared_key=shared_key_harvester(shared_key_patterns, shared_key_wrappers),
py_entrypoints=main_guard_harvester(),
## Constructed with no arguments, exactly as `import_ast_macro_refs` constructs it, so
## the two agree on the (stage, stage_version, extra_key) half of the cache key and the
## stage genuinely finds the warmed row. A harvester built differently here would warm a
## row the stage then misses, and the only symptom would be the cost coming back.
macro_refs=MacroRefHarvester(),
blocking=blocking_harvester(blocking),
js_symbols=js_symbol_harvester(),
script_symbols=script_symbol_harvester(),
config_defaults=defaults_harvester(),
includes=includes_harvester(),
property_keys=property_key_harvester(),
py_docstrings=docstring_harvester(),
dispatch=(dispatch_harvester(dispatch, dispatch_key) if dispatch is not None else None),
subscribe=subscribe_harvester(mqtt_dispatch),
)
Activity · 1 steps
Requirements
warm_harvest_plan
HarvestTally clew.harvest_plan.warm_harvest_plan(Path db_path, Path repo_root, HarvestPlan plan, IndexCache|None cache=None, int jobs=1)
Parse every indexed file once, warming all of the plan's stages.
Source · 20 lines
def warm_harvest_plan(
db_path: Path,
repo_root: Path,
plan: HarvestPlan,
cache: IndexCache | None = None,
jobs: int = 1,
) -> HarvestTally:
"""Opens its own connection because it runs between two stages that each own
theirs, and READS ONLY — the `path` table, to enumerate the file set. Everything
it writes goes to the sidecar cache, never to the index.
@brief Drive the shared parse pass over one build's plan.
@version 3
"""
conn = sqlite3.connect(str(db_path))
try:
return run_shared_parse(conn, repo_root, plan.active(), cache, jobs)
finally:
conn.close()1 more lines, not shown