fgmacedo / python-statemachine

Python Finite State Machines made easy.
MIT License
854 stars 84 forks source link

Extra dependencies doesn't seems to install pydot #474

Closed halbow closed 6 days ago

halbow commented 1 week ago

Hi 👋

First of all, thanks for this library, I just started to use it and the interface seems really well designed 🚀

Description

When installing statemachine with the diagrams support, it doesn't seem install pydot. And when installing manually, there's still another error, maybe an incompatibility with a pydot version ?

What I Did

I just run this on the latest python image using docker run -it --rm python:latest bash

root@a3fdbfdd021f:/# pip install python-statemachine[diagrams]
Collecting python-statemachine[diagrams]
  Downloading python_statemachine-2.3.4-py3-none-any.whl.metadata (13 kB)
Downloading python_statemachine-2.3.4-py3-none-any.whl (41 kB)
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 41.3/41.3 kB 3.5 MB/s eta 0:00:00
Installing collected packages: python-statemachine
Successfully installed python-statemachine-2.3.4
WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv

[notice] A new release of pip is available: 24.0 -> 24.2
[notice] To update, run: pip install --upgrade pip
root@a3fdbfdd021f:/# python
Python 3.12.3 (main, May 14 2024, 05:40:55) [GCC 12.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from statemachine import State, StateMachine
>>> 
>>> class ReproBug(StateMachine, strict_states=True):
...     "A workflow machine"
...     new = State("new", initial=True, value="new")
...     finished = State("finished", final=True, value="finished")
...     complete = new.to(finished)
... 
>>> repro_bug = ReproBug()
>>> repro_bug._graph().write_png("img_path.png")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.12/site-packages/statemachine/statemachine.py", line 248, in _graph
    from .contrib.diagram import DotGraphMachine
  File "/usr/local/lib/python3.12/site-packages/statemachine/contrib/diagram.py", line 6, in <module>
    import pydot
ModuleNotFoundError: No module named 'pydot'
>>>
>>> import pydot
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ModuleNotFoundError: No module named 'pydot'
[EDIT] looks like the second error has been fixed by https://github.com/fgmacedo/python-statemachine/pull/470 but not released yet If I install `graphviz` and `libgraphviz-dev` and `pydot`, I still have the following error: ```console root@ce911605e8d1:/# apt update Get:1 http://deb.debian.org/debian bookworm InRelease [151 kB] [REDACTED] 67 packages can be upgraded. Run 'apt list --upgradable' to see them. root@ce911605e8d1:/# apt install graphviz libgraphviz-dev Reading package lists... Done [REDACTED] Processing triggers for fontconfig (2.14.1-4) ... root@ce911605e8d1:/# pip install pydot Collecting pydot Downloading pydot-3.0.1-py3-none-any.whl.metadata (9.9 kB) Collecting pyparsing>=3.0.9 (from pydot) Downloading pyparsing-3.1.4-py3-none-any.whl.metadata (5.1 kB) Downloading pydot-3.0.1-py3-none-any.whl (22 kB) Downloading pyparsing-3.1.4-py3-none-any.whl (104 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 104.1/104.1 kB 5.2 MB/s eta 0:00:00 Installing collected packages: pyparsing, pydot Successfully installed pydot-3.0.1 pyparsing-3.1.4 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv [notice] A new release of pip is available: 24.0 -> 24.2 [notice] To update, run: pip install --upgrade pip root@ce911605e8d1:/# pip install python-statemachine Collecting python-statemachine Downloading python_statemachine-2.3.4-py3-none-any.whl.metadata (13 kB) Downloading python_statemachine-2.3.4-py3-none-any.whl (41 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 41.3/41.3 kB 2.8 MB/s eta 0:00:00 Installing collected packages: python-statemachine Successfully installed python-statemachine-2.3.4 WARNING: Running pip as the 'root' user can result in broken permissions and conflicting behaviour with the system package manager. It is recommended to use a virtual environment instead: https://pip.pypa.io/warnings/venv [notice] A new release of pip is available: 24.0 -> 24.2 [notice] To update, run: pip install --upgrade pip root@ce911605e8d1:/# python Python 3.12.3 (main, May 14 2024, 05:40:55) [GCC 12.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> from statemachine import State, StateMachine >>> >>> class ReproBug(StateMachine, strict_states=True): ... "A workflow machine" ... new = State("new", initial=True, value="new") ... finished = State("finished", final=True, value="finished") ... complete = new.to(finished) ... >>> repro_bug = ReproBug() >>> repro_bug._graph().write_png("res.png") "dot" with args ['-Tpng', '/tmp/tmpguib_k3o'] returned code: 1 stdout, stderr: b'' b"Warning: syntax ambiguity - badly delimited number '10p' in line 4 of /tmp/tmpguib_k3o splits into two tokens\nWarning: syntax ambiguity - badly delimited number '1p' in line 6 of /tmp/tmpguib_k3o splits into two tokens\nError: /tmp/tmpguib_k3o: syntax error in line 6 near ','\n" Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.12/site-packages/pydot/core.py", line 177, in __write_method self.write(path, format=f, prog=prog, encoding=encoding) File "/usr/local/lib/python3.12/site-packages/pydot/core.py", line 1708, in write s = self.create(prog, format, encoding=encoding) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "/usr/local/lib/python3.12/site-packages/pydot/core.py", line 1825, in create assert process.returncode == 0, ( ^^^^^^^^^^^^^^^^^^^^^^^ AssertionError: "dot" with args ['-Tpng', '/tmp/tmpguib_k3o'] returned code: 1 >>> ``` Looks like the real error from pydot is `Error: /tmp/tmpguib_k3o: syntax error in line 6 near ','\n` but I'm not sure how to troubleshoot further than that
fgmacedo commented 1 week ago

I'll start a release process for the #470 , I think this is also related.

fgmacedo commented 1 week ago

Hi @halbow , I've released 2.3.5. Please let me know if this fixes the issue for you.

Best regards!

halbow commented 6 days ago

I don't have the second error anymore with 2.3.5 👍 But pydot is still missing when adding [diagrams] It works when installing manually the deb package graphviz and libgraphviz-dev, then install python-statemachine[diagrams] and I have to manually install pydot even when passing the diagrams optional dependency which is supposed to install it

fgmacedo commented 6 days ago

Thanks @halbow , I got the issue!

I was declaring the pydot dependence on the dev group instead of an optional one: https://python-poetry.org/docs/pyproject#extras

BTW, I'm planning to switch from Poetry to UV.

Thanks again for reporting this!