Contributing¶
Development Setup¶
git clone https://github.com/yourusername/supervice.git
cd supervice
python3 -m venv .venv
source .venv/bin/activate
pip install -e ".[docs]"
Running Tests¶
python3 -m pytest tests/ -v
All 63 tests should pass. Tests use unittest with asyncio support.
Code Quality¶
All code must pass these checks before merging:
mypy --strict supervice/
ruff check supervice/
ruff format --check supervice/
Type Checking¶
Supervice uses mypy --strict. Rules:
All functions must have type annotations
No
Anytypes unless absolutely necessaryNo
type: ignoreor@ts-expect-errorsuppressionsUnion types use
X | Ysyntax (Python 3.10+)
Linting¶
Ruff is configured with these rule sets:
Rule Set |
Description |
|---|---|
|
pycodestyle errors |
|
pyflakes |
|
pycodestyle warnings |
|
isort (import sorting) |
|
pep8-naming |
|
pyupgrade |
|
flake8-bugbear |
Line length: 100 characters.
Project Structure¶
supervice/
├── supervice/ # Source code
│ ├── __init__.py
│ ├── main.py # Daemon entry point
│ ├── core.py # Supervisor orchestrator
│ ├── process.py # Process lifecycle
│ ├── config.py # Config parser
│ ├── models.py # Data models
│ ├── events.py # EventBus
│ ├── rpc.py # RPC server
│ ├── client.py # CLI client
│ ├── health.py # Health checks
│ └── logger.py # Logging
├── tests/ # Test suite
├── docs/ # Sphinx documentation
├── pyproject.toml # Project config
├── README.md
└── LICENSE
Making Changes¶
Adding a Configuration Option¶
Add the field to the appropriate dataclass in
models.pyParse it in
config.py(add validation if needed)Use it in
process.pyorcore.pyAdd tests
Update documentation
Adding an RPC Command¶
Add the command name to
VALID_COMMANDSinrpc.pyAdd a handler in
RPCServer.process_request()Add a CLI subcommand in
client.pyAdd a method to the
ControllerclassAdd tests
Update documentation
Adding a Process State¶
Define the state constant in
process.pyAdd the corresponding
EventTypeinevents.pyAdd the state mapping in
Process._change_state()Update state transition logic in
Process.supervise()Add tests
Update documentation
Constraints¶
Zero dependencies — Do not add external packages. Use stdlib only.
Python 3.10+ — Use modern syntax (
match,X | Yunions, etc.)Unix-only — No Windows compatibility needed
Async-first — All I/O must use
asyncio
Building Documentation¶
cd docs
make html
Output is in docs/_build/html/. Open index.html in a browser.
Code Style Tips¶
Prefer
%string formatting over f-strings (existing codebase convention for log messages)Use
shlex.split()for command parsingUse
asyncio.wait_for()with timeouts, never bareawaiton external I/OProcess groups: always
os.killpg()instead ofprocess.kill()