nvalchemi.hooks.HookRegistryMixin#

class nvalchemi.hooks.HookRegistryMixin[source]#

Mixin providing flat-list hook storage and dispatch.

The host class must provide a step_count attribute. Override _build_context to populate workflow-specific fields.

Set _stage_type on the host class to restrict which stage enum types may be registered. When set, register_hook raises TypeError if hook.stage is not an instance of the declared type(s).

hooks#

Flat list of registered hooks.

Type:

list[Hook]

step_count#

Current step number (must be provided by the engine).

Type:

int

_stage_type#

Accepted stage enum type(s). None disables validation.

Type:

type[Enum] | tuple[type[Enum], …] | None

register_hook(hook, stage=None)[source]#

Register a hook.

Parameters:
  • hook (Hook) – Hook to register.

  • stage (Enum | None) – If provided, assigns hook.stage = stage before validation. This allows stage-agnostic hooks (constructed with stage=None) to receive their stage at registration time.

Raises:
  • ValueError – If hook.frequency is not a positive integer.

  • TypeError – If hook.stage is None after assignment and the hook does not define _runs_on_stage, or if hook.stage is not an instance of the accepted _stage_type declared on the engine and the hook does not define _runs_on_stage (cross-category hooks that manage their own stage dispatch bypass this check).

Return type:

None