pytransitions / transitions

A lightweight, object-oriented finite state machine implementation in Python with many extensions
MIT License
5.49k stars 524 forks source link

can't use mermaid example #680

Closed dstumbo closed 1 day ago

dstumbo commented 4 days ago

Used the following code (copied from example at https://github.com/pytransitions/transitions):

from transitions.extensions.diagrams import HierarchicalGraphMachine
import pyperclip

states = ['A', 'B', {'name': 'C',
                     'final': True,
                     'parallel': [{'name': '1', 'children': ['a', {"name": "b", "final": True}],
                                   'initial': 'a',
                                   'transitions': [['go', 'a', 'b']]},
                                  {'name': '2', 'children': ['a', {"name": "b", "final": True}],
                                   'initial': 'a',
                                   'transitions': [['go', 'a', 'b']]}]}]
transitions = [['reset', 'C', 'A'], ["init", "A", "B"], ["do", "B", "C"]]

m = HierarchicalGraphMachine(states=states, transitions=transitions, initial="A", show_conditions=True,
                             title="Mermaid", graph_engine="mermaid", auto_transitions=False)
m.init()

pyperclip.copy(m.get_graph().draw(None))  # using pyperclip for convenience
print("Graph copied to clipboard!")

results in:

ValueError: Passing arguments dict_keys(['graph_engine']) caused an inheritance error: object.__init__() takes exactly one argument (the instance to initialize)

Versions used in venv:

Package     Version
----------- -------
pip         24.1.1
pyperclip   1.9.0
setuptools  68.2.2
six         1.16.0
transitions 0.9.1

Am i doing something wrong or is this a bug?

aleneum commented 1 day ago

Hello @dstumbo,

mermaid support was recently introduced in transitions 0.9.2 and has not been released via PYPI yet.

You could try to install transitions via GitHub:

# pip  install --upgrade pip wheel setuptools
pip install git+https://github.com/pytransitions/transition
dstumbo commented 1 day ago

Thanks for the quick response! I will try using 0.9.2, you can close this.