simplug 0.5.6__tar.gz → 0.5.8__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.8/.editorconfig +8 -0
- simplug-0.5.8/.github/workflows/build.yml +56 -0
- simplug-0.5.8/.github/workflows/docs.yml +29 -0
- simplug-0.5.8/.gitignore +155 -0
- simplug-0.5.8/.pre-commit-config.yaml +46 -0
- simplug-0.5.8/AGENTS.md +74 -0
- simplug-0.5.8/PKG-INFO +87 -0
- simplug-0.5.8/README.md +74 -0
- simplug-0.5.8/docs/examples.md +296 -0
- simplug-0.5.8/docs/getting-started.md +147 -0
- simplug-0.5.8/docs/guide/async-hooks.md +287 -0
- simplug-0.5.8/docs/guide/defining-hooks.md +182 -0
- simplug-0.5.8/docs/guide/entrypoints.md +266 -0
- simplug-0.5.8/docs/guide/implementing-hooks.md +279 -0
- simplug-0.5.8/docs/guide/plugin-registry.md +313 -0
- simplug-0.5.8/docs/guide/priority-system.md +286 -0
- simplug-0.5.8/docs/guide/result-collection.md +367 -0
- simplug-0.5.8/docs/index.md +85 -0
- simplug-0.5.8/docs/requirements.txt +4 -0
- simplug-0.5.8/docs/style.css +115 -0
- simplug-0.5.8/examples/__init__.py +0 -0
- simplug-0.5.8/examples/complete/AGENTS.md +46 -0
- simplug-0.5.8/examples/complete/__init__.py +0 -0
- simplug-0.5.8/examples/complete/__main__.py +4 -0
- simplug-0.5.8/examples/complete/hookspecs.py +19 -0
- simplug-0.5.8/examples/complete/host.py +44 -0
- simplug-0.5.8/examples/complete/lib.py +15 -0
- simplug-0.5.8/examples/complete/plugin/plugin.py +24 -0
- simplug-0.5.8/examples/complete/plugin/setup.py +7 -0
- simplug-0.5.8/examples/toy.py +30 -0
- simplug-0.5.8/mkdocs.yml +77 -0
- simplug-0.5.8/pyproject.toml +57 -0
- simplug-0.5.6/simplug.py → simplug-0.5.8/simplug/__init__.py +68 -22
- simplug-0.5.8/simplug/py.typed +0 -0
- simplug-0.5.8/tests/__init__.py +0 -0
- simplug-0.5.8/tests/entrypoint_plugin/__init__.py +0 -0
- simplug-0.5.8/tests/entrypoint_plugin/entrypoint_plugin.py +7 -0
- simplug-0.5.8/tests/entrypoint_plugin/setup.py +7 -0
- simplug-0.5.8/tests/plugin_module.py +10 -0
- simplug-0.5.8/tests/test_simplug.py +2071 -0
- simplug-0.5.8/tox.ini +4 -0
- simplug-0.5.8/uv.lock +2025 -0
- simplug-0.5.6/PKG-INFO +0 -213
- simplug-0.5.6/README.md +0 -192
- simplug-0.5.6/pyproject.toml +0 -45
- simplug-0.5.6/setup.py +0 -25
- {simplug-0.5.6 → simplug-0.5.8}/LICENSE +0 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
name: Build and Deploy
|
|
2
|
+
|
|
3
|
+
on: [push, pull_request]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
|
|
7
|
+
build:
|
|
8
|
+
runs-on: ubuntu-latest
|
|
9
|
+
if: "! contains(github.event.head_commit.message, 'wip')"
|
|
10
|
+
strategy:
|
|
11
|
+
matrix:
|
|
12
|
+
python-version: [3.9, "3.10", "3.11", "3.12"]
|
|
13
|
+
|
|
14
|
+
steps:
|
|
15
|
+
- uses: actions/checkout@v6
|
|
16
|
+
- name: Install uv
|
|
17
|
+
uses: astral-sh/setup-uv@v8.0.0
|
|
18
|
+
with:
|
|
19
|
+
python-version: ${{ matrix.python-version }}
|
|
20
|
+
- name: Install dependencies
|
|
21
|
+
run: |
|
|
22
|
+
uv sync
|
|
23
|
+
- name: Run flake8
|
|
24
|
+
run: uv run flake8 simplug
|
|
25
|
+
- name: Test with pytest
|
|
26
|
+
run: uv run pytest tests/ --junitxml=junit/test-results-${{ matrix.python-version }}.xml
|
|
27
|
+
- name: Upload pytest test results
|
|
28
|
+
uses: actions/upload-artifact@v7
|
|
29
|
+
with:
|
|
30
|
+
name: pytest-results-${{ matrix.python-version }}
|
|
31
|
+
path: junit/test-results-${{ matrix.python-version }}.xml
|
|
32
|
+
# Use always() to always run this step to publish test results when there are test failures
|
|
33
|
+
if: ${{ always() }}
|
|
34
|
+
- name: Run codacy-coverage-reporter
|
|
35
|
+
uses: codacy/codacy-coverage-reporter-action@master
|
|
36
|
+
if: matrix.python-version == 3.12
|
|
37
|
+
with:
|
|
38
|
+
project-token: ${{ secrets.CODACY_PROJECT_TOKEN }}
|
|
39
|
+
coverage-reports: .coverage.xml
|
|
40
|
+
|
|
41
|
+
deploy:
|
|
42
|
+
needs: build
|
|
43
|
+
runs-on: ubuntu-latest
|
|
44
|
+
if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags')
|
|
45
|
+
strategy:
|
|
46
|
+
matrix:
|
|
47
|
+
python-version: ["3.12"]
|
|
48
|
+
steps:
|
|
49
|
+
- uses: actions/checkout@v6
|
|
50
|
+
- name: Install uv
|
|
51
|
+
uses: astral-sh/setup-uv@v8.0.0
|
|
52
|
+
with:
|
|
53
|
+
python-version: ${{ matrix.python-version }}
|
|
54
|
+
- name: Publish to PyPI
|
|
55
|
+
run: uv build && uv publish --username ${{ secrets.PYPI_USER }} --password ${{ secrets.PYPI_PASSWORD }}
|
|
56
|
+
if: success()
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
name: Build Docs
|
|
2
|
+
|
|
3
|
+
on: [push]
|
|
4
|
+
|
|
5
|
+
jobs:
|
|
6
|
+
docs:
|
|
7
|
+
runs-on: ubuntu-latest
|
|
8
|
+
if: "! contains(github.event.head_commit.message, 'wip')"
|
|
9
|
+
strategy:
|
|
10
|
+
matrix:
|
|
11
|
+
python-version: ["3.12"]
|
|
12
|
+
steps:
|
|
13
|
+
- uses: actions/checkout@v6
|
|
14
|
+
- name: Install uv
|
|
15
|
+
uses: astral-sh/setup-uv@v8.0.0
|
|
16
|
+
with:
|
|
17
|
+
python-version: ${{ matrix.python-version }}
|
|
18
|
+
- name: Install dependencies
|
|
19
|
+
run: uv sync --group docs
|
|
20
|
+
- name: Update docs
|
|
21
|
+
run: |
|
|
22
|
+
uv pip install mkdocs
|
|
23
|
+
uv pip install -r docs/requirements.txt
|
|
24
|
+
|
|
25
|
+
cd docs
|
|
26
|
+
cp ../README.md index.md
|
|
27
|
+
cd ..
|
|
28
|
+
uv run mkdocs gh-deploy --clean --force
|
|
29
|
+
if: success()
|
simplug-0.5.8/.gitignore
ADDED
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
|
|
2
|
+
# Created by https://www.gitignore.io/api/python
|
|
3
|
+
# Edit at https://www.gitignore.io/?templates=python
|
|
4
|
+
|
|
5
|
+
### Python ###
|
|
6
|
+
# Byte-compiled / optimized / DLL files
|
|
7
|
+
__pycache__/
|
|
8
|
+
*.py[cod]
|
|
9
|
+
*$py.class
|
|
10
|
+
|
|
11
|
+
# C extensions
|
|
12
|
+
*.so
|
|
13
|
+
|
|
14
|
+
# Distribution / packaging
|
|
15
|
+
.Python
|
|
16
|
+
build/
|
|
17
|
+
develop-eggs/
|
|
18
|
+
dist/
|
|
19
|
+
downloads/
|
|
20
|
+
eggs/
|
|
21
|
+
.eggs/
|
|
22
|
+
lib/
|
|
23
|
+
lib64/
|
|
24
|
+
parts/
|
|
25
|
+
sdist/
|
|
26
|
+
var/
|
|
27
|
+
wheels/
|
|
28
|
+
pip-wheel-metadata/
|
|
29
|
+
share/python-wheels/
|
|
30
|
+
*.egg-info/
|
|
31
|
+
.installed.cfg
|
|
32
|
+
*.egg
|
|
33
|
+
MANIFEST
|
|
34
|
+
|
|
35
|
+
# PyInstaller
|
|
36
|
+
# Usually these files are written by a python script from a template
|
|
37
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
38
|
+
*.manifest
|
|
39
|
+
*.spec
|
|
40
|
+
|
|
41
|
+
# Installer logs
|
|
42
|
+
pip-log.txt
|
|
43
|
+
pip-delete-this-directory.txt
|
|
44
|
+
|
|
45
|
+
# Unit test / coverage reports
|
|
46
|
+
htmlcov/
|
|
47
|
+
.tox/
|
|
48
|
+
.nox/
|
|
49
|
+
.coverage
|
|
50
|
+
.coverage.*
|
|
51
|
+
.cache
|
|
52
|
+
nosetests.xml
|
|
53
|
+
coverage.xml
|
|
54
|
+
*.cover
|
|
55
|
+
.hypothesis/
|
|
56
|
+
.pytest_cache/
|
|
57
|
+
|
|
58
|
+
# Translations
|
|
59
|
+
*.mo
|
|
60
|
+
*.pot
|
|
61
|
+
|
|
62
|
+
# Django stuff:
|
|
63
|
+
*.log
|
|
64
|
+
local_settings.py
|
|
65
|
+
db.sqlite3
|
|
66
|
+
|
|
67
|
+
# Flask stuff:
|
|
68
|
+
instance/
|
|
69
|
+
.webassets-cache
|
|
70
|
+
|
|
71
|
+
# Scrapy stuff:
|
|
72
|
+
.scrapy
|
|
73
|
+
|
|
74
|
+
# Sphinx documentation
|
|
75
|
+
docs/_build/
|
|
76
|
+
|
|
77
|
+
# PyBuilder
|
|
78
|
+
target/
|
|
79
|
+
|
|
80
|
+
# Jupyter Notebook
|
|
81
|
+
.ipynb_checkpoints
|
|
82
|
+
|
|
83
|
+
# IPython
|
|
84
|
+
profile_default/
|
|
85
|
+
ipython_config.py
|
|
86
|
+
|
|
87
|
+
# pyenv
|
|
88
|
+
.python-version
|
|
89
|
+
|
|
90
|
+
# pipenv
|
|
91
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
92
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
93
|
+
# having no cross-platform support, pipenv may install dependencies that don’t work, or not
|
|
94
|
+
# install all needed dependencies.
|
|
95
|
+
#Pipfile.lock
|
|
96
|
+
|
|
97
|
+
# celery beat schedule file
|
|
98
|
+
celerybeat-schedule
|
|
99
|
+
|
|
100
|
+
# SageMath parsed files
|
|
101
|
+
*.sage.py
|
|
102
|
+
|
|
103
|
+
# Environments
|
|
104
|
+
.env
|
|
105
|
+
.venv
|
|
106
|
+
env/
|
|
107
|
+
venv/
|
|
108
|
+
ENV/
|
|
109
|
+
env.bak/
|
|
110
|
+
venv.bak/
|
|
111
|
+
|
|
112
|
+
# Spyder project settings
|
|
113
|
+
.spyderproject
|
|
114
|
+
.spyproject
|
|
115
|
+
|
|
116
|
+
# Rope project settings
|
|
117
|
+
.ropeproject
|
|
118
|
+
|
|
119
|
+
# mkdocs documentation
|
|
120
|
+
/site
|
|
121
|
+
|
|
122
|
+
# mypy
|
|
123
|
+
.mypy_cache/
|
|
124
|
+
.dmypy.json
|
|
125
|
+
dmypy.json
|
|
126
|
+
|
|
127
|
+
# Pyre type checker
|
|
128
|
+
.pyre/
|
|
129
|
+
|
|
130
|
+
.vscode/
|
|
131
|
+
|
|
132
|
+
*.bak
|
|
133
|
+
|
|
134
|
+
# data for Examples
|
|
135
|
+
examples/data/
|
|
136
|
+
|
|
137
|
+
# logs
|
|
138
|
+
plkit_logs/
|
|
139
|
+
hparams.yaml
|
|
140
|
+
|
|
141
|
+
workdir/
|
|
142
|
+
|
|
143
|
+
**/t-*.ipynb
|
|
144
|
+
.in.fish
|
|
145
|
+
.out.fish
|
|
146
|
+
|
|
147
|
+
# local history for vscode
|
|
148
|
+
.history/
|
|
149
|
+
|
|
150
|
+
# lightning_logs, plkit_logs
|
|
151
|
+
*_logs/
|
|
152
|
+
|
|
153
|
+
docs/api/
|
|
154
|
+
|
|
155
|
+
# End of https://www.gitignore.io/api/python
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# See https://pre-commit.com for more information
|
|
2
|
+
# See https://pre-commit.com/hooks.html for more hooks
|
|
3
|
+
fail_fast: false
|
|
4
|
+
exclude: '^tests/|^setup\.py$|^examples/'
|
|
5
|
+
repos:
|
|
6
|
+
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
7
|
+
rev: 5df1a4bf6f04a1ed3a643167b38d502575e29aef
|
|
8
|
+
hooks:
|
|
9
|
+
- id: trailing-whitespace
|
|
10
|
+
- id: end-of-file-fixer
|
|
11
|
+
- id: check-yaml
|
|
12
|
+
- id: check-added-large-files
|
|
13
|
+
- repo: local
|
|
14
|
+
hooks:
|
|
15
|
+
- id: flake8
|
|
16
|
+
name: Run flake8
|
|
17
|
+
files: ^simplug\.py$
|
|
18
|
+
pass_filenames: true
|
|
19
|
+
entry: flake8
|
|
20
|
+
types: [python]
|
|
21
|
+
language: system
|
|
22
|
+
- id: mypy
|
|
23
|
+
name: Run mypy
|
|
24
|
+
files: ^simplug\.py$
|
|
25
|
+
pass_filenames: true
|
|
26
|
+
entry: mypy
|
|
27
|
+
types: [python]
|
|
28
|
+
language: system
|
|
29
|
+
- id: versionchecker
|
|
30
|
+
name: Check version agreement in pyproject and __version__
|
|
31
|
+
entry: bash -c
|
|
32
|
+
language: system
|
|
33
|
+
args:
|
|
34
|
+
- get_ver() { echo $(egrep "^__version|^version" $1 | cut -d= -f2 | sed 's/\"\| //g'); };
|
|
35
|
+
v1=`get_ver pyproject.toml`;
|
|
36
|
+
v2=`get_ver simplug.py`;
|
|
37
|
+
if [[ $v1 == $v2 ]]; then exit 0; else exit 1; fi
|
|
38
|
+
pass_filenames: false
|
|
39
|
+
files: ^pyproject\.toml|simplug\.py$
|
|
40
|
+
- id: pytest
|
|
41
|
+
name: Run pytest
|
|
42
|
+
entry: pytest
|
|
43
|
+
language: system
|
|
44
|
+
args: [tests/]
|
|
45
|
+
pass_filenames: false
|
|
46
|
+
files: ^tests/.+$|^simplug\.py$
|
simplug-0.5.8/AGENTS.md
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
# PROJECT KNOWLEDGE BASE
|
|
2
|
+
|
|
3
|
+
**Generated:** 2026-01-14
|
|
4
|
+
**Commit:** N/A
|
|
5
|
+
**Branch:** main
|
|
6
|
+
|
|
7
|
+
## OVERVIEW
|
|
8
|
+
Simple plugin system for Python with async hooks. Single-file architecture (~1,300 lines) with comprehensive test coverage. Uses decorator-based API with 18 result collection strategies.
|
|
9
|
+
|
|
10
|
+
## STRUCTURE
|
|
11
|
+
```
|
|
12
|
+
simplug/
|
|
13
|
+
├── simplug.py # Single-file module (entire library)
|
|
14
|
+
├── tests/ # Test suite
|
|
15
|
+
│ └── test_simplug.py # 2,072 lines, 68 tests
|
|
16
|
+
├── examples/ # Usage examples
|
|
17
|
+
│ ├── toy.py # Minimal 30-line demo
|
|
18
|
+
│ └── complete/ # Full example with entrypoints
|
|
19
|
+
├── docs/ # Documentation (mkdocs)
|
|
20
|
+
└── pyproject.toml # Poetry configuration
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## WHERE TO LOOK
|
|
24
|
+
| Task | Location | Notes |
|
|
25
|
+
|------|----------|-------|
|
|
26
|
+
| Main API | simplug.py lines 1002-1293 | Simplug class - plugin manager |
|
|
27
|
+
| Hook execution | simplug.py lines 379-802 | SimplugHook/SimplugHookAsync |
|
|
28
|
+
| Result collection | simplug.py lines 141-182 | SimplugResult enum (18 strategies) |
|
|
29
|
+
| Plugin registry | simplug.py lines 804-930 | SimplugHooks class |
|
|
30
|
+
| Decorators | simplug.py lines 19-69 | SimplugImpl wrapper |
|
|
31
|
+
| Tests | tests/test_simplug.py | Comprehensive coverage of all features |
|
|
32
|
+
| Entrypoints | examples/complete/plugin/ | Setuptools entrypoint demo |
|
|
33
|
+
|
|
34
|
+
## CONVENTIONS
|
|
35
|
+
- **Decorator-based API**: `@simplug.spec` defines hooks, `@simplug.impl` implements them
|
|
36
|
+
- **Single-file architecture**: All library code in simplug.py (intentional, not legacy)
|
|
37
|
+
- **Priority system**: Plugins sorted by `(priority_attr, batch_index)`, negative = higher priority
|
|
38
|
+
- **Async/sync bridge**: `makecall()` handles both, warnings for sync impl on async spec
|
|
39
|
+
- **OrderedDiot**: Uses diot package for plugin registry (preserves insertion order)
|
|
40
|
+
- **Signature validation**: Spec and impl parameter names must match (excluding defaults)
|
|
41
|
+
|
|
42
|
+
## ANTI-PATTERNS (THIS PROJECT)
|
|
43
|
+
- **Modifying spec parameters**: Examples explicitly warn "don't touch them!" (ingredients)
|
|
44
|
+
- **Version mismatch**: Pre-commit hook enforces version sync between pyproject.toml and simplug.py
|
|
45
|
+
|
|
46
|
+
## UNIQUE STYLES
|
|
47
|
+
- **Singleton per project**: `Simplug('project_name')` returns same instance each time
|
|
48
|
+
- **Plugin name resolution**: Priority: `_name` → `name` → `__name__.lower()` → `__class__.__name__.lower()`
|
|
49
|
+
- **Auto-instantiation**: Classes auto-instantiated if no required constructor params
|
|
50
|
+
- **Bit-flag result types**: SimplugResult uses `0b TRY ALL AVAIL ID` pattern
|
|
51
|
+
|
|
52
|
+
## COMMANDS
|
|
53
|
+
```bash
|
|
54
|
+
# Install
|
|
55
|
+
poetry install
|
|
56
|
+
|
|
57
|
+
# Test
|
|
58
|
+
poetry run pytest tests/
|
|
59
|
+
|
|
60
|
+
# Run examples
|
|
61
|
+
poetry run python examples/toy.py
|
|
62
|
+
poetry run python -m examples.complete
|
|
63
|
+
|
|
64
|
+
# Lint
|
|
65
|
+
flake8 simplug.py
|
|
66
|
+
mypy simplug.py
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## NOTES
|
|
70
|
+
- **No src/ directory**: Poetry single-file layout with `generate-setup-file = true`
|
|
71
|
+
- **Minimal dependencies**: Only external dependency is `diot >= 0.3`
|
|
72
|
+
- **Python 3.9+**: Supports 3.9, 3.10, 3.11, 3.12
|
|
73
|
+
- **Entrypoint testing**: Tests and examples include setup.py files for setuptools entrypoints
|
|
74
|
+
- **CI**: GitHub Actions with matrix testing, pre-commit hooks for quality
|
simplug-0.5.8/PKG-INFO
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: simplug
|
|
3
|
+
Version: 0.5.8
|
|
4
|
+
Summary: A simple plugin system for python with async hooks supported
|
|
5
|
+
Project-URL: Homepage, https://github.com/pwwang/simplug
|
|
6
|
+
Project-URL: Repository, https://github.com/pwwang/simplug
|
|
7
|
+
Author-email: pwwang <pwwang@pwwang.com>
|
|
8
|
+
License: MIT
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Requires-Dist: diot>=0.3
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
|
|
14
|
+
# simplug
|
|
15
|
+
|
|
16
|
+
A simple plugin system for Python with async hooks support.
|
|
17
|
+
|
|
18
|
+
## Features
|
|
19
|
+
|
|
20
|
+
- **Decorator-based API**: Define hooks with `@simplug.spec` and implement with `@simplug.impl`
|
|
21
|
+
- **Async support**: First-class async hooks with sync/async bridging
|
|
22
|
+
- **Flexible result collection**: 18 built-in strategies for collecting plugin results
|
|
23
|
+
- **Priority system**: Control plugin execution order
|
|
24
|
+
- **Setuptools entrypoints**: Load plugins from installed packages
|
|
25
|
+
- **Singleton per project**: Same instance returned for same project name
|
|
26
|
+
|
|
27
|
+
## Installation
|
|
28
|
+
|
|
29
|
+
```shell
|
|
30
|
+
pip install -U simplug
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Quick Start
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
from simplug import Simplug
|
|
37
|
+
|
|
38
|
+
# Create a plugin manager
|
|
39
|
+
simplug = Simplug('myproject')
|
|
40
|
+
|
|
41
|
+
# Define a hook specification
|
|
42
|
+
class MySpec:
|
|
43
|
+
@simplug.spec
|
|
44
|
+
def process_data(self, data):
|
|
45
|
+
"""Process data in plugins."""
|
|
46
|
+
|
|
47
|
+
# Implement the hook in plugins
|
|
48
|
+
class PluginA:
|
|
49
|
+
@simplug.impl
|
|
50
|
+
def process_data(self, data):
|
|
51
|
+
return data.upper()
|
|
52
|
+
|
|
53
|
+
class PluginB:
|
|
54
|
+
@simplug.impl
|
|
55
|
+
def process_data(self, data):
|
|
56
|
+
return data.lower()
|
|
57
|
+
|
|
58
|
+
# Register plugins
|
|
59
|
+
simplug.register(PluginA, PluginB)
|
|
60
|
+
|
|
61
|
+
# Call the hook
|
|
62
|
+
results = simplug.hooks.process_data("Hello")
|
|
63
|
+
print(results) # ['HELLO', 'hello']
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Documentation
|
|
67
|
+
|
|
68
|
+
Full documentation is available at [https://pwwang.github.io/simplug/](https://pwwang.github.io/simplug/)
|
|
69
|
+
|
|
70
|
+
## Getting Started
|
|
71
|
+
|
|
72
|
+
1. **Define hooks** - Specify what plugins can customize
|
|
73
|
+
2. **Implement hooks** - Create plugins with implementations
|
|
74
|
+
3. **Register plugins** - Load plugins into your application
|
|
75
|
+
4. **Call hooks** - Trigger plugin execution
|
|
76
|
+
|
|
77
|
+
For detailed guides and API reference, see the [full documentation](https://pwwang.github.io/simplug/).
|
|
78
|
+
|
|
79
|
+
## Examples
|
|
80
|
+
|
|
81
|
+
See the [examples](examples/) directory for complete examples:
|
|
82
|
+
- [`examples/toy.py`](examples/toy.py) - A minimal 30-line demo
|
|
83
|
+
- [`examples/complete/`](examples/complete/) - Full example with setuptools entrypoints
|
|
84
|
+
|
|
85
|
+
## License
|
|
86
|
+
|
|
87
|
+
MIT
|
simplug-0.5.8/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
|