loader
loader ¤
Registration helpers + YAML/dict loaders for lambda rules.
A lambda rule lives in two places once registered:
- :data:
ts_shape.eventlog.taxonomy.REGISTRY— the :class:~ts_shape.eventlog.taxonomy.LabelRulemapping that :func:~ts_shape.eventlog.to_event_logconsults. - :data:
ts_shape.eventlog.archetypes.ARCHETYPE_BY_METHOD— the archetype classification that the coverage tests use to enforcestandard_attrscompleteness.
Both mutations happen through :func:register_lambda_rule. The
coverage test test_no_orphan_registry_entries is configured to
exempt entries whose class name starts with Lambda, so registered
lambda rules do not need a real Python class on disk.
register_lambda_rule ¤
register_lambda_rule(spec: RuleSpec) -> LambdaDetector
Register spec in REGISTRY + ARCHETYPE_BY_METHOD; return runnable detector.
The trigger expression is compiled here, so a bad expression fails at registration rather than at the first evaluation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
spec
|
RuleSpec
|
The rule to register. |
required |
Returns:
| Type | Description |
|---|---|
LambdaDetector
|
The runnable :class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the spec is malformed, the expression does not compile
(:class: |
unregister_lambda_rule ¤
unregister_lambda_rule(
class_name: str, method_name: str
) -> None
Remove a rule previously installed by :func:register_lambda_rule.
Used by tests to keep the global REGISTRY clean between cases. No-op if the rule was not registered. Deprecated class / method names resolve to their current names, as in the registry lookup.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
class_name
|
str
|
The rule's class name. |
required |
method_name
|
str
|
The rule's method name. |
required |
load_dicts ¤
load_dicts(
entries: Iterable[Mapping[str, Any]],
) -> list[LambdaDetector]
Compile and register an iterable of dict rules, all or nothing.
Every rule is validated and its trigger compiled before any is registered; if one fails, the rules registered by this call are removed again and the error is raised.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
entries
|
Iterable[Mapping[str, Any]]
|
Rule mappings with the :class: |
required |
Returns:
| Name | Type | Description |
|---|---|---|
One |
list[LambdaDetector]
|
class: |
Raises:
| Type | Description |
|---|---|
ValueError
|
For a malformed rule, a duplicate registration or an
expression that does not compile (:class: |
load_yaml ¤
load_yaml(path: str | Path) -> list[LambdaDetector]
Load and register every rule under a YAML file's rules: key.
YAML is imported lazily so :mod:ts_shape.eventlog does not gain a
hard runtime dependency on PyYAML for users who only use built-in
detectors. Install ts-shape[yaml] to enable this loader, or use
:func:load_dicts with a hand-built list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str | Path
|
Path to a YAML file with a top-level |
required |
Returns:
| Name | Type | Description |
|---|---|---|
One |
list[LambdaDetector]
|
class: |
Raises:
| Type | Description |
|---|---|
ImportError
|
When PyYAML is not installed. |
ValueError
|
When the file has no |