Commit Graph

69 Commits

Author SHA1 Message Date
Riccardo Pittau fed5f89755 Remove six dependency
We run on Python 3 only, time to remove six dependency

Also fix l-c for new pip-resolver and move pep8 deps
in tox.ini to avoid conflicts.

And since we're here, update pre-commit config to support correct
hacking version.

Change-Id: Ibbe733c4be37d1a9dd9149d491591ef2e50dad6a
2020-12-12 08:08:06 +01:00
Hervé Beraud dee4179fa0 Stop to use the __future__ module.
The __future__ module [1] was used in this context to ensure compatibility
between python 2 and python 3.

We previously dropped the support of python 2.7 [2] and now we only support
python 3 so we don't need to continue to use this module and the imports
listed below.

Imports commonly used and their related PEPs:
- `division` is related to PEP 238 [3]
- `print_function` is related to PEP 3105 [4]
- `unicode_literals` is related to PEP 3112 [5]
- `with_statement` is related to PEP 343 [6]
- `absolute_import` is related to PEP 328 [7]

[1] https://docs.python.org/3/library/__future__.html
[2] https://governance.openstack.org/tc/goals/selected/ussuri/drop-py27.html
[3] https://www.python.org/dev/peps/pep-0238
[4] https://www.python.org/dev/peps/pep-3105
[5] https://www.python.org/dev/peps/pep-3112
[6] https://www.python.org/dev/peps/pep-0343
[7] https://www.python.org/dev/peps/pep-0328

Change-Id: Ib32cd47131b154509357b228b2e97548cf5ba4e4
2020-06-02 19:34:29 +02:00
ChangBo Guo(gcb) f620f2aa87 Remove kwarg default_start_state in the machine constructor
The usage of 'default_start_state' via the machine constructor is
deprecated usage of the 'default_start_state' property setter is
recommended. And there is no usage of default_start_state as
constructor argument in other projects [1]. It's safe to remove
it now.

[1] http://codesearch.openstack.org/?q=default_start_state&i=nope&files=&repos=

Change-Id: I454d453d513ae670ddd664d1d8b20ecf8d1202dd
2017-08-22 14:05:16 +08:00
Jenkins 05dbe3dbb0 Merge "Removes unnecessary utf-8 encoding" 2017-01-12 16:50:14 +00:00
Cao Xuan Hoang fa92789024 Removes unnecessary utf-8 encoding
The following files added utf-8 encoding but never used. So we can
remove them at all.

automaton/_utils.py
automaton/converters/pydot.py
automaton/exceptions.py
automaton/machines.py
automaton/runners.py
automaton/tests/test_fsm.py

Change-Id: I6b3b4f3b0b53cc4223cdea02e3cda8cd548a4115
2016-12-22 10:08:52 +07:00
gecong1973 0a2eff6a20 Replace six.iteritems() with .items()
1.As mentioned in [1], we should avoid using
six.iteritems to achieve iterators. We can use
dict.items instead, as it will return iterators
in PY3 as well. And dict.items/keys will more
readable. 2.In py2, the performance about list
should be negligible, see the link [2].
[1] https://wiki.openstack.org/wiki/Python3
[2] http://lists.openstack.org/pipermail/openstack-dev/2015-June/066391.html

Change-Id: Id4355f3f96c830e3116ef6f6e0a17d2ed0dcd1f4
2016-11-28 10:43:14 +08:00
Joshua Harlow 818b7998b4 Ensure state space can also pass on_enter/exit callbacks
Change-Id: If455f9799b9a3f1a5489d50f8cac8c75143bbb58
2016-01-27 11:14:19 -08:00
Joshua Harlow 64c51a554c Ensure machine special method(s) include in generated docs
Without explicitly mentioning that it should have its docs
generated sphinx won't generate docs for it, so ensure that
we list __iter__ and __contains__ so that it does get
generated docs.

Also fixes 'default_start_state' docs which were not showing
up since they were on the setter method vs the getter method.

Change-Id: I83d02a3604678d16b16f6da5384ff10543af850f
2016-01-07 13:01:52 -08:00
Jenkins 20c05120fd Merge "Provide a finite machine build() method" 2015-09-16 12:00:25 +00:00
Joshua Harlow ae7d6df7f4 Provide a finite machine build() method
This method can be quite useful to simplify building a
state-machine in a automated manner.

Change-Id: I1428f95bad1637c565745673f5ce018d9439f442
2015-09-14 11:25:28 -07:00
Joshua Harlow 2276f53661 Allow for raising on duplicate transition registration
Instead of always by default overwriting an existing
transition from a state to another state on a given event
make it possible to avoid that overwriting (and raise
a duplication exception instead).

