simplug 0.5.5__tar.gz → 0.5.7__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.
- simplug-0.5.7/PKG-INFO +88 -0
- simplug-0.5.7/README.md +74 -0
- {simplug-0.5.5 → simplug-0.5.7}/pyproject.toml +27 -18
- simplug-0.5.7/setup.cfg +4 -0
- simplug-0.5.5/simplug.py → simplug-0.5.7/simplug/__init__.py +46 -12
- simplug-0.5.7/simplug/py.typed +0 -0
- simplug-0.5.7/simplug.egg-info/PKG-INFO +88 -0
- simplug-0.5.7/simplug.egg-info/SOURCES.txt +11 -0
- simplug-0.5.7/simplug.egg-info/dependency_links.txt +1 -0
- simplug-0.5.7/simplug.egg-info/requires.txt +1 -0
- simplug-0.5.7/simplug.egg-info/top_level.txt +1 -0
- simplug-0.5.7/tests/test_simplug.py +2071 -0
- simplug-0.5.5/PKG-INFO +0 -213
- simplug-0.5.5/README.md +0 -192
- simplug-0.5.5/setup.py +0 -25
- {simplug-0.5.5 → simplug-0.5.7}/LICENSE +0 -0
simplug-0.5.7/PKG-INFO
ADDED
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: simplug
|
|
3
|
+
Version: 0.5.7
|
|
4
|
+
Summary: A simple plugin system for python with async hooks supported
|
|
5
|
+
Author-email: pwwang <pwwang@pwwang.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/pwwang/simplug
|
|
8
|
+
Project-URL: Repository, https://github.com/pwwang/simplug
|
|
9
|
+
Requires-Python: >=3.9
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: diot>=0.3
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# simplug
|
|
16
|
+
|
|
17
|
+
A simple plugin system for Python with async hooks support.
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
- **Decorator-based API**: Define hooks with `@simplug.spec` and implement with `@simplug.impl`
|
|
22
|
+
- **Async support**: First-class async hooks with sync/async bridging
|
|
23
|
+
- **Flexible result collection**: 18 built-in strategies for collecting plugin results
|
|
24
|
+
- **Priority system**: Control plugin execution order
|
|
25
|
+
- **Setuptools entrypoints**: Load plugins from installed packages
|
|
26
|
+
- **Singleton per project**: Same instance returned for same project name
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```shell
|
|
31
|
+
pip install -U simplug
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from simplug import Simplug
|
|
38
|
+
|
|
39
|
+
# Create a plugin manager
|
|
40
|
+
simplug = Simplug('myproject')
|
|
41
|
+
|
|
42
|
+
# Define a hook specification
|
|
43
|
+
class MySpec:
|
|
44
|
+
@simplug.spec
|
|
45
|
+
def process_data(self, data):
|
|
46
|
+
"""Process data in plugins."""
|
|
47
|
+
|
|
48
|
+
# Implement the hook in plugins
|
|
49
|
+
class PluginA:
|
|
50
|
+
@simplug.impl
|
|
51
|
+
def process_data(self, data):
|
|
52
|
+
return data.upper()
|
|
53
|
+
|
|
54
|
+
class PluginB:
|
|
55
|
+
@simplug.impl
|
|
56
|
+
def process_data(self, data):
|
|
57
|
+
return data.lower()
|
|
58
|
+
|
|
59
|
+
# Register plugins
|
|
60
|
+
simplug.register(PluginA, PluginB)
|
|
61
|
+
|
|
62
|
+
# Call the hook
|
|
63
|
+
results = simplug.hooks.process_data("Hello")
|
|
64
|
+
print(results) # ['HELLO', 'hello']
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Documentation
|
|
68
|
+
|
|
69
|
+
Full documentation is available at [https://pwwang.github.io/simplug/](https://pwwang.github.io/simplug/)
|
|
70
|
+
|
|
71
|
+
## Getting Started
|
|
72
|
+
|
|
73
|
+
1. **Define hooks** - Specify what plugins can customize
|
|
74
|
+
2. **Implement hooks** - Create plugins with implementations
|
|
75
|
+
3. **Register plugins** - Load plugins into your application
|
|
76
|
+
4. **Call hooks** - Trigger plugin execution
|
|
77
|
+
|
|
78
|
+
For detailed guides and API reference, see the [full documentation](https://pwwang.github.io/simplug/).
|
|
79
|
+
|
|
80
|
+
## Examples
|
|
81
|
+
|
|
82
|
+
See the [examples](examples/) directory for complete examples:
|
|
83
|
+
- [`examples/toy.py`](examples/toy.py) - A minimal 30-line demo
|
|
84
|
+
- [`examples/complete/`](examples/complete/) - Full example with setuptools entrypoints
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
MIT
|
simplug-0.5.7/README.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# simplug
|
|
2
|
+
|
|
3
|
+
A simple plugin system for Python with async hooks support.
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Decorator-based API**: Define hooks with `@simplug.spec` and implement with `@simplug.impl`
|
|
8
|
+
- **Async support**: First-class async hooks with sync/async bridging
|
|
9
|
+
- **Flexible result collection**: 18 built-in strategies for collecting plugin results
|
|
10
|
+
- **Priority system**: Control plugin execution order
|
|
11
|
+
- **Setuptools entrypoints**: Load plugins from installed packages
|
|
12
|
+
- **Singleton per project**: Same instance returned for same project name
|
|
13
|
+
|
|
14
|
+
## Installation
|
|
15
|
+
|
|
16
|
+
```shell
|
|
17
|
+
pip install -U simplug
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
## Quick Start
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
from simplug import Simplug
|
|
24
|
+
|
|
25
|
+
# Create a plugin manager
|
|
26
|
+
simplug = Simplug('myproject')
|
|
27
|
+
|
|
28
|
+
# Define a hook specification
|
|
29
|
+
class MySpec:
|
|
30
|
+
@simplug.spec
|
|
31
|
+
def process_data(self, data):
|
|
32
|
+
"""Process data in plugins."""
|
|
33
|
+
|
|
34
|
+
# Implement the hook in plugins
|
|
35
|
+
class PluginA:
|
|
36
|
+
@simplug.impl
|
|
37
|
+
def process_data(self, data):
|
|
38
|
+
return data.upper()
|
|
39
|
+
|
|
40
|
+
class PluginB:
|
|
41
|
+
@simplug.impl
|
|
42
|
+
def process_data(self, data):
|
|
43
|
+
return data.lower()
|
|
44
|
+
|
|
45
|
+
# Register plugins
|
|
46
|
+
simplug.register(PluginA, PluginB)
|
|
47
|
+
|
|
48
|
+
# Call the hook
|
|
49
|
+
results = simplug.hooks.process_data("Hello")
|
|
50
|
+
print(results) # ['HELLO', 'hello']
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Documentation
|
|
54
|
+
|
|
55
|
+
Full documentation is available at [https://pwwang.github.io/simplug/](https://pwwang.github.io/simplug/)
|
|
56
|
+
|
|
57
|
+
## Getting Started
|
|
58
|
+
|
|
59
|
+
1. **Define hooks** - Specify what plugins can customize
|
|
60
|
+
2. **Implement hooks** - Create plugins with implementations
|
|
61
|
+
3. **Register plugins** - Load plugins into your application
|
|
62
|
+
4. **Call hooks** - Trigger plugin execution
|
|
63
|
+
|
|
64
|
+
For detailed guides and API reference, see the [full documentation](https://pwwang.github.io/simplug/).
|
|
65
|
+
|
|
66
|
+
## Examples
|
|
67
|
+
|
|
68
|
+
See the [examples](examples/) directory for complete examples:
|
|
69
|
+
- [`examples/toy.py`](examples/toy.py) - A minimal 30-line demo
|
|
70
|
+
- [`examples/complete/`](examples/complete/) - Full example with setuptools entrypoints
|
|
71
|
+
|
|
72
|
+
## License
|
|
73
|
+
|
|
74
|
+
MIT
|
|
@@ -1,24 +1,33 @@
|
|
|
1
|
-
[
|
|
1
|
+
[project]
|
|
2
2
|
name = "simplug"
|
|
3
|
-
version = "0.5.
|
|
3
|
+
version = "0.5.7"
|
|
4
4
|
description = "A simple plugin system for python with async hooks supported"
|
|
5
|
-
authors = ["pwwang
|
|
6
|
-
license = "MIT"
|
|
7
|
-
homepage = "https://github.com/pwwang/simplug"
|
|
8
|
-
repository = "https://github.com/pwwang/simplug"
|
|
5
|
+
authors = [{name = "pwwang", email = "pwwang@pwwang.com"}]
|
|
6
|
+
license = {text = "MIT"}
|
|
9
7
|
readme = "README.md"
|
|
8
|
+
requires-python = ">=3.9"
|
|
9
|
+
dependencies = [
|
|
10
|
+
"diot>=0.3",
|
|
11
|
+
]
|
|
10
12
|
|
|
11
|
-
[
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
[tool.poetry.build]
|
|
16
|
-
generate-setup-file = true
|
|
13
|
+
[project.urls]
|
|
14
|
+
Homepage = "https://github.com/pwwang/simplug"
|
|
15
|
+
Repository = "https://github.com/pwwang/simplug"
|
|
17
16
|
|
|
18
|
-
[
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
17
|
+
[dependency-groups]
|
|
18
|
+
dev = [
|
|
19
|
+
"flake8>=7.3.0",
|
|
20
|
+
"pytest>=8",
|
|
21
|
+
"pytest-cov>=5",
|
|
22
|
+
"setuptools>=68",
|
|
23
|
+
]
|
|
24
|
+
docs = [
|
|
25
|
+
"jinja2>=3.1.6",
|
|
26
|
+
"mkapi-fix>=0.1.1",
|
|
27
|
+
"mkdocs>=1.6.1",
|
|
28
|
+
"mkdocs-material>=9.7.6",
|
|
29
|
+
"pymdown-extensions>=10.21.2",
|
|
30
|
+
]
|
|
22
31
|
|
|
23
32
|
[tool.mypy]
|
|
24
33
|
ignore_missing_imports = true
|
|
@@ -36,8 +45,8 @@ filterwarnings = [
|
|
|
36
45
|
]
|
|
37
46
|
|
|
38
47
|
[build-system]
|
|
39
|
-
requires = ["
|
|
40
|
-
build-backend = "
|
|
48
|
+
requires = ["setuptools>=68"]
|
|
49
|
+
build-backend = "setuptools.build_meta"
|
|
41
50
|
|
|
42
51
|
[tool.black]
|
|
43
52
|
line-length = 88
|
simplug-0.5.7/setup.cfg
ADDED
|
@@ -13,7 +13,32 @@ from typing import Any, Callable, Dict, Iterable, List, Tuple, Union, Optional
|
|
|
13
13
|
|
|
14
14
|
from diot import OrderedDiot
|
|
15
15
|
|
|
16
|
-
__version__ = "0.5.
|
|
16
|
+
__version__ = "0.5.7"
|
|
17
|
+
|
|
18
|
+
__all__ = [
|
|
19
|
+
"SimplugImpl",
|
|
20
|
+
"SimplugException",
|
|
21
|
+
"NoSuchPlugin",
|
|
22
|
+
"ResultError",
|
|
23
|
+
"ResultUnavailableError",
|
|
24
|
+
"PluginRegistered",
|
|
25
|
+
"NoPluginNameDefined",
|
|
26
|
+
"HookSignatureDifferentFromSpec",
|
|
27
|
+
"NoSuchHookSpec",
|
|
28
|
+
"HookRequired",
|
|
29
|
+
"HookSpecExists",
|
|
30
|
+
"AsyncImplOnSyncSpecError",
|
|
31
|
+
"SyncImplOnAsyncSpecWarning",
|
|
32
|
+
"MultipleImplsForSingleResultHookWarning",
|
|
33
|
+
"ImplMightNeedInstanceWarning",
|
|
34
|
+
"SimplugResult",
|
|
35
|
+
"SimplugWrapper",
|
|
36
|
+
"SimplugHook",
|
|
37
|
+
"SimplugHookAsync",
|
|
38
|
+
"SimplugHooks",
|
|
39
|
+
"SimplugContext",
|
|
40
|
+
"Simplug",
|
|
41
|
+
]
|
|
17
42
|
|
|
18
43
|
|
|
19
44
|
class SimplugImpl:
|
|
@@ -274,6 +299,10 @@ class SimplugWrapper:
|
|
|
274
299
|
(batch_index, index) if priority is None else (priority, batch_index)
|
|
275
300
|
)
|
|
276
301
|
|
|
302
|
+
instantiate = getattr(self.plugin, "instantiate", False)
|
|
303
|
+
if instantiate and inspect.isclass(self.plugin):
|
|
304
|
+
self.plugin = self.plugin()
|
|
305
|
+
|
|
277
306
|
self.enabled = True # type: bool
|
|
278
307
|
|
|
279
308
|
@property
|
|
@@ -438,12 +467,17 @@ class SimplugHook:
|
|
|
438
467
|
try:
|
|
439
468
|
sig = inspect.signature(self_obj)
|
|
440
469
|
required_params = [
|
|
441
|
-
p
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
470
|
+
p
|
|
471
|
+
for p in sig.parameters.values()
|
|
472
|
+
if (
|
|
473
|
+
p.kind
|
|
474
|
+
in (
|
|
475
|
+
inspect.Parameter.POSITIONAL_ONLY,
|
|
476
|
+
inspect.Parameter.POSITIONAL_OR_KEYWORD,
|
|
477
|
+
)
|
|
478
|
+
and p.default is inspect.Parameter.empty
|
|
479
|
+
and p.name != "self"
|
|
480
|
+
)
|
|
447
481
|
]
|
|
448
482
|
if not required_params:
|
|
449
483
|
self_obj = self_obj()
|
|
@@ -709,9 +743,7 @@ class SimplugHookAsync(SimplugHook):
|
|
|
709
743
|
ret = await makecall(call, True)
|
|
710
744
|
if ret is not None:
|
|
711
745
|
if self.debug:
|
|
712
|
-
print(
|
|
713
|
-
"[simplug] - Returning first available (non-None) result"
|
|
714
|
-
)
|
|
746
|
+
print("[simplug] - Returning first available (non-None) result")
|
|
715
747
|
return ret
|
|
716
748
|
raise ResultUnavailableError
|
|
717
749
|
if result == SimplugResult.LAST_AVAIL.value:
|
|
@@ -818,7 +850,7 @@ class SimplugHooks:
|
|
|
818
850
|
|
|
819
851
|
def __init__(self) -> None:
|
|
820
852
|
|
|
821
|
-
self._registry = OrderedDiot()
|
|
853
|
+
self._registry = OrderedDiot() # type: ignore
|
|
822
854
|
self._specs: Dict[str, Union[SimplugHook, SimplugHookAsync]] = {}
|
|
823
855
|
self._registry_sorted = False
|
|
824
856
|
|
|
@@ -1062,7 +1094,7 @@ class Simplug:
|
|
|
1062
1094
|
plugin = ep.load()
|
|
1063
1095
|
self.register((plugin, ep.name))
|
|
1064
1096
|
|
|
1065
|
-
def register(self, *plugins: Any) -> None:
|
|
1097
|
+
def register(self, *plugins: Any) -> None | Callable:
|
|
1066
1098
|
"""Register plugins
|
|
1067
1099
|
|
|
1068
1100
|
Args:
|
|
@@ -1081,6 +1113,8 @@ class Simplug:
|
|
|
1081
1113
|
# allow to use as a decorator
|
|
1082
1114
|
return plugins[0]
|
|
1083
1115
|
|
|
1116
|
+
return None
|
|
1117
|
+
|
|
1084
1118
|
def get_plugin(self, name: str, raw: bool = False) -> Union[SimplugWrapper, Any]:
|
|
1085
1119
|
"""Get the plugin wrapper or the raw plugin object
|
|
1086
1120
|
|
|
File without changes
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: simplug
|
|
3
|
+
Version: 0.5.7
|
|
4
|
+
Summary: A simple plugin system for python with async hooks supported
|
|
5
|
+
Author-email: pwwang <pwwang@pwwang.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/pwwang/simplug
|
|
8
|
+
Project-URL: Repository, https://github.com/pwwang/simplug
|
|
9
|
+
Requires-Python: >=3.9
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: diot>=0.3
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# simplug
|
|
16
|
+
|
|
17
|
+
A simple plugin system for Python with async hooks support.
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
- **Decorator-based API**: Define hooks with `@simplug.spec` and implement with `@simplug.impl`
|
|
22
|
+
- **Async support**: First-class async hooks with sync/async bridging
|
|
23
|
+
- **Flexible result collection**: 18 built-in strategies for collecting plugin results
|
|
24
|
+
- **Priority system**: Control plugin execution order
|
|
25
|
+
- **Setuptools entrypoints**: Load plugins from installed packages
|
|
26
|
+
- **Singleton per project**: Same instance returned for same project name
|
|
27
|
+
|
|
28
|
+
## Installation
|
|
29
|
+
|
|
30
|
+
```shell
|
|
31
|
+
pip install -U simplug
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## Quick Start
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from simplug import Simplug
|
|
38
|
+
|
|
39
|
+
# Create a plugin manager
|
|
40
|
+
simplug = Simplug('myproject')
|
|
41
|
+
|
|
42
|
+
# Define a hook specification
|
|
43
|
+
class MySpec:
|
|
44
|
+
@simplug.spec
|
|
45
|
+
def process_data(self, data):
|
|
46
|
+
"""Process data in plugins."""
|
|
47
|
+
|
|
48
|
+
# Implement the hook in plugins
|
|
49
|
+
class PluginA:
|
|
50
|
+
@simplug.impl
|
|
51
|
+
def process_data(self, data):
|
|
52
|
+
return data.upper()
|
|
53
|
+
|
|
54
|
+
class PluginB:
|
|
55
|
+
@simplug.impl
|
|
56
|
+
def process_data(self, data):
|
|
57
|
+
return data.lower()
|
|
58
|
+
|
|
59
|
+
# Register plugins
|
|
60
|
+
simplug.register(PluginA, PluginB)
|
|
61
|
+
|
|
62
|
+
# Call the hook
|
|
63
|
+
results = simplug.hooks.process_data("Hello")
|
|
64
|
+
print(results) # ['HELLO', 'hello']
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
## Documentation
|
|
68
|
+
|
|
69
|
+
Full documentation is available at [https://pwwang.github.io/simplug/](https://pwwang.github.io/simplug/)
|
|
70
|
+
|
|
71
|
+
## Getting Started
|
|
72
|
+
|
|
73
|
+
1. **Define hooks** - Specify what plugins can customize
|
|
74
|
+
2. **Implement hooks** - Create plugins with implementations
|
|
75
|
+
3. **Register plugins** - Load plugins into your application
|
|
76
|
+
4. **Call hooks** - Trigger plugin execution
|
|
77
|
+
|
|
78
|
+
For detailed guides and API reference, see the [full documentation](https://pwwang.github.io/simplug/).
|
|
79
|
+
|
|
80
|
+
## Examples
|
|
81
|
+
|
|
82
|
+
See the [examples](examples/) directory for complete examples:
|
|
83
|
+
- [`examples/toy.py`](examples/toy.py) - A minimal 30-line demo
|
|
84
|
+
- [`examples/complete/`](examples/complete/) - Full example with setuptools entrypoints
|
|
85
|
+
|
|
86
|
+
## License
|
|
87
|
+
|
|
88
|
+
MIT
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
simplug/__init__.py
|
|
5
|
+
simplug/py.typed
|
|
6
|
+
simplug.egg-info/PKG-INFO
|
|
7
|
+
simplug.egg-info/SOURCES.txt
|
|
8
|
+
simplug.egg-info/dependency_links.txt
|
|
9
|
+
simplug.egg-info/requires.txt
|
|
10
|
+
simplug.egg-info/top_level.txt
|
|
11
|
+
tests/test_simplug.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
diot>=0.3
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
simplug
|