Skip to content

Commit eb865bf

Browse files
committed
refactor(sdk): rewrite SDK for ServerlessWorkflow 1.0 specification
Complete rewrite of the Python SDK to conform to the Serverless Workflow specification v1.0, replacing the previous v0.8 implementation. - Replace WorkflowValidator with automatic parsing validation - `base.py`: New base types (Duration, Error, Timeout, Input/Output, etc.) - `authentication.py`: OAuth2, OIDC, Bearer, Basic, Digest auth policies - `call_tasks.py`: HTTP, gRPC, OpenAPI, AsyncAPI, MCP function calls - `tasks.py`: Core task types (Do, Fork, For, Listen, Emit, Set, Switch, Try, Wait, Run, Raise) - `events.py`: Event consumption strategies and correlation - `retry.py`: Retry policies with backoff strategies - `endpoint.py`: Endpoint and catalog definitions - `draw.py`: Workflow visualization using Graphviz (930 lines) - `workflow.py`: Rewritten Workflow class with Document, Schedule, Use components - Replace Pipfile/pipenv with pyproject.toml/uv - Add pre-commit hooks configuration - Add specification submodule for validation testing - Update to Python 3.10+ - Configure ruff for linting/formatting, mypy for type checking - Modernize GitHub Actions workflow - Split into separate lint, test, build jobs - Add ruff linting and formatting checks - Add mypy type checking - Test matrix: Python 3.10, 3.11, 3.12 - Use uv for faster dependency management - Remove old v0.8 test examples (13 JSON files) - Add comprehensive v1.0 spec validation tests (1,748 lines) - Add visualization tests with 74 DOT fixtures - Test against official specification examples via submodule - Update README for v1.0 API with modern examples - Replace state-based examples with task-based patterns - Update installation instructions for uv - Document workflow visualization capabilities - Reference new test locations ## Breaking Changes - Complete API rewrite - no backwards compatibility with v0.8 - All state classes removed - WorkflowValidator removed (validation now automatic) - StateMachineHelper replaced with workflow.render_graph()
1 parent ab7b6d4 commit eb865bf

File tree

176 files changed

+7508
-4801
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

176 files changed

+7508
-4801
lines changed

.github/workflows/python-ci.yml

Lines changed: 53 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,28 +7,66 @@ on:
77
branches: ["main"]
88

99
jobs:
10-
tests:
11-
name: "Python 3.9"
10+
lint:
11+
name: "Lint (ruff, mypy)"
1212
runs-on: "ubuntu-latest"
13+
steps:
14+
- uses: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683" # v4.2.2
15+
- name: Install uv
16+
uses: astral-sh/setup-uv@v5
17+
with:
18+
enable-cache: true
19+
- name: Set up Python
20+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
21+
with:
22+
python-version-file: "pyproject.toml"
23+
- name: Install dependencies
24+
run: uv sync --all-extras
25+
- name: Run ruff (linting)
26+
run: uv run ruff check .
27+
- name: Run ruff (formatting)
28+
run: uv run ruff format --check .
29+
- name: Run mypy
30+
run: uv run mypy serverlessworkflow
1331