Change-Id: I7f5c1abf3b8737b71033250f7754595fbb28589a
2015-09-02 17:04:52 -07:00
Jenkins 183882193c Merge "Allow providing a state-name translation dict" 2015-07-30 20:51:49 +00:00
Jenkins d434212af8 Merge "Ensure doctesting and doc8 testing done in py27 env" 2015-07-20 22:01:42 +00:00
Joshua Harlow 01ee0381fe Ensure doctesting and doc8 testing done in py27 env
This ensures that sphinx doc tests are ran and validated
and also runs doc8 to ensure style checks are done and adjusts
some of the current examples and code to fix found issues.

Also fixes the `get_callback_name` method which needs to check
if the __module__ is non-none (since it appears sphinx somehow
triggers it being none).

Change-Id: I54daecff219a9e9be71ff382d36fc2d5e67360cf
2015-07-16 14:47:27 -07:00
Jenkins fdfb1e0b3c Merge "Allow providing and using a 'nested_start_state_fetcher'" 2015-07-14 11:22:41 +00:00
Jenkins daa40a2421 Merge "Document `process_event` return and expose return namedtuple type" 2015-07-10 00:06:45 +00:00
Joshua Harlow c6989a0867 Document `process_event` return and expose return namedtuple type
Change-Id: I50f4695dd24c7f1f947a77b66b871360d2271e91
2015-07-09 14:19:45 -07:00
Joshua Harlow 151f447a8a Allow providing and using a 'nested_start_state_fetcher'
For hierarchical machines it seems like it would be
quite useful to allow nested machines to initialize to
states that are not just none so to enable this allow for
providing a callback that will be used to determine the
callback for all nested machines (and nested-nested
machines) so that they can be initialized to the users
desire.

Change-Id: I45a0c0e0c2a976e0df094e6c728f943766be7c7a
2015-07-06 12:09:03 -07:00
Joshua Harlow b6f1dc066e Allow providing a state-name translation dict
Certain projects use ``None`` as a state (and it is
possible for other projects to use other hashable
objects as states) so make it possible to provide
a renaming dict that can provide an alternative name
mapping.

This allows those projects to translate their states
into something useful on conversion.

Change-Id: I1debeaf0c1d7a7af58376ada50b014cf5de40746
2015-07-06 11:57:26 -07:00
Jenkins 3111444bd5 Merge "Add and use a callback name fetching utility function" 2015-07-01 14:24:29 +00:00
Jenkins d30e169cf9 Merge "When a state has no transitions show its own `on_exit` and `on_enter`" 2015-07-01 14:22:13 +00:00
Jenkins da9d063274 Merge "Add `is_actionable_event` checking function" 2015-06-30 23:27:21 +00:00
Jenkins f511ea9f94 Merge "Disallow adding transitions from terminal states" 2015-06-30 19:30:29 +00:00
Joshua Harlow 2dea8f5675 Add `is_actionable_event` checking function
Change-Id: I51f27d23ebabaca2ec956f41ee795a4764531b91
2015-06-29 19:59:12 +00:00
Joshua Harlow 89656ae907 Disallow adding transitions from terminal states
Terminal states are by there very nature terminal and can not
have transitions to other states on any kind of event so on add
make sure we disallow those types of transitions to even be
created in the first place.

Change-Id: I70321e9482a0d053a8cb0bc89a766b5fbc82f69e
2015-06-29 12:59:01 -07:00
Joshua Harlow 5dc121d596 Add and use a callback name fetching utility function
Perform a better and more uniform (calling into a single
function) job at fetching a callbacks fully qualified name.

Change-Id: Ia0693b8e06fa5bed2beabfff9c8b6023e8b58980
2015-06-28 19:14:20 -07:00
Joshua Harlow ecf1263033 Add runners to features.rst & add a runner base & update docstrings
Change-Id: I18d7a656f537c3bf28257d24adc4a900e77906f3
2015-06-27 18:09:58 +00:00
Jenkins 9094074e5b Merge "Remove 2.6 classifier + 2.6 compatibility code" 2015-06-27 05:35:28 +00:00
Jenkins a17e2ff682 Merge "Add base exception class for this library" 2015-06-25 21:10:17 +00:00
Joshua Harlow 9008f5e067 Remove 2.6 classifier + 2.6 compatibility code
Depends-On: I2ea92dfdc78b645d2322b91d94c9469bf639b27f

