Skip to content

Commit be7b641

Browse files
authored
Merge pull request #30 from ATNoG/feature/graph
Add workflow graph generation functionality
2 parents bc80a31 + 9df3424 commit be7b641

File tree

12 files changed

+1058
-78
lines changed

12 files changed

+1058
-78
lines changed

.github/workflows/python-ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ jobs:
1616
- uses: "actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065" # v5.6.0
1717
with:
1818
python-version: '3.9'
19+
- name: Install graphviz
20+
run: |
21+
sudo apt-get update
22+
sudo apt-get install graphviz graphviz-dev
1923
- name: Install dependencies
2024
run: |
2125
pip install pipenv

Pipfile

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,12 @@ name = "pypi"
77
jsonschema = "==4.4.0"
88
pyyaml = "==6.0"
99
requests = "*"
10+
pygraphviz = "==1.11"
11+
transitions = "==0.9.2"
1012

1113
[dev-packages]
1214
pytest = "==6.2.5"
1315
pytest-runner = "==5.3.1"
1416

1517
[requires]
16-
python_version = "3"
18+
python_version = "3.9"

Pipfile.lock

Lines changed: 202 additions & 71 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,4 +134,33 @@ WorkflowValidator(Workflow(workflow)).validate()
134134
```
135135
The `validate` method will raise an exception if the provided workflow does not complaint specification.
136136

137-
You can see a full example in the [test_workflow_validator](tests/serverlessworkflow/sdk/test_workflow_validator.py) file
137+
You can see a full example in the [test_workflow_validator](tests/serverlessworkflow/sdk/test_workflow_validator.py) file
138+
139+
## Generate workflow state machine and graph
140+
141+
To generate the workflow graph diagram:
142+
143+
```python
144+
from serverlessworkflow.sdk.workflow import Workflow
145+
from serverlessworkflow.sdk.state_machine_helper import StateMachineHelper
146+
147+
def main():
148+
subflows = []
149+
with open("tests/examples/graph.json") as f:
150+
workflow = Workflow.from_source(f.read())
151+
with open("tests/examples/advertise-listing.json") as f:
152+
subflows.append(Workflow.from_source(f.read()))
153+
with open("tests/examples/second-subgraph.json") as f:
154+
subflows.append(Workflow.from_source(f.read()))
155+
machine_helper = StateMachineHelper(workflow=workflow, get_actions=True, subflows=subflows)
156+
machine_helper.draw('diagram.svg')
157+
158+
159+
if __name__ == "__main__":
160+
main()
161+
```
162+
163+
The `StateMachineHelper` can be set with `get_actions` as `False` and the produced diagram will not represent the actions inside each state (it will only create a diagram with the states and their transitions). Moreover, the developer may not give any `subflows`, and they simply will not be generated.
164+
As for the `draw` method, the developer can also specify `graph_engine='mermaid'`. In that case, the method will not generate a figure, but rather the Mermaid code that can be executed, for instance, in the [Mermaid Live Editor](https://mermaid.live).
165+
166+
It is also possible to only generate the workflow state machine. An example on how to do so can be analyzed in the [state_machine_helper](serverlessworkflow/sdk/state_machine_helper.py) source code.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy