Manager
provide.foundation.hub.manager
¶
TODO: Add module docstring.
Classes¶
Hub
¶
Hub(
context: CLIContext | None = None,
component_registry: Registry | None = None,
command_registry: Registry | None = None,
use_shared_registries: bool = False,
)
Bases: CoreHub
Central hub for managing components, commands, and Foundation integration.
The Hub provides a unified interface for: - Registering components and commands - Discovering plugins via entry points - Creating Click CLI applications - Managing component lifecycle - Foundation system initialization
Example
hub = Hub() hub.add_component(MyResource, "resource") hub.add_command(init_cmd, "init") hub.initialize_foundation()
Create CLI with all commands¶
cli = hub.create_cli() cli()
Initialize the hub.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
context
|
CLIContext | None
|
Foundation CLIContext for configuration |
None
|
component_registry
|
Registry | None
|
Custom component registry |
None
|
command_registry
|
Registry | None
|
Custom command registry |
None
|
use_shared_registries
|
bool
|
If True, use global shared registries |
False
|
Source code in provide/foundation/hub/manager.py
Functions¶
clear
¶
Clear registrations and dispose of resources properly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimension
|
str | None
|
Optional dimension to clear (None = all) |
None
|
Source code in provide/foundation/hub/manager.py
dispose_all
¶
Dispose of all managed resources without clearing registrations.
get_foundation_config
¶
get_foundation_logger
¶
Get Foundation logger instance through Hub.
Auto-initializes Foundation if not already done. Thread-safe with fallback behavior.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str | None
|
Logger name (e.g., module name) |
None
|
Returns:
| Type | Description |
|---|---|
Any
|
Configured logger instance |
Source code in provide/foundation/hub/manager.py
initialize_foundation
¶
Initialize Foundation system through Hub.
Single initialization method replacing all setup_* functions. Thread-safe and idempotent, unless force=True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Any
|
Optional TelemetryConfig (defaults to from_env) |
None
|
force
|
bool
|
If True, force re-initialization even if already initialized |
False
|
Source code in provide/foundation/hub/manager.py
is_foundation_initialized
¶
Functions¶
clear_hub
¶
Clear the global hub instance.
This is primarily used for testing to reset Foundation state between test runs.
Source code in provide/foundation/hub/manager.py
get_hub
¶
Get the global shared hub instance (singleton pattern).
This function acts as the Composition Root for the global singleton instance. It is maintained for backward compatibility and convenience.
Note: For building testable and maintainable applications, the recommended
approach is to use a Container or Hub instance created at your application's
entry point for explicit dependency management. This global accessor should be
avoided in application code.
Thread-safe: Uses double-checked locking pattern for efficient lazy initialization.
Auto-Initialization Behavior: This function automatically initializes the Foundation system on first access. The initialization is: - Idempotent: Safe to call multiple times - Thread-safe: Uses lock manager for coordination - Lazy: Only happens on first access
Returns:
| Type | Description |
|---|---|
Hub
|
Global Hub instance (created and initialized if needed) |
Example
hub = get_hub() hub.register_command("my_command", my_function)
Note
For isolated Hub instances (testing, advanced use cases), use:
hub = Hub(use_shared_registries=False)