Change-Id: I2c6ec5fdec80184b1d03c21a901494ebf4ad0b71
2015-06-23 16:25:16 -07:00
Joshua Harlow fd1d81a90c Add base exception class for this library
To make it easier for users of this library to
differentiate general exceptions from automaton
exceptions it is quite common to have a root exception
class that libraries use (and derive there exceptions
from); this adds that.

Change-Id: I140cb188f58849ac5caea97ed5a422375b549f6f
2015-06-23 12:36:17 -07:00
Joshua Harlow 3898b1d803 Add optional machine conversion into a pydot graph
Both ironic and taskflow share this same code to convert
their state machines into a pydot graph which then gets
converted into SVG to form:

- http://docs.openstack.org/developer/taskflow/states.html
- http://docs.openstack.org/developer/ironic/dev/states.html

So instead of duplicating it, provide a useful helper function
that both (and others) can share to produce a dot/graphviz pretty
diagram from a state machine.

Change-Id: I218740910163a1ca2587d706edc55852af1c0c74
2015-06-18 10:44:44 -07:00
Joshua Harlow 72239cfd70 When a state has no transitions show its own `on_exit` and `on_enter`
Change-Id: I4730fb35018b6e1ceb02ef30fd04ef2c9e7348a6
2015-06-12 22:32:49 -07:00
Joshua Harlow bcb61f0b0d Split the state machine runners off into own file
When using a state machine it is not always desired
to use the runner concept, so to ensure both concepts
are modular split runners off into there own module.

Change-Id: Iac8ce50b0a17468190f3f737663b5b094c324a55
2015-06-09 15:14:34 -07:00
Joshua Harlow 33c7e82b94 Use debtcollector removals function instead of warnings.warn
Change-Id: I7a9554a66c38999645d12c42a939e787c95fff3c
2015-06-05 17:28:47 -07:00
Joshua Harlow d71b6cf8b4 Revamp repo to match openstack repos
Get the repo in a working state so that it works
with the new and improved openstack CI system.

Change-Id: I80661c35fa7109a7ee9b1d00f89ca521a469eed0
2015-06-05 17:18:17 -07:00
Joshua Harlow 468a9923b5 Allow the hierarchical machine to provide back the nested machines
For those that wish to introspect the hierarchical machines that
are contained inside of it; provide back a way to get this information.
2014-12-16 12:05:55 -08:00
Joshua Harlow 230ade3c5e Retain & deprecate default_start_state via constructor 2014-12-12 12:49:31 -08:00
Joshua Harlow a6fe13bc11 Merge pull request #2 from harlowja/start_on_enter
Have the start state 'on_exit' be called when exit occurs
2014-12-11 15:09:43 -08:00
Joshua Harlow 931de8b0ca Amend the unittest due to more on_exit being triggered 2014-12-11 14:48:25 -08:00
Joshua Harlow dd34f046d2 Have the start state 'on_exit' be called when exit occurs
When the initial start state is exited from some event
to a new stable state it is nice to have its 'on_exit'
callback be triggerred.

The 'on_enter' is not triggered since the initialization
of a machine to a start state is not triggered by an event
and is more along the line of 'priming' the state machine,
not triggering any events that cause a transition to occur.
2014-12-11 14:43:28 -08:00
Joshua Harlow 01a92f9e80 Use a property setter instead of a method 2014-12-11 14:17:25 -08:00
Joshua Harlow b0abcebdbb Require using set_default_start_state to set the default 2014-12-11 14:16:21 -08:00
Joshua Harlow 93f1f4e802 Add more checks on setting a alternative start state default 2014-12-11 14:14:51 -08:00
Joshua Harlow daacc95dd1 Rename start_state to default_start_state
Allow for the start_state (really the default start
state, since initialize can change it) to be provided
in the constructor, as well as set via a property that
will be used by default in initialize (if one is not
provided that overrides the initial state).
2014-12-11 13:37:28 -08:00
Joshua Harlow ba0214a179 Use type(self) instead of self.__class__ 2014-12-10 18:28:55 -08:00
Joshua Harlow 00b59ec276 Correctly copy derived classes
When a derived class is requested to copy it should
get a new instance of the derived class and not always
a instance of the state machine base class, so we should
make that happen correctly.
2014-12-10 17:46:16 -08:00
Joshua Harlow 6f1be9d745 Allow initialize to take an alternative start_state
For the cases where it is desireable to force the machine
to start in a state that is not the constructor provided
state allow that to be possible using the initialize method.

By default it performs the existing behavior.
2014-12-10 17:43:20 -08:00
Joshua Harlow eb169daa98 Update message when processing event and not initialized 2014-12-10 12:57:57 -08:00
Joshua Harlow 8c897cfa6f Add pre and post event processing methods 2014-12-07 19:08:43 -08:00