Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: Improvements on the docs, removing jupyterlite #331

Merged
merged 1 commit into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 8 additions & 8 deletions README.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
====================
Python State Machine
====================
===================
Python StateMachine
===================


.. image:: https://img.shields.io/pypi/v/python-statemachine.svg
Expand Down Expand Up @@ -112,7 +112,7 @@ Then start sending events:
>>> traffic_light.cycle()
'Running cycle from green to yellow'

You can inspect about the current state:
You can inspect the current state:

>>> traffic_light.current_state.id
'yellow'
Expand Down Expand Up @@ -151,13 +151,13 @@ Or over events:
>>> [t.name for t in traffic_light.events]
['cycle', 'go', 'slowdown', 'stop']

Call an event by it's name:
Call an event by its name:

>>> traffic_light.cycle()
Don't move.
'Running cycle from yellow to red'

Or sending an event with the event name:
Or send an event with the event name:

>>> traffic_light.send('cycle')
Go ahead!
Expand All @@ -180,8 +180,8 @@ True
And you can pass arbitrary positional or keyword arguments to the event, and
they will be propagated to all actions and callbacks:

>>> traffic_light.cycle(message="Please, now slowdon.")
'Running cycle from green to yellow. Please, now slowdon.'
>>> traffic_light.cycle(message="Please, now slowdown.")
'Running cycle from green to yellow. Please, now slowdown.'


Models
Expand Down
17 changes: 8 additions & 9 deletions docs/actions.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Actions

An action is the way a StateMachine can cause things to happen in the
Action is the way a StateMachine can cause things to happen in the
outside world, and indeed they are the main reason why they exist at all.

The main point of introducing a state machine is for the
actions to be invoked at the right times, depending on the sequence of events
and the state of the guards.

Actions are most commonly performed on entry or exit of a state, although
it is possible to add them before / after a transition.
it is possible to add them before/after a transition.

There are several action callbacks that you can define to interact with a
StateMachine in execution.
Expand Down Expand Up @@ -257,9 +257,9 @@ You can also declare an event while also adding a callback:

```

Note that with this syntax, the result `loop` that is present on the `ExampleStateMachine.loop`
Note that with this syntax, the resulting `loop` that is present on the `ExampleStateMachine.loop`
namespace is not a simple method, but an {ref}`event` trigger. So it only executes if the
StateMachine is on the right state.
StateMachine is in the right state.

So, you can use the event-oriented approach:

Expand All @@ -275,8 +275,7 @@ On loop

## Other callbacks

In addition to {ref}`actions`, you can specify {ref}`validators-and-guards` that are checked
before an transition is started. They are meant to stop a transition to occur.
In addition to {ref}`actions`, you can specify {ref}`validators and guards` that are checked before a transition is started. They are meant to stop a transition to occur.

```{seealso}
See {ref}`guards` and {ref}`validators`.
Expand Down Expand Up @@ -320,7 +319,7 @@ Actions and Guards will be executed in the following order:

python-statemachine implements a custom dispatch mechanism on all those available Actions and
Guards, this means that you can declare an arbitrary number of `*args` and `**kwargs`, and the
library will match your method signature of what's expect to receive with the provided arguments.
library will match your method signature of what's expected to receive with the provided arguments.

This means that if on your `on_enter_<state.id>()` or `on_execute_<event>()` method, you need to know
the `source` ({ref}`state`), or the `event` ({ref}`event`), or access a keyword
Expand All @@ -346,10 +345,10 @@ For your convenience, all these parameters are available for you on any Action o
: The {ref}`Event` that was triggered.

`source`
: The {ref}`State` the statemachine was when the {ref}`Event` started.
: The {ref}`State` the state machine was when the {ref}`Event` started.

`state`
: The current {ref}`State` of the statemachine.
: The current {ref}`State` of the state machine.

`target`
: The destination {ref}`State` of the transition.
Expand Down
11 changes: 0 additions & 11 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
"sphinx.ext.viewcode",
"sphinx.ext.autosectionlabel",
"sphinx_gallery.gen_gallery",
"jupyterlite_sphinx",
]

# Add any paths that contain templates here, relative to this directory.
Expand Down Expand Up @@ -243,11 +242,6 @@
"event": "{ref}`event`",
}

# JupyterLite
jupyterlite_config = "jupyterlite_config.json"
jupyterlite_contents = ["./examples", "./auto_examples"]
jupyterlite_dir = "./auto_examples"

# Github

html_context = {
Expand All @@ -271,10 +265,5 @@
"min_reported_time": 9999,
"thumbnail_size": (400, 280),
"image_scrapers": (MachineScraper(project_root),),
"first_notebook_cell": (
"# import piplite\n"
"# await piplite.install('python-statemachine[diagrams]')\n"
"# import patch_repr_svg\n"
),
"reset_modules": [],
}
24 changes: 22 additions & 2 deletions docs/diagram.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Diagrams

You can generate diagrams from your statemachine.
You can generate diagrams from your state machine.

```{note}
This functionality depends on [pydot](https://github.com/pydot/pydot), it means that you need to
Expand All @@ -25,7 +25,7 @@ To install Graphviz, you can visit the [Graphviz website](https://graphviz.org/)
instructions for your operating system. Alternatively, you can use a package manager to install
Graphviz. For example, on Debian-based systems (such as Ubuntu), you can use the following command:

apt-get install graphviz
sudo apt install graphviz

```

Expand Down Expand Up @@ -81,6 +81,16 @@ The current state is also highlighted:
![OrderControl](images/order_control_machine_processing.png)


```{hint}

A handy shortcut to have the graph representation:

```py
>>> machine._graph()
<pydot.Dot ...

```

## Generate from the command line

You can also generate a diagram from the command line using the `statemachine.contrib.diagram` as a module.
Expand Down Expand Up @@ -118,3 +128,13 @@ Machines instances are automatically displayed as a diagram when used on Jupyter


![Approval machine on JupyterLab](images/lab_approval_machine_accepted.png)


## Don't want to install Graphviz


```{eval-rst}
.. autofunction:: statemachine.contrib.diagram.quickchart_write_svg
```

![OrderControl](images/oc_machine_processing.svg)
38 changes: 0 additions & 38 deletions docs/examples/patch_repr_svg.py

This file was deleted.

90 changes: 90 additions & 0 deletions docs/images/_oc_machine_processing.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.