super-solid-system 1.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- super_solid_system-1.0.0/LICENSE +201 -0
- super_solid_system-1.0.0/PKG-INFO +494 -0
- super_solid_system-1.0.0/README.md +468 -0
- super_solid_system-1.0.0/pyproject.toml +55 -0
- super_solid_system-1.0.0/supersolid/__init__.py +2 -0
- super_solid_system-1.0.0/supersolid/core/__init__.py +97 -0
- super_solid_system-1.0.0/supersolid/core/discovery.py +74 -0
- super_solid_system-1.0.0/supersolid/core/engine.py +92 -0
- super_solid_system-1.0.0/supersolid/core/events.py +149 -0
- super_solid_system-1.0.0/supersolid/core/health.py +24 -0
- super_solid_system-1.0.0/supersolid/core/registry.py +303 -0
- super_solid_system-1.0.0/supersolid/core/security.py +38 -0
- super_solid_system-1.0.0/supersolid/core/system.py +97 -0
- super_solid_system-1.0.0/supersolid/py.typed +1 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [2026] [Doth-J]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: super-solid-system
|
|
3
|
+
Version: 1.0.0
|
|
4
|
+
Summary: A lightweight, type-safe microkernel & plug-and-play framework for Python.
|
|
5
|
+
License-Expression: Apache-2.0
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Keywords: microkernel,plugin,registry,modular,framework,dependency-injection,type-safe
|
|
8
|
+
Author: Doth-J
|
|
9
|
+
Author-email: theodjoan@gmail.com
|
|
10
|
+
Requires-Python: >=3.10
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Programming Language :: Python :: 3
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
18
|
+
Classifier: Topic :: Software Development :: Libraries :: Application Frameworks
|
|
19
|
+
Classifier: Typing :: Typed
|
|
20
|
+
Requires-Dist: pydantic (>=2.0.0)
|
|
21
|
+
Project-URL: Homepage, https://github.com/Doth-J/super-solid-system
|
|
22
|
+
Project-URL: Issues, https://github.com/Doth-J/super-solid-system/issues
|
|
23
|
+
Project-URL: Repository, https://github.com/Doth-J/super-solid-system
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
|
|
26
|
+
# Super-Solid System (`supersolid`)
|
|
27
|
+
|
|
28
|
+
<p align="center">
|
|
29
|
+
<img src="docs/logo.png" alt="Super-Solid" width="250"/>
|
|
30
|
+
</p>
|
|
31
|
+
|
|
32
|
+
<h1 align="center">Super-Solid System</h1>
|
|
33
|
+
|
|
34
|
+
<p align="center">
|
|
35
|
+
<strong>A robust, generic infrastructure for building modular software systems with plug-and-play engines, dynamic plugin discovery, thread-safe component registries, and fault-tolerant system lifecycle management.</strong><br/>
|
|
36
|
+
</p>
|
|
37
|
+
|
|
38
|
+
<p align="center">
|
|
39
|
+
<img alt="Python" src="https://img.shields.io/badge/python-%3E%3D3.10-blue?logo=python&logoColor=white"/>
|
|
40
|
+
<img alt="License" src="https://img.shields.io/badge/license-Apache%202.0-green"/>
|
|
41
|
+
<img alt="Tests" src="https://img.shields.io/badge/tests-43%2F43%20passing-brightgreen"/>
|
|
42
|
+
<img alt="Coverage" src="https://img.shields.io/badge/coverage-100%25-brightgreen"/>
|
|
43
|
+
<img alt="Status" src="https://img.shields.io/badge/status-v1.0.0-brightgreen"/>
|
|
44
|
+
</p>
|
|
45
|
+
|
|
46
|
+
> A lightweight, type-safe microkernel & plug-and-play framework for Python.
|
|
47
|
+
|
|
48
|
+
## What is Super-Solid System?
|
|
49
|
+
|
|
50
|
+
Super-Solid System (`S³`) gives you a small set of building blocks for assembling modular applications:
|
|
51
|
+
|
|
52
|
+
- **Registries** hold your components — type-checked, thread-safe, and cached.
|
|
53
|
+
- **Engines** group registries together and handle boot/shutdown logic.
|
|
54
|
+
- **Systems** orchestrate engines in dependency order with automatic rollback.
|
|
55
|
+
- **Events** let everything talk to each other through a reactive signal bus.
|
|
56
|
+
- **Security** controls who can load what and from where.
|
|
57
|
+
- **Health** provides a standard way for components to report their status.
|
|
58
|
+
|
|
59
|
+
No magic, no hidden state, no framework lock-in. Just clean abstractions you subclass and wire up.
|
|
60
|
+
|
|
61
|
+
## Architecture
|
|
62
|
+
|
|
63
|
+
```mermaid
|
|
64
|
+
graph TD
|
|
65
|
+
S["SuperSolidSystem"]
|
|
66
|
+
EB["SuperSolidEventBus"]
|
|
67
|
+
E1["SuperSolidEngine A"]
|
|
68
|
+
E2["SuperSolidEngine B"]
|
|
69
|
+
R1["SuperSolidRegistry 1"]
|
|
70
|
+
R2["SuperSolidRegistry 2"]
|
|
71
|
+
R3["SuperSolidRegistry 3"]
|
|
72
|
+
D["DiscoveryStrategy Chain"]
|
|
73
|
+
SP["SecurityPolicy"]
|
|
74
|
+
H["HealthCheckable"]
|
|
75
|
+
|
|
76
|
+
S -->|starts / stops| E1
|
|
77
|
+
S -->|starts / stops| E2
|
|
78
|
+
S -->|publishes signals| EB
|
|
79
|
+
E1 -->|routes loads to| R1
|
|
80
|
+
E1 -->|routes loads to| R2
|
|
81
|
+
E2 -->|routes loads to| R3
|
|
82
|
+
R1 -->|discovers plugins via| D
|
|
83
|
+
R1 -.->|enforced by| SP
|
|
84
|
+
R2 -.->|enforced by| SP
|
|
85
|
+
E1 -.->|implements| H
|
|
86
|
+
E2 -.->|implements| H
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The core loop is simple:
|
|
90
|
+
|
|
91
|
+
1. **Register** component classes into typed registries (or let discovery find them).
|
|
92
|
+
2. **Load** components on demand — the registry instantiates, caches, and returns them.
|
|
93
|
+
3. **Wire** registries into engines, engines into a system, and call `start()`.
|
|
94
|
+
|
|
95
|
+
## Installation
|
|
96
|
+
|
|
97
|
+
### Pip (editable, for development)
|
|
98
|
+
|
|
99
|
+
```bash
|
|
100
|
+
pip install -e /path/to/super-solid-system
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### Poetry (as a local dependency)
|
|
104
|
+
|
|
105
|
+
```bash
|
|
106
|
+
poetry add --editable /path/to/super-solid-system
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
### Docker (Multi-stage build)
|
|
110
|
+
|
|
111
|
+
```bash
|
|
112
|
+
# Build the production Docker image
|
|
113
|
+
docker build -t super-solid-system:latest .
|
|
114
|
+
|
|
115
|
+
# Run container & verify installation
|
|
116
|
+
docker run --rm super-solid-system:latest
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
## Quickstart
|
|
120
|
+
|
|
121
|
+
### 1. Define a base interface and a registry
|
|
122
|
+
|
|
123
|
+
```python
|
|
124
|
+
from abc import ABC, abstractmethod
|
|
125
|
+
from supersolid.core import super_solid_registry, SuperSolidRegistry
|
|
126
|
+
|
|
127
|
+
class BaseAdapter(ABC):
|
|
128
|
+
@abstractmethod
|
|
129
|
+
def connect(self) -> None: ...
|
|
130
|
+
|
|
131
|
+
# [QUICK] Create a typed component registry using super_solid_registry
|
|
132
|
+
Adapters = super_solid_registry(name="adapters", component_class=BaseAdapter)
|
|
133
|
+
|
|
134
|
+
# [ALTERNATIVE] Create a class component registry by subclassing SuperSolidRegistry
|
|
135
|
+
class AdapterRegistry(SuperSolidRegistry[BaseAdapter]):
|
|
136
|
+
def __init__(self):
|
|
137
|
+
super().__init__(name="adapters", component_class=BaseAdapter)
|
|
138
|
+
|
|
139
|
+
Adapters = AdapterRegistry()
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
`SuperSolidRegistry` is generic — it enforces that only `BaseAdapter` subclasses can be registered here. Anything else raises a `TypeError` at registration time.
|
|
143
|
+
|
|
144
|
+
### 2. Register components
|
|
145
|
+
|
|
146
|
+
You can register manually:
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
Adapters.register("database", "sqlite", SqliteAdapter)
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
Or use the `@super_solid_component` decorator for a more declarative style:
|
|
153
|
+
|
|
154
|
+
```python
|
|
155
|
+
from supersolid.core import super_solid_component
|
|
156
|
+
|
|
157
|
+
@super_solid_component(Adapters, namespace="database", name="postgres", version="1.0.0")
|
|
158
|
+
class PostgresAdapter(BaseAdapter):
|
|
159
|
+
def __init__(self, dsn: str = "postgresql://localhost/db"):
|
|
160
|
+
self.dsn = dsn
|
|
161
|
+
|
|
162
|
+
def connect(self) -> None:
|
|
163
|
+
print(f"Connected to {self.dsn}")
|
|
164
|
+
|
|
165
|
+
def disconnect(self) -> None:
|
|
166
|
+
print("Disconnected.")
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
The decorator registers the class and attaches a `ComponentMetadata` model you can inspect later:
|
|
170
|
+
|
|
171
|
+
```python
|
|
172
|
+
PostgresAdapter._metadata.version # "1.0.0"
|
|
173
|
+
PostgresAdapter._metadata.namespace # "database"
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### 3. Load components
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
db = Adapters.load("database", "postgres", dsn="postgresql://prod/mydb")
|
|
180
|
+
db.connect() # Connected to postgresql://prod/mydb
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
What happens under the hood:
|
|
184
|
+
|
|
185
|
+
1. Checks the cache — if already loaded with the same parameters, returns the cached instance.
|
|
186
|
+
2. If not registered, runs the **discovery chain** (more on that below).
|
|
187
|
+
3. Introspects the constructor signature and filters keyword arguments automatically.
|
|
188
|
+
4. Calls lifecycle hooks (`initialize()` or `boot()`) if the component defines them.
|
|
189
|
+
5. Caches and returns the instance.
|
|
190
|
+
|
|
191
|
+
When you're done:
|
|
192
|
+
|
|
193
|
+
```python
|
|
194
|
+
Adapters.unload("database", "postgres")
|
|
195
|
+
# Calls disconnect() or stop() automatically if the component defines them
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
### 4. Build an engine
|
|
199
|
+
|
|
200
|
+
A `SuperSolidEngine` groups registries and provides a unified loading interface:
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
from supersolid.core import SuperSolidEngine
|
|
204
|
+
|
|
205
|
+
class CoreEngine(SuperSolidEngine):
|
|
206
|
+
def __init__(self):
|
|
207
|
+
super().__init__()
|
|
208
|
+
self.connect(Adapters) # attach registries
|
|
209
|
+
|
|
210
|
+
def boot(self, **kwargs) -> None:
|
|
211
|
+
self._running = True
|
|
212
|
+
db = self.load("adapters", "database", "postgres")
|
|
213
|
+
db.connect()
|
|
214
|
+
|
|
215
|
+
def mount(self, app, **kwargs) -> None:
|
|
216
|
+
pass # hook for attaching to a web framework, etc.
|
|
217
|
+
|
|
218
|
+
def shutdown(self, **kwargs) -> None:
|
|
219
|
+
self._running = False
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Need async? Subclass `SuperSolidAsyncEngine` instead — it provides `boot_async()`, `mount_async()`, and `shutdown_async()` that automatically bridge to the sync interface via `asyncio.run()`.
|
|
223
|
+
|
|
224
|
+
### 5. Orchestrate with a system
|
|
225
|
+
|
|
226
|
+
```python
|
|
227
|
+
from supersolid.core import SuperSolidSystem
|
|
228
|
+
|
|
229
|
+
class MyApp(SuperSolidSystem):
|
|
230
|
+
pass
|
|
231
|
+
|
|
232
|
+
app = MyApp()
|
|
233
|
+
app.add_engine("core", CoreEngine())
|
|
234
|
+
app.start() # boots engines in dependency order
|
|
235
|
+
# ... your app runs ...
|
|
236
|
+
app.stop() # shuts down in reverse order
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
If any engine fails during `start()`, all previously booted engines are shut down in reverse (LIFO) order automatically.
|
|
240
|
+
|
|
241
|
+
## Engine Dependencies (Dependency Resolution)
|
|
242
|
+
|
|
243
|
+
Engines can declare dependencies on other engines:
|
|
244
|
+
|
|
245
|
+
```python
|
|
246
|
+
class ConsensusEngine(SuperSolidEngine):
|
|
247
|
+
depends_on = ["network"] # boot network engine first
|
|
248
|
+
# ...
|
|
249
|
+
|
|
250
|
+
class NetworkEngine(SuperSolidEngine):
|
|
251
|
+
depends_on = []
|
|
252
|
+
# ...
|
|
253
|
+
|
|
254
|
+
system = MyApp()
|
|
255
|
+
system.add_engine("consensus", ConsensusEngine())
|
|
256
|
+
system.add_engine("network", NetworkEngine())
|
|
257
|
+
system.start()
|
|
258
|
+
# Boot order: network → consensus (resolved via topological sort)
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
The system uses the internal `graphlibs` `TopologicalSorter` so circular dependencies raise a `CycleError` immediately.
|
|
262
|
+
|
|
263
|
+
## Events
|
|
264
|
+
|
|
265
|
+
`SuperSolidSystem` comes with a built-in `SuperSolidEventBus` that publishes lifecycle signals automatically:
|
|
266
|
+
|
|
267
|
+
| Event | When it fires |
|
|
268
|
+
| :-------------------- | :--------------------------------- |
|
|
269
|
+
| `EngineBootingEvent` | Right before an engine boots |
|
|
270
|
+
| `EngineBootedEvent` | After an engine boots successfully |
|
|
271
|
+
| `EngineShutdownEvent` | After an engine shuts down |
|
|
272
|
+
| `SystemErrorEvent` | On boot failure or shutdown error |
|
|
273
|
+
| `PluginLoadedEvent` | When a plugin is loaded |
|
|
274
|
+
|
|
275
|
+
### Subscribing to events
|
|
276
|
+
|
|
277
|
+
```python
|
|
278
|
+
from supersolid.core import SuperSolidEventBus, EngineBootedEvent, super_solid_subscriber
|
|
279
|
+
|
|
280
|
+
bus = SuperSolidEventBus()
|
|
281
|
+
|
|
282
|
+
@super_solid_subscriber(bus)
|
|
283
|
+
def on_boot(event: EngineBootedEvent):
|
|
284
|
+
print(f"Engine '{event.engine_name}' is up!")
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
The decorator infers the event type from the parameter annotation. You can also be explicit:
|
|
288
|
+
|
|
289
|
+
```python
|
|
290
|
+
@super_solid_subscriber(bus, event_type=EngineBootedEvent)
|
|
291
|
+
def on_boot(event):
|
|
292
|
+
print(f"Engine '{event.engine_name}' is up!")
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Publishing events
|
|
296
|
+
|
|
297
|
+
The `@super_solid_publisher` decorator auto-publishes a function's return value if it's a `SystemEvent`:
|
|
298
|
+
|
|
299
|
+
```python
|
|
300
|
+
from supersolid.core import super_solid_publisher, EngineBootedEvent
|
|
301
|
+
|
|
302
|
+
@super_solid_publisher(bus)
|
|
303
|
+
def finish_boot(name: str) -> EngineBootedEvent:
|
|
304
|
+
# ... do boot work ...
|
|
305
|
+
return EngineBootedEvent(engine_name=name)
|
|
306
|
+
|
|
307
|
+
finish_boot("consensus") # automatically published to bus
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
Works with both sync and async functions.
|
|
311
|
+
|
|
312
|
+
### Custom events
|
|
313
|
+
|
|
314
|
+
All events are Pydantic models with `extra = "allow"`, so you can add any fields:
|
|
315
|
+
|
|
316
|
+
```python
|
|
317
|
+
from supersolid.core import SystemEvent
|
|
318
|
+
|
|
319
|
+
class NodeSyncEvent(SystemEvent):
|
|
320
|
+
node_id: str
|
|
321
|
+
epoch: int
|
|
322
|
+
|
|
323
|
+
# Extra fields work too — they serialize to JSON just fine
|
|
324
|
+
event = NodeSyncEvent(node_id="node_01", epoch=42, custom_field="whatever")
|
|
325
|
+
event.model_dump_json()
|
|
326
|
+
```
|
|
327
|
+
|
|
328
|
+
## Plugin Discovery
|
|
329
|
+
|
|
330
|
+
When you call `registry.load()` for something that isn't registered yet, the registry runs a **discovery chain** to try to find it automatically. The default chain has three strategies:
|
|
331
|
+
|
|
332
|
+
```mermaid
|
|
333
|
+
graph LR
|
|
334
|
+
A["InternalLib"] -->|not found| B["EntryPoints"]
|
|
335
|
+
B -->|not found| C["PluginDirectory"]
|
|
336
|
+
style A fill:#4a9,stroke:#333,color:#fff
|
|
337
|
+
style B fill:#49a,stroke:#333,color:#fff
|
|
338
|
+
style C fill:#a94,stroke:#333,color:#fff
|
|
339
|
+
```
|
|
340
|
+
|
|
341
|
+
| Strategy | Where it looks |
|
|
342
|
+
| :---------------- | :------------------------------------------------------------------------ |
|
|
343
|
+
| `InternalLib` | `{root_pkg}.lib.{registry_name}.{namespace}_{name}` (trusted imports) |
|
|
344
|
+
| `EntryPoints` | Setuptools entry points in group `{root_pkg}.{registry_name}.{namespace}` |
|
|
345
|
+
| `PluginDirectory` | `plugins.{registry_name}.{namespace}_{name}` (local files) |
|
|
346
|
+
|
|
347
|
+
### Writing a custom discovery strategy
|
|
348
|
+
|
|
349
|
+
```python
|
|
350
|
+
from supersolid.core import DiscoveryStrategy
|
|
351
|
+
|
|
352
|
+
class RemoteDiscovery(DiscoveryStrategy):
|
|
353
|
+
def discover(self, registry, item_namespace, item_name) -> bool:
|
|
354
|
+
# fetch plugin from remote source, register it
|
|
355
|
+
return registry.is_registered(item_namespace, item_name)
|
|
356
|
+
|
|
357
|
+
Adapters.add_discovery(RemoteDiscovery())
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
## Security
|
|
361
|
+
|
|
362
|
+
### SecurityPolicy
|
|
363
|
+
|
|
364
|
+
Attach a `SecurityPolicy` to any registry to control access:
|
|
365
|
+
|
|
366
|
+
```python
|
|
367
|
+
from supersolid.core import SecurityPolicy
|
|
368
|
+
|
|
369
|
+
policy = SecurityPolicy(
|
|
370
|
+
allowed_namespaces={"database", "cache"}, # only these namespaces can be loaded
|
|
371
|
+
allowed_callers={"core_engine"}, # only these caller IDs are authorized
|
|
372
|
+
allow_internal_lib=True, # trusted internal imports still work
|
|
373
|
+
allow_dynamic_discovery=False, # block external plugins (EntryPoints, PluginDirectory)
|
|
374
|
+
)
|
|
375
|
+
|
|
376
|
+
Adapters.set_policy(policy)
|
|
377
|
+
```
|
|
378
|
+
|
|
379
|
+
Now `Adapters.load("auth", "oauth")` raises `PermissionError` because `"auth"` isn't in the allowed set. And external discovery strategies are skipped entirely, while `InternalLib` still runs as a trusted fallback.
|
|
380
|
+
|
|
381
|
+
### Plugin verification
|
|
382
|
+
|
|
383
|
+
Before importing a plugin file, you can verify its checksum:
|
|
384
|
+
|
|
385
|
+
```python
|
|
386
|
+
from supersolid.core import PluginVerifier
|
|
387
|
+
|
|
388
|
+
if PluginVerifier.verify_sha256("plugins/consensus/my_plugin.py", expected_hash):
|
|
389
|
+
import plugins.consensus.my_plugin
|
|
390
|
+
```
|
|
391
|
+
|
|
392
|
+
## Health Checks
|
|
393
|
+
|
|
394
|
+
Any component can implement health reporting by defining a `health_check()` method:
|
|
395
|
+
|
|
396
|
+
```python
|
|
397
|
+
from supersolid.core import HealthStatus, HealthState, HealthCheckable
|
|
398
|
+
|
|
399
|
+
class DatabaseAdapter:
|
|
400
|
+
def health_check(self) -> HealthStatus:
|
|
401
|
+
return HealthStatus(
|
|
402
|
+
state=HealthState.HEALTHY,
|
|
403
|
+
details={"connections": 42, "pool_size": 100}
|
|
404
|
+
)
|
|
405
|
+
|
|
406
|
+
db = DatabaseAdapter()
|
|
407
|
+
isinstance(db, HealthCheckable) # True — structural typing via Protocol
|
|
408
|
+
db.health_check().model_dump_json()
|
|
409
|
+
# {"state": "healthy", "details": {"connections": 42, "pool_size": 100}, "timestamp": ...}
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
`HealthCheckable` is a `@runtime_checkable` Protocol — no need to inherit from anything.
|
|
413
|
+
|
|
414
|
+
The three states are `HEALTHY`, `DEGRADED`, and `UNHEALTHY`.
|
|
415
|
+
|
|
416
|
+
## Project Structure
|
|
417
|
+
|
|
418
|
+
```
|
|
419
|
+
super-solid-system/
|
|
420
|
+
├── supersolid/
|
|
421
|
+
│ └── core/
|
|
422
|
+
│ ├── __init__.py # Public API exports
|
|
423
|
+
│ ├── registry.py # SuperSolidRegistry, super_solid_component, ComponentMetadata
|
|
424
|
+
│ ├── engine.py # SuperSolidEngine, AsyncSuperSolidEngine
|
|
425
|
+
│ ├── system.py # SuperSolidSystem (orchestrator)
|
|
426
|
+
│ ├── events.py # SuperSolidEventBus, SystemEvent, super_solid_subscriber, super_solid_publisher
|
|
427
|
+
│ ├── discovery.py # DiscoveryStrategy, InternalLib, EntryPoints, PluginDirectory
|
|
428
|
+
│ ├── security.py # SecurityPolicy, PluginVerifier
|
|
429
|
+
│ └── health.py # HealthStatus, HealthState, HealthCheckable
|
|
430
|
+
├── tests/
|
|
431
|
+
│ ├── test_registry.py # Registration, loading, type enforcement, thread safety, unload
|
|
432
|
+
│ ├── test_events.py # Event bus pub/sub, @open_subscriber, @open_publisher
|
|
433
|
+
│ ├── test_security.py # Namespace ACL, caller auth, discovery fallbacks, SHA-256
|
|
434
|
+
│ ├── test_health.py # Health models, Protocol duck typing
|
|
435
|
+
│ └── test_system.py # DAG resolution, start/stop, rollback on failure
|
|
436
|
+
├── pyproject.toml
|
|
437
|
+
├── LICENSE
|
|
438
|
+
└── README.md
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
---
|
|
442
|
+
|
|
443
|
+
## API Reference
|
|
444
|
+
|
|
445
|
+
| Export | Module | What it does |
|
|
446
|
+
| :----------------------- | :--------------- | :----------------------------------------------------------------------------------------------- |
|
|
447
|
+
| `SuperSolidSystem` | `core.system` | Orchestrator — boots/stops engines in dependency order (`SolidSystem`, `OpenSystem`) |
|
|
448
|
+
| `SuperSolidEngine` | `core.engine` | Domain hub — groups registries, handles boot/mount/shutdown (`SolidEngine`, `OpenEngine`) |
|
|
449
|
+
| `SuperSolidAsyncEngine` | `core.engine` | Async variant supporting `boot_async()`, `mount_async()` (`SolidAsyncEngine`, `AsyncOpenEngine`) |
|
|
450
|
+
| `SuperSolidRegistry` | `core.registry` | Generic registry — type checks, caching, discovery (`SolidRegistry`, `OpenRegistry`) |
|
|
451
|
+
| `super_solid_registry` | `core.registry` | Factory function — instantiates a `SuperSolidRegistry` (`solid_registry`, `open_registry`) |
|
|
452
|
+
| `super_solid_component` | `core.registry` | Decorator — registers a class with metadata (`solid_component`, `open_component`) |
|
|
453
|
+
| `ComponentMetadata` | `core.registry` | Pydantic model — name, namespace, version, and extras |
|
|
454
|
+
| `SuperSolidEventBus` | `core.events` | In-memory pub/sub signal bus (`SolidEventBus`, `OpenEventBus`) |
|
|
455
|
+
| `SystemEvent` | `core.events` | Base event model (Pydantic, extra fields allowed) |
|
|
456
|
+
| `super_solid_subscriber` | `core.events` | Decorator — subscribes handler with type inference (`solid_subscriber`, `open_subscriber`) |
|
|
457
|
+
| `super_solid_publisher` | `core.events` | Decorator — auto-publishes return values (`solid_publisher`, `open_publisher`) |
|
|
458
|
+
| `DiscoveryStrategy` | `core.discovery` | Abstract base — subclass to write custom plugin discovery |
|
|
459
|
+
| `SecurityPolicy` | `core.security` | Pydantic model — namespace/caller ACL, discovery toggles |
|
|
460
|
+
| `PluginVerifier` | `core.security` | SHA-256 file checksum verification |
|
|
461
|
+
| `HealthStatus` | `core.health` | Pydantic model — state, details, timestamp |
|
|
462
|
+
| `HealthState` | `core.health` | Enum — `HEALTHY`, `DEGRADED`, `UNHEALTHY` |
|
|
463
|
+
| `HealthCheckable` | `core.health` | Protocol — any class with `health_check()` satisfies it |
|
|
464
|
+
|
|
465
|
+
## Running Tests
|
|
466
|
+
|
|
467
|
+
Run the test suite with coverage report:
|
|
468
|
+
|
|
469
|
+
```bash
|
|
470
|
+
poetry run python -m pytest --cov=supersolid --cov-report=term-missing
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
```text
|
|
474
|
+
Name Stmts Miss Cover
|
|
475
|
+
--------------------------------------------------
|
|
476
|
+
supersolid/__init__.py 2 0 100%
|
|
477
|
+
supersolid/core/__init__.py 8 0 100%
|
|
478
|
+
supersolid/core/discovery.py 43 0 100%
|
|
479
|
+
supersolid/core/engine.py 49 0 100%
|
|
480
|
+
supersolid/core/events.py 85 0 100%
|
|
481
|
+
supersolid/core/health.py 14 0 100%
|
|
482
|
+
supersolid/core/registry.py 154 0 100%
|
|
483
|
+
supersolid/core/security.py 24 0 100%
|
|
484
|
+
supersolid/core/system.py 59 0 100%
|
|
485
|
+
--------------------------------------------------
|
|
486
|
+
TOTAL 438 0 100%
|
|
487
|
+
|
|
488
|
+
============================= 43 passed in 1.12s ==============================
|
|
489
|
+
```
|
|
490
|
+
|
|
491
|
+
## License
|
|
492
|
+
|
|
493
|
+
[Apache-2.0](LICENSE)
|
|
494
|
+
|