Skip to content

Commit

Permalink
Merge branch 'release/2.3.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
fgmacedo committed Sep 11, 2024
2 parents a1501f9 + 97e4576 commit 0610c9d
Show file tree
Hide file tree
Showing 14 changed files with 77 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
run: poetry install --no-interaction --no-root --all-extras
#----------------------------------------------
# run ruff
#----------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
key: venv-${{ runner.os }}-${{ matrix.python-version }}-${{ hashFiles('**/poetry.lock') }}
- name: Install dependencies
if: steps.cached-poetry-dependencies.outputs.cache-hit != 'true'
run: poetry install --no-interaction --no-root
run: poetry install --no-interaction --no-root --all-extras
- name: Test with pytest
run: |
source .venv/bin/activate
Expand Down
2 changes: 1 addition & 1 deletion docs/contributing.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ Ready to contribute? Here's how to set up `python-statemachine` for local develo

1. Run `poetry install` once to install all the dependencies and create a virtual environment::

poetry install
poetry install --all-extras

1. Run `poetry shell` to enter the provided virtual

Expand Down
9 changes: 9 additions & 0 deletions docs/releases/2.3.6.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# StateMachine 2.3.6

*September 11, 2024*


## Bugfixes in 2.3.6

- Fixes [#474](https://github.com/fgmacedo/python-statemachine/issues/474) install with extra was not working to install `pydot`.
- Fixes [#480](https://github.com/fgmacedo/python-statemachine/issues/480) error when trying to trigger an event inside the initial callback.
1 change: 1 addition & 0 deletions docs/releases/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Below are release notes through StateMachine and its patch releases.
```{toctree}
:maxdepth: 2
2.3.6
2.3.5
2.3.4
2.3.3
Expand Down
8 changes: 4 additions & 4 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "python-statemachine"
version = "2.3.5"
version = "2.3.6"
description = "Python Finite State Machines made easy."
authors = ["Fernando Macedo <[email protected]>"]
maintainers = [
Expand Down Expand Up @@ -33,14 +33,14 @@ classifiers = [
"Intended Audience :: Developers",
]

[tool.poetry.extras]
diagrams = ["pydot"]

[tool.poetry.dependencies]
python = ">=3.7"
pydot = { version = ">=2.0.0", optional = true }

[tool.poetry.extras]
diagrams = ["pydot"]

[tool.poetry.group.dev.dependencies]
pydot = "^2.0.0"
ruff = "^0.4.8"
pre-commit = "*"
mypy = "*"
Expand Down
2 changes: 1 addition & 1 deletion statemachine/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

__author__ = """Fernando Macedo"""
__email__ = "[email protected]"
__version__ = "2.3.5"
__version__ = "2.3.6"

__all__ = ["StateMachine", "State"]
1 change: 1 addition & 0 deletions statemachine/engines/async_.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

class AsyncEngine:
def __init__(self, sm: "StateMachine", rtc: bool = True):
sm._engine = self
self.sm = proxy(sm)
self._sentinel = object()
if not rtc:
Expand Down
1 change: 1 addition & 0 deletions statemachine/engines/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

class SyncEngine:
def __init__(self, sm: "StateMachine", rtc: bool = True):
sm._engine = self
self.sm = proxy(sm)
self._sentinel = object()
self._rtc = rtc
Expand Down
9 changes: 5 additions & 4 deletions statemachine/statemachine.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,14 @@ def __init__(
)
self._put_nonblocking(trigger_data)

self._engine = self._get_engine(rtc)
self._engine: AsyncEngine | SyncEngine | None = None
self._select_engine(rtc)

def _get_engine(self, rtc: bool):
def _select_engine(self, rtc: bool):
if self._callbacks_registry.has_async_callbacks:
return AsyncEngine(self, rtc=rtc)
AsyncEngine(self, rtc=rtc)
else:
return SyncEngine(self, rtc=rtc)
SyncEngine(self, rtc=rtc)

def activate_initial_state(self):
result = self._engine.activate_initial_state()
Expand Down
4 changes: 2 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ class TrafficLightMachine(StateMachine):
stop = yellow.to(red)
go = red.to(green)

def _get_engine(self, rtc: bool):
return engine(self, rtc)
def _select_engine(self, rtc: bool):
engine(self, rtc)

return TrafficLightMachine

Expand Down
4 changes: 2 additions & 2 deletions tests/test_transitions.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ class TestStateMachine(StateMachine):

loop = initial.to.itself(internal=internal)

def _get_engine(self, rtc: bool):
return engine(self, rtc)
def _select_engine(self, rtc: bool):
engine(self, rtc)

def on_exit_initial(self):
calls.append("on_exit_initial")
Expand Down
43 changes: 43 additions & 0 deletions tests/testcases/issue480.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@


### Issue 480

A StateMachine that exercises the example given on issue
#[480](https://github.com/fgmacedo/python-statemachine/issues/480).

Should be possible to trigger an event on the initial state activation handler.

```py
>>> from statemachine import StateMachine, State
>>>
>>> class MyStateMachine(StateMachine):
... State_1 = State(initial=True)
... State_2 = State()
... Trans_1 = State_1.to(State_2)
...
... def __init__(self):
... super(MyStateMachine, self).__init__()
...
... def on_enter_State_1(self):
... print("Entering State_1 state")
... self.long_running_task()
...
... def on_exit_State_1(self):
... print("Exiting State_1 state")
...
... def on_enter_State_2(self):
... print("Entering State_2 state")
...
... def long_running_task(self):
... print("long running task process started")
... self.Trans_1()
... print("long running task process ended")
...
>>> sm = MyStateMachine()
Entering State_1 state
long running task process started
long running task process ended
Exiting State_1 state
Entering State_2 state

```

0 comments on commit 0610c9d

Please sign in to comment.