-
-
Notifications
You must be signed in to change notification settings - Fork 103
feat: Nested states (compound / parallel) and support for SCXML (test suit) #501
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
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@ ## develop #501 +/- ## =========================================== - Coverage 100.00% 96.21% -3.79% =========================================== Files 25 31 +6 Lines 1631 3227 +1596 Branches 257 466 +209 =========================================== + Hits 1631 3105 +1474 - Misses 0 71 +71 - Partials 0 51 +51
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
ecc7957 to
1b74bf5
Compare
f1edb7f to
1e7f40d
Compare
0890680 to
35f4bed
Compare
e2b6907 to
b392cbd
Compare
Is this in a state (🤣) that I could try it out? I have several use-cases where the sub-state functionality would be useful and I'd be glad to give feedback if I run into issues.
Note, the user experience I had expected looked something like this:
class SubMachine(StateMachine): test = State(initial=True) test_complete = State(final=True) next = test.to(test_complete) class TestSM(StateMachine): initial_state = State(initial=True) sub_machine_as_state = SubMachine() some_other_state = State(final=True) goto_sub_machine = initial_state.to(sub_machine_as_state) goto_finish = sub_machine_as_state.to(some_other_state)
And then something like
sm = TestSM() sm.send('goto_sub_machine') sm.send('next') # TestSM now has the submachine states as states it can traverse. sm.send('goto_finish')
...hen entering a top level final state the SM terminates
...for TypedDict and | operator
...es parameter since scxml don't expect that the graph should have a single component
...tance should keep the same
93eaa58 to
eec118a
Compare
fgmacedo
commented
Jan 26, 2025
@comalice Thanks for your interest on this. I think the internals are usable, but the external API may still change as I've not yet finished documenting and exploring examples using the Python API.
There are many new *.scxml files that I've used to fine tune the internal behaviour for composite and parallel states, and the create_machine_class_from_definition is more stable and mature as a way to construct the statemachine from a dict-like definition similar to the way SCXML works. I'm planning to also add a YAML parser.
The only notable non implemented feature is the <invoke> and thus cross sending events between distinct statemachines.
Note, the user experience I had expected looked something like this:
class SubMachine(StateMachine): test = State(initial=True) test_complete = State(final=True) next = test.to(test_complete) class TestSM(StateMachine): initial_state = State(initial=True) sub_machine_as_state = SubMachine() some_other_state = State(final=True) goto_sub_machine = initial_state.to(sub_machine_as_state) goto_finish = sub_machine_as_state.to(some_other_state)
I may try to implement this syntax, but I think that will be hard to get it right. The initial proposal that I'm implement is the one that is in the description, using the internal namespace of nested Parallel and Compose classes to build hierarchy.
Feel free to fork and test, please let me know if you expecience any issues.
Since this got into a huge PR and almost stable, I'm considering merging and finish the work with smaller PRs.
...ateMachine for backwards compatibility
Quality Gate Failed Quality Gate failed
Failed conditions
4 Security Hotspots
Uh oh!
There was an error while loading. Please reload this page.
Another approach for #329.
By supporting the test cases defined at https://www.w3.org/Voice/2013/scxml-irp/ we can incorporate small functionalities until we get covered by the full spec.
Experimental Python class API
Tests:
Pending tasks
Donedata failing tests (test.scxml)
Those tests have a corresponding
test<id>.fail.scxmldescribing the error output.donedata. Can be anon_enter_<state>that returns a dict.donedata. Can be anon_enter_<state>that returns a dict.