|
1 | | -"""Vetted step library, self-registering via the `@step` decorator. |
| 1 | +"""Vetted step library, assembled explicitly when a registry is requested. |
2 | 2 |
|
3 | | -Importing this package imports every step module for its registration side |
4 | | -effects (each `@step` / `register_step` records a `StepSpec`); |
5 | | -`register_builtin_steps` flushes the collected specs into a `StepRegistry`. |
6 | | -There is no central `add(StepSpec(...))` block to keep in sync — a step's name, |
7 | | -metadata and handler live together at its definition (see doc/architecture/CODE_TOUR.md §5). |
| 3 | +Each module still keeps its step name, metadata and handler together with |
| 4 | +`@step` / `register_step`. Importing this package alone is inert; only |
| 5 | +`register_builtin_steps` loads the vetted modules and fills a `StepRegistry`. |
| 6 | +This keeps application and SDK imports from loading every workflow effect. |
8 | 7 | """ |
9 | 8 |
|
10 | 9 | from __future__ import annotations |
11 | 10 |
|
| 11 | +from importlib import import_module |
| 12 | + |
12 | 13 | from ..registry import StepRegistry |
13 | 14 | from . import _common |
14 | 15 |
|
15 | | -# side-effect imports: each module registers its steps into the collection. |
16 | | -from . import ( # noqa: F401,E402 |
17 | | - workspace, |
18 | | - review, |
19 | | - report, |
20 | | - pr, |
21 | | - issue, |
22 | | - profile, |
23 | | - rebase_v3, |
24 | | - rebase_knowledge, |
| 16 | +_BUILTIN_MODULES = ( |
| 17 | + "workspace", "review", "report", "pr", "issue", "profile", |
| 18 | + "rebase_v3", "rebase_knowledge", |
25 | 19 | ) |
26 | 20 |
|
27 | 21 |
|
28 | 22 | def register_builtin_steps(registry: StepRegistry) -> StepRegistry: |
29 | | - """Flush every step collected by import side effects into `registry` and |
30 | | - return it. Called once at startup, after this package's module imports have |
31 | | - populated the collection; the registry then holds the full vetted library.""" |
| 23 | + """Load the vetted modules and install their collected specs into `registry`. |
| 24 | +
|
| 25 | + Module imports are cached by Python, so repeated registry assembly uses |
| 26 | + the same step definitions without a second registration side effect. |
| 27 | + """ |
| 28 | + for name in _BUILTIN_MODULES: |
| 29 | + import_module(f"{__name__}.{name}") |
32 | 30 | for spec in _common.collected(): |
33 | 31 | registry.register(spec) |
34 | 32 | return registry |
0 commit comments