Skip to content

Commit

Permalink
fix: Patch to get the statemachine diagram on jupyterlite
Browse files Browse the repository at this point in the history
  • Loading branch information
fgmacedo committed Jan 13, 2023
1 parent ac99985 commit abbd83c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
8 changes: 4 additions & 4 deletions docs/auto_examples/order_control_rich_model_machine.rst
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ Since there's still $6 left to fulfill the payment, we cannot process the order.
.. code-block:: none
OrderControl(model=<__main__.Order object at 0x7f5730b462e0>, state_field='state', current_state='waiting_for_payment')
OrderControl(model=<__main__.Order object at 0x7fa3456ef2e0>, state_field='state', current_state='waiting_for_payment')
Expand Down Expand Up @@ -258,7 +258,7 @@ Now paying the left amount, we can proceed.
.. code-block:: none
OrderControl(model=<__main__.Order object at 0x7f5730b462e0>, state_field='state', current_state='processing')
OrderControl(model=<__main__.Order object at 0x7fa3456ef2e0>, state_field='state', current_state='processing')
Expand Down Expand Up @@ -292,7 +292,7 @@ Now paying the left amount, we can proceed.
.. code-block:: none
OrderControl(model=<__main__.Order object at 0x7f5730b462e0>, state_field='state', current_state='shipping')
OrderControl(model=<__main__.Order object at 0x7fa3456ef2e0>, state_field='state', current_state='shipping')
Expand Down Expand Up @@ -391,7 +391,7 @@ Just checking the final expected state
.. code-block:: none
OrderControl(model=<__main__.Order object at 0x7f5730b462e0>, state_field='state', current_state='completed')
OrderControl(model=<__main__.Order object at 0x7fa3456ef2e0>, state_field='state', current_state='completed')
Expand Down
18 changes: 8 additions & 10 deletions docs/examples/patch_repr_svg.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
import sys


def patch__repr_svg_(): # pragma: no cover
def patch__repr_html_(): # pragma: no cover
"""
You're running this example directly from your browser! By using the amazing
https://pyodide.org/.
Since we're in a browser, the default dependency of GraphViz installed locally don't work. So
this cell is an option to see our examples and try the library on the fly without the need to
install anything.
We've to patch `StateMachine._repr_svg_` to retrieve the svg diagram online as the graphviz is
not available.
as an option to see our examples and try the library on the fly without the need to
install anything we'll patch `StateMachine._repr_html_` to retrieve the svg diagram online as
the graphviz is not available.
This method will serialize and request the graph to an external service: https://quickchart.io.
By using de diagrams support you trust quickchart.io. Please read
Expand All @@ -28,11 +26,11 @@ def show_sm(sm):
)
return '<svg width="auto" height="auto"><image xlink:href="{}"/>'.format(url)

StateMachine._repr_svg_ = show_sm
StateMachine._repr_html_ = show_sm


if sys.platform == "emscripten": # pragma: no cover
# https://pyodide.org/ is the runtime!
patch__repr_svg_()
print(patch__repr_svg_.__doc__)
print("'StateMachine._repr_svg_' patched!")
patch__repr_html_()
print(patch__repr_html_.__doc__)
print("'StateMachine._repr_html_' patched!")

0 comments on commit abbd83c

Please sign in to comment.