32+
test:
33+
name: "Test (Python ${{ matrix.python-version }})"
34+
runs-on: "ubuntu-latest"
35+
strategy:
36+
matrix:
37+
python-version: ["3.10", "3.11", "3.12"]
1438
steps:
1539
- uses: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683" # v4.2.2
16-
- uses: "actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065" # v5.6.0
40+
- name: Install uv
41+
uses: astral-sh/setup-uv@v5
1742
with:
18-
python-version: '3.9'
43+
enable-cache: true
44+
- name: Set up Python ${{ matrix.python-version }}
45+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
46+
with:
47+
python-version: ${{ matrix.python-version }}
1948
- name: Install graphviz
2049
run: |
2150
sudo apt-get update
2251
sudo apt-get install graphviz graphviz-dev
2352
- name: Install dependencies
24-
run: |
25-
pip install pipenv
26-
pip install build
27-
pipenv install --dev --system
28-
pip install setuptools==70.3.0
29-
- name: Test
30-
run: |
31-
pipenv run pytest
32-
- name: Build
33-
run: |
34-
python -m build
53+
run: uv sync --all-extras
54+
- name: Run pytest
55+
run: uv run pytest
56+
57+
build:
58+
name: "Build package"
59+
runs-on: "ubuntu-latest"
60+
needs: [lint, test]
61+
steps:
62+
- uses: "actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683" # v4.2.2
63+
- name: Install uv
64+
uses: astral-sh/setup-uv@v5
65+
with:
66+
enable-cache: true
67+
- name: Set up Python
68+
uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
69+
with:
70+
python-version-file: "pyproject.toml"
71+
- name: Build package
72+
run: uv build

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,6 @@ dmypy.json
132132
.idea
133133
.vscode
134134
*.iml
135+
136+
tests/visualization/outputs/*
137+
tests/visualization/fixtures/*.png

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "submodules/specification"]
2+
path = submodules/specification
3+
url = https://github.com/serverlessworkflow/specification.git

.pre-commit-config.yaml

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Pre-commit hooks for Python projects
2+
# See https://pre-commit.com for more information
3+
# See https://pre-commit.com/hooks.html for more hooks
4+
5+
default_language_version:
6+
python: python3.10
7+
8+
repos:
9+
# General file checks
10+
- repo: https://github.com/pre-commit/pre-commit-hooks
11+
rev: v4.5.0
12+
hooks:
13+
# Prevent giant files from being committed
14+
- id: check-added-large-files
15+
args: [--maxkb=1000]
16+
# Check for files that would conflict in case-insensitive filesystems
17+
- id: check-case-conflict
18+
# Check for merge conflicts
19+
- id: check-merge-conflict
20+
# Check for debugger imports and py37+ breakpoint()
21+
- id: debug-statements
22+
# Check JSON files are valid
23+
- id: check-json
24+
# Check TOML files are valid
25+
- id: check-toml
26+
# Check YAML files are valid
27+
- id: check-yaml
28+
args: [--unsafe] # Allow custom YAML tags
29+
# Ensure files end with a newline
30+
- id: end-of-file-fixer
31+
# Remove trailing whitespace
32+
- id: trailing-whitespace
33+
args: [--markdown-linebreak-ext=md]
34+
# Fix mixed line endings
35+
- id: mixed-line-ending
36+
args: [--fix=lf]
37+
# Check docstrings are valid Python
38+
- id: check-docstring-first
39+
# Check for symlinks that point to nothing
40+
- id: check-symlinks
41+
# Detect private keys
42+
- id: detect-private-key
43+
44+
# Ruff - Fast Python linter and formatter (replaces Black, isort, flake8, pylint)
45+
- repo: https://github.com/astral-sh/ruff-pre-commit
46+
rev: v0.2.1
47+
hooks:
48+
# Run the linter
49+
- id: ruff
50+
args: [--fix, --exit-non-zero-on-fix]
51+
# Run the formatter
52+
- id: ruff-format
53+
54+
# Type checking with mypy
55+
- repo: https://github.com/pre-commit/mirrors-mypy
56+
rev: v1.8.0
57+
hooks:
58+
- id: mypy
59+
additional_dependencies:
60+
- types-PyYAML
61+
- types-requests
62+
args: [--ignore-missing-imports, --warn-unused-configs]
63+
# Only run on serverlessworkflow package, not tests
64+
files: ^serverlessworkflow/
65+
66+
# Security checks
67+
- repo: https://github.com/PyCQA/bandit
68+
rev: 1.7.6
69+
hooks:
70+
- id: bandit
71+
args: [-c, pyproject.toml]
72+
additional_dependencies: ['bandit[toml]']
73+
# Skip tests directory
74+
exclude: ^tests/
75+
76+
# # Check for common security issues
77+
# - repo: https://github.com/Lucas-C/pre-commit-hooks-safety
78+
# rev: v1.3.3
79+
# hooks:
80+
# - id: python-safety-dependencies-check
81+
# files: pyproject.toml
82+
83+
# Markdown formatting
84+
- repo: https://github.com/executablebooks/mdformat
85+
rev: 0.7.17
86+
hooks:
87+
- id: mdformat
88+
additional_dependencies:
89+
- mdformat-gfm # GitHub Flavored Markdown
90+
- mdformat-black # Format code blocks with black style
91+
args: [--wrap, '100']
92+
93+
# Check for spelling errors
94+
- repo: https://github.com/codespell-project/codespell
95+
rev: v2.2.6
96+
hooks:
97+
- id: codespell
98+
args: [--ignore-words-list=crate]
99+
exclude: ^(poetry.lock|package-lock.json|\.git/|\.pytest_cache/|\.mypy_cache/)
100+
101+
# Validate GitHub Actions workflows
102+
- repo: https://github.com/python-jsonschema/check-jsonschema
103+
rev: 0.27.4
104+
hooks:
105+
- id: check-github-workflows
106+
- id: check-dependabot
107+
108+
# YAML formatting
109+
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
110+
rev: v2.12.0
111+
hooks:
112+
- id: pretty-format-yaml
113+
args: [--autofix, --indent, '2']
114+
exclude: ^(\.github/|examples/) # Exclude workflow files and examples
115+
116+
# pyproject.toml formatting
117+
- repo: https://github.com/tox-dev/pyproject-fmt
118+
rev: 1.7.0
119+
hooks:
120+
- id: pyproject-fmt
121+
122+
# Check for outdated Python syntax
123+
- repo: https://github.com/asottile/pyupgrade
124+
rev: v3.15.0
125+
hooks:
126+
- id: pyupgrade
127+
args: [--py310-plus]
128+
129+
# Check requirements files
130+
- repo: https://github.com/Lucas-C/pre-commit-hooks
131+
rev: v1.5.4
132+
hooks:
133+
- id: forbid-crlf
134+
- id: remove-crlf
135+
- id: forbid-tabs
136+
- id: remove-tabs
137+
138+
# Conventional commits
139+
- repo: https://github.com/compilerla/conventional-pre-commit
140+
rev: v3.0.0
141+
hooks:
142+
- id: conventional-pre-commit
143+
stages: [commit-msg]
144+
args: [--force-scope]
145+
146+
# CI configuration
147+
ci:
148+
autofix_commit_msg: |
149+
[pre-commit.ci] auto fixes from pre-commit.com hooks
150+
151+
for more information, see https://pre-commit.ci
152+
autofix_prs: true
153+
autoupdate_branch: ''
154+
autoupdate_commit_msg: '[pre-commit.ci] pre-commit autoupdate'
155+
autoupdate_schedule: weekly
156+
skip: []
157+
submodules: false

Pipfile

Lines changed: 0 additions & 18 deletions
This file was deleted.

0 commit comments

Comments
 (0)