config
orchard.core.config
¶
Configuration Package Initialization.
Provides a unified, flat public API for configuration components while avoiding eager imports of heavy or optional dependencies (e.g. torch).
Architecture:
- Lazy Import Pattern (PEP 562): Uses getattr for on-demand loading
- Deferred Dependencies: torch and pydantic loaded only when needed
- Flat API: All configs accessible from orchard.core.config namespace
- Caching: Loaded modules cached in globals() for performance
Implementation:
__all__: Public API contract listing all available configs_LAZY_IMPORTS: Mapping from config names to module paths__getattr__: Dynamic loader triggered on first access__dir__: IDE/introspection support for auto-completion
Example
from orchard.core.config import Config, HardwareConfig
torch is NOT imported yet (lazy loading)¶
cfg = Config.from_recipe(Path("recipes/config_mini_cnn.yaml"))
NOW torch is imported (triggered by Config access)¶
__getattr__(name)
¶
Lazily import configuration components on first access.
Implements PEP 562 module-level getattr to defer heavy dependency imports (torch, pydantic) until the corresponding class is used.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Name of the configuration class to import. |
required |
Returns:
| Type | Description |
|---|---|
Any
|
The requested configuration class. |
Raises:
| Type | Description |
|---|---|
AttributeError
|
If name is not in the public API (all). |
Source code in orchard/core/config/__init__.py
__dir__()
¶
Support for dir() and IDE auto-completion.
Returns:
| Type | Description |
|---|---|
list[str]
|
Sorted list of public configuration class names |