├── .bumpversion.cfg ├── .cookiecutterrc ├── .coveragerc ├── .editorconfig ├── .github └── dependabot.yml ├── .gitignore ├── .pyup.yml ├── .travis.yml ├── AUTHORS.rst ├── CHANGELOG.rst ├── CONTRIBUTING.rst ├── LICENSE ├── MANIFEST.in ├── README.rst ├── ci ├── bootstrap.py └── templates │ └── .travis.yml ├── docs ├── authors.rst ├── changelog.rst ├── conf.py ├── contributing.rst ├── django.rst ├── index.rst ├── installation.rst ├── readme.rst ├── reference │ ├── fsm.rst │ └── index.rst ├── requirements.txt ├── spelling_wordlist.txt └── usage.rst ├── fsm ├── __init__.py ├── exceptions.py └── fsm.py ├── pyproject.toml ├── setup.py ├── tests └── test_fsm.py └── tox.ini /.bumpversion.cfg: -------------------------------------------------------------------------------- 1 | [bumpversion] 2 | current_version = 2.1.0 3 | commit = True 4 | tag = True 5 | 6 | [bumpversion:file:setup.py] 7 | 8 | [bumpversion:file:pyproject.toml] 9 | 10 | [bumpversion:file:docs/conf.py] 11 | 12 | [bumpversion:file:fsm/__init__.py] 13 | 14 | -------------------------------------------------------------------------------- /.cookiecutterrc: -------------------------------------------------------------------------------- 1 | # This file exists so you can easily regenerate your project. 2 | # 3 | # `cookiepatcher` is a convenient shim around `cookiecutter` 4 | # for regenerating projects (it will generate a .cookiecutterrc 5 | # automatically for any template). To use it: 6 | # 7 | # pip install cookiepatcher 8 | # cookiepatcher gh:ionelmc/cookiecutter-pylibrary project-path 9 | # 10 | # See: 11 | # https://pypi.python.org/pypi/cookiecutter 12 | # 13 | # Alternatively, you can run: 14 | # 15 | # cookiecutter --overwrite-if-exists --config-file=project-path/.cookiecutterrc gh:ionelmc/cookiecutter-pylibrary 16 | 17 | default_context: 18 | 19 | appveyor: 'no' 20 | c_extension_cython: 'no' 21 | c_extension_optional: 'no' 22 | c_extension_support: 'no' 23 | codacy: 'no' 24 | codeclimate: 'no' 25 | codecov: 'yes' 26 | command_line_interface: 'no' 27 | command_line_interface_bin_name: 'python-fsm' 28 | coveralls: 'no' 29 | distribution_name: 'python-fsm' 30 | email: 'santiwilly@gmail.com' 31 | full_name: 'Santiago Fraire Willemoes' 32 | github_username: 'Woile' 33 | landscape: 'no' 34 | package_name: 'fsm' 35 | project_name: 'Python Finite State Machine' 36 | project_short_description: 'Minimal state machine' 37 | release_date: 'today' 38 | repo_name: 'pyfsm' 39 | requiresio: 'no' 40 | scrutinizer: 'no' 41 | sphinx_doctest: 'no' 42 | sphinx_theme: 'sphinx-py3doc-enhanced-theme' 43 | test_matrix_configurator: 'no' 44 | test_matrix_separate_coverage: 'no' 45 | test_runner: 'pytest' 46 | travis: 'yes' 47 | version: '0.1.0' 48 | website: 'https://github.com/woile' 49 | year: '2016' 50 | -------------------------------------------------------------------------------- /.coveragerc: -------------------------------------------------------------------------------- 1 | [paths] 2 | source = 3 | src/fsm 4 | */site-packages/fsm 5 | 6 | [run] 7 | branch = True 8 | source = fsm 9 | parallel = true 10 | 11 | [report] 12 | show_missing = true 13 | precision = 2 14 | omit = *migrations* 15 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # see http://editorconfig.org 2 | root = true 3 | 4 | [*] 5 | end_of_line = lf 6 | trim_trailing_whitespace = true 7 | insert_final_newline = true 8 | indent_style = space 9 | indent_size = 4 10 | charset = utf-8 11 | 12 | [*.{bat,cmd,ps1}] 13 | end_of_line = crlf 14 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: pip 4 | directory: "/" 5 | schedule: 6 | interval: daily 7 | time: "04:00" 8 | open-pull-requests-limit: 10 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.py[cod] 2 | 3 | .vscode/ 4 | pyproject.lock 5 | # C extensions 6 | *.so 7 | .pypirc 8 | # Packages 9 | *.egg 10 | *.egg-info 11 | dist 12 | build 13 | eggs 14 | .eggs 15 | parts 16 | bin 17 | var 18 | sdist 19 | wheelhouse 20 | develop-eggs 21 | .installed.cfg 22 | lib 23 | lib64 24 | venv*/ 25 | pyvenv*/ 26 | .pytest_cache/ 27 | 28 | # Installer logs 29 | pip-log.txt 30 | 31 | # Unit test / coverage reports 32 | .coverage 33 | .tox 34 | .coverage.* 35 | nosetests.xml 36 | coverage.xml 37 | htmlcov 38 | 39 | # Translations 40 | *.mo 41 | 42 | # Mr Developer 43 | .mr.developer.cfg 44 | .project 45 | .pydevproject 46 | .idea 47 | *.iml 48 | *.komodoproject 49 | 50 | # Complexity 51 | output/*.html 52 | output/*/index.html 53 | 54 | # Sphinx 55 | docs/_build 56 | 57 | .DS_Store 58 | *~ 59 | .*.sw[po] 60 | .build 61 | .ve 62 | .env 63 | .cache 64 | .pytest 65 | .bootstrap 66 | .appveyor.token 67 | *.bak 68 | -------------------------------------------------------------------------------- /.pyup.yml: -------------------------------------------------------------------------------- 1 | # autogenerated pyup.io config file 2 | # see https://pyup.io/docs/configuration/ for all available options 3 | 4 | schedule: every week 5 | update: insecure 6 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | matrix: 3 | include: 4 | - python: 2.7 5 | env: TOXENV=py27,docs 6 | - python: 3.4 7 | env: TOXENV=py34 8 | - python: 3.5 9 | env: TOXENV=py35 10 | - python: 3.6 11 | env: TOXENV=py36,codecov,docs 12 | - python: pypy 13 | env: TOXENV=pypy 14 | env: 15 | global: 16 | - LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so 17 | - SEGFAULT_SIGNALS=all 18 | before_install: 19 | - python --version 20 | - uname -a 21 | - lsb_release -a 22 | install: 23 | - pip install tox tox-travis 24 | - virtualenv --version 25 | - easy_install --version 26 | - pip --version 27 | - tox --version 28 | script: 29 | - tox -v 30 | after_failure: 31 | - more .tox/log/* | cat 32 | - more .tox/*/log/* | cat 33 | before_cache: 34 | - rm -rf $HOME/.cache/pip/log 35 | cache: 36 | directories: 37 | - $HOME/.cache/pip 38 | notifications: 39 | email: 40 | on_success: never 41 | on_failure: always 42 | -------------------------------------------------------------------------------- /AUTHORS.rst: -------------------------------------------------------------------------------- 1 | 2 | Authors 3 | ======= 4 | 5 | * Santiago Fraire Willemoes - https://github.com/woile 6 | -------------------------------------------------------------------------------- /CHANGELOG.rst: -------------------------------------------------------------------------------- 1 | 2 | Changelog 3 | ========= 4 | 5 | 2.0.0 (2018-08-26) 6 | ----------------------------------------- 7 | 8 | * BREAKING: Simpler implementation 9 | * Docs and README updated 10 | * Usage of pyproject.toml 11 | 12 | 1.0.0 (2018-07-03) 13 | ----------------------------------------- 14 | 15 | * Renamed hooks to :code:`pre_` and :code:`post_` 16 | 17 | 0.1.3 (2017-15-09) 18 | ----------------------------------------- 19 | 20 | * Updated docs 21 | * Corrections to code 22 | * ci updated 23 | 24 | 25 | 0.1.0 (2016-04-18) 26 | ----------------------------------------- 27 | 28 | * First release on PyPI. 29 | -------------------------------------------------------------------------------- /CONTRIBUTING.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | Contributing 3 | ============ 4 | 5 | Contributions are welcome, and they are greatly appreciated! Every 6 | little bit helps, and credit will always be given. 7 | 8 | Bug reports 9 | =========== 10 | 11 | When `reporting a bug `_ please include: 12 | 13 | * Your operating system name and version. 14 | * Any details about your local setup that might be helpful in troubleshooting. 15 | * Detailed steps to reproduce the bug. 16 | 17 | Documentation improvements 18 | ========================== 19 | 20 | Python Finite State Machine could always use more documentation, whether as part of the 21 | official Python Finite State Machine docs, in docstrings, or even on the web in blog posts, 22 | articles, and such. 23 | 24 | Feature requests and feedback 25 | ============================= 26 | 27 | The best way to send feedback is to file an issue at https://github.com/Woile/pyfsm/issues. 28 | 29 | If you are proposing a feature: 30 | 31 | * Explain in detail how it would work. 32 | * Keep the scope as narrow as possible, to make it easier to implement. 33 | * Remember that this is a volunteer-driven project, and that code contributions are welcome :) 34 | 35 | Development 36 | =========== 37 | 38 | To set up `pyfsm` for local development: 39 | 40 | 1. Fork `pyfsm `_ 41 | (look for the "Fork" button). 42 | 2. Clone your fork locally:: 43 | 44 | git clone git@github.com:your_name_here/pyfsm.git 45 | 46 | 3. Create a branch for local development:: 47 | 48 | git checkout -b name-of-your-bugfix-or-feature 49 | 50 | Now you can make your changes locally. 51 | 52 | 4. When you're done making changes, run all the checks, doc builder and spell checker with `tox `_ one command:: 53 | 54 | tox 55 | 56 | 5. Commit your changes and push your branch to GitHub:: 57 | 58 | git add . 59 | git commit -m "Your detailed description of your changes." 60 | git push origin name-of-your-bugfix-or-feature 61 | 62 | 6. Submit a pull request through the GitHub website. 63 | 64 | Pull Request Guidelines 65 | ----------------------- 66 | 67 | If you need some code review or feedback while you're developing the code just make the pull request. 68 | 69 | For merging, you should: 70 | 71 | 1. Include passing tests (run ``tox``) [1]_. 72 | 2. Update documentation when there's new API, functionality etc. 73 | 3. Add a note to ``CHANGELOG.rst`` about the changes. 74 | 4. Add yourself to ``AUTHORS.rst``. 75 | 76 | .. [1] If you don't have all the necessary python versions available locally you can rely on Travis - it will 77 | `run the tests `_ for each change you add in the pull request. 78 | 79 | It will be slower though ... 80 | 81 | Tips 82 | ---- 83 | 84 | To run a subset of tests:: 85 | 86 | tox -e envname -- py.test -k test_myfeature 87 | 88 | To run all the test environments in *parallel* (you need to ``pip install detox``):: 89 | 90 | detox 91 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Santiago 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | graft docs 2 | graft examples 3 | graft fsm 4 | graft ci 5 | graft tests 6 | 7 | include .bumpversion.cfg 8 | include .coveragerc 9 | include .cookiecutterrc 10 | include .editorconfig 11 | include *.yml 12 | 13 | include AUTHORS.rst 14 | include CHANGELOG.rst 15 | include CONTRIBUTING.rst 16 | include LICENSE 17 | include README.rst 18 | 19 | include tox.ini .travis.yml appveyor.yml 20 | 21 | global-exclude *.py[cod] __pycache__ *.so *.dylib 22 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | ======== 2 | Overview 3 | ======== 4 | 5 | .. start-badges 6 | 7 | .. list-table:: 8 | :stub-columns: 1 9 | 10 | * - docs 11 | - |docs| 12 | * - tests 13 | - | |travis| 14 | | |codecov| 15 | * - package 16 | - |version| |wheel| |supported-versions| |supported-implementations| 17 | 18 | 19 | .. |docs| image:: https://img.shields.io/readthedocs/pip.svg?style=flat-square 20 | :alt: Read the Docs 21 | :target: https://readthedocs.org/projects/pyfsm 22 | 23 | .. |travis| image:: https://img.shields.io/travis/Woile/pyfsm.svg?style=flat-square 24 | :alt: Travis-CI Build Status 25 | :target: https://travis-ci.org/Woile/pyfsm 26 | 27 | .. |codecov| image:: https://img.shields.io/codecov/c/github/Woile/pyfsm.svg?style=flat-square 28 | :alt: Coverage Status 29 | :target: https://codecov.io/github/Woile/pyfsm 30 | 31 | .. |version| image:: https://img.shields.io/pypi/v/fsmpy.svg?style=flat-square 32 | :alt: PyPI Package latest release 33 | :target: https://pypi.python.org/pypi/fsmpy 34 | 35 | .. |wheel| image:: https://img.shields.io/pypi/wheel/fsmpy.svg?style=flat-square 36 | :alt: PyPI Wheel 37 | :target: https://pypi.python.org/pypi/fsmpy 38 | 39 | .. |supported-versions| image:: https://img.shields.io/pypi/pyversions/fsmpy.svg?style=flat-square 40 | :alt: Supported versions 41 | :target: https://pypi.python.org/pypi/fsmpy 42 | 43 | .. |supported-implementations| image:: https://img.shields.io/pypi/implementation/fsmpy.svg?style=flat-square 44 | :alt: Supported implementations 45 | :target: https://pypi.python.org/pypi/fsmpy 46 | 47 | 48 | .. end-badges 49 | 50 | Minimal state machine 51 | 52 | * Free software: BSD license 53 | 54 | 55 | .. code-block:: python 56 | 57 | import fsm 58 | 59 | class MyTasks(fsm.FiniteStateMachineMixin): 60 | """An example to test the state machine. 61 | 62 | Contains transitions to everywhere, nowhere and specific states. 63 | """ 64 | 65 | state_machine = { 66 | 'created': '__all__', 67 | 'pending': ('running',), 68 | 'running': ('success', 'failed'), 69 | 'success': None, 70 | 'failed': ('retry',), 71 | 'retry': ('pending', 'retry'), 72 | } 73 | 74 | def __init__(self, state): 75 | """Initialize setting a state.""" 76 | self.state = state 77 | 78 | def on_before_pending(self): 79 | print("I'm going to a pending state") 80 | 81 | :: 82 | 83 | In [4]: m = MyTasks(state='created') 84 | 85 | In [5]: m.change_state('pending') 86 | I'm going to a pending state 87 | Out[5]: 'pending' 88 | 89 | 90 | :: 91 | 92 | In [6]: m.change_state('failed') # Let's try to transition to an invalid state 93 | --------------------------------------------------------------------------- 94 | InvalidTransition Traceback (most recent call last) 95 | in () 96 | ----> 1 m.change_state('failed') 97 | 98 | ~/pyfsm/src/fsm/fsm.py in change_state(self, next_state, **kwargs) 99 | 90 msg = "The transition from {0} to {1} is not valid".format(previous_state, 100 | 91 next_state) 101 | ---> 92 raise InvalidTransition(msg) 102 | 93 103 | 94 name = 'pre_{0}'.format(next_state) 104 | 105 | InvalidTransition: The transition from pending to failed is not valid 106 | 107 | .. contents:: 108 | :depth: 2 109 | 110 | 111 | Installation 112 | ============ 113 | 114 | :: 115 | 116 | pip install fsmpy 117 | 118 | 119 | Usage 120 | ====== 121 | 122 | 1. Define in a class the :code:`state_machine` 123 | 2. Initialize :code:`state`, either with a value, using :code:`__init__` or as a django field 124 | 3. Add hooks: 125 | 126 | +------------------------+-------------------------------------------------------------------------------------------------------------+ 127 | | Method | Description | 128 | +------------------------+-------------------------------------------------------------------------------------------------------------+ 129 | | on_before_change_state | Before transitioning to the state | 130 | +------------------------+-------------------------------------------------------------------------------------------------------------+ 131 | | on_change_state | After transitioning to the state, if no failure, runs for every state | 132 | +------------------------+-------------------------------------------------------------------------------------------------------------+ 133 | | pre_ | Runs before a particular state, where :code:`state_name` is the specified name in the :code:`state_machine` | 134 | +------------------------+-------------------------------------------------------------------------------------------------------------+ 135 | | post_ | Runs after a particular state, where :code:`state_name` is the specified name in the :code:`state_machine` | 136 | +------------------------+-------------------------------------------------------------------------------------------------------------+ 137 | 138 | This hooks will receive any extra argument given to :code:`change_state` 139 | 140 | 141 | E.g: 142 | 143 | Running :code:`m.change_state('pending', name='john')` will trigger :code:`pre_pending(name='john')` 144 | 145 | Django integration 146 | ================== 147 | 148 | .. code-block:: python 149 | 150 | import fsm 151 | from django.db import models 152 | 153 | 154 | class MyModel(models.Model, fsm.FiniteStateMachineMixin): 155 | """An example to test the state machine. 156 | 157 | Contains transitions to everywhere, nowhere and specific states. 158 | """ 159 | 160 | CHOICES = ( 161 | ('created', 'CREATED'), 162 | ('pending', 'PENDING'), 163 | ('running', 'RUNNING'), 164 | ('success', 'SUCCESS'), 165 | ('failed', 'FAILED'), 166 | ('retry', 'RETRY'), 167 | ) 168 | 169 | state_machine = { 170 | 'created': '__all__', 171 | 'pending': ('running',), 172 | 'running': ('success', 'failed'), 173 | 'success': None, 174 | 'failed': ('retry',), 175 | 'retry': ('pending', 'retry'), 176 | } 177 | 178 | state = models.CharField(max_length=30, choices=CHOICES, default='created') 179 | 180 | def on_change_state(self, previous_state, next_state, **kwargs): 181 | self.save() 182 | 183 | Django Rest Framework 184 | --------------------- 185 | 186 | If you are using :code:`serializers`, they usually perform the :code:`save`, so saving inside :code:`on_change_state` is not necessary. 187 | 188 | One simple solution is to do this: 189 | 190 | .. code-block:: python 191 | 192 | class MySerializer(serializers.ModelSerializer): 193 | 194 | def update(self, instance, validated_data): 195 | new_state = validated_data.get('state', instance.state) 196 | try: 197 | instance.change_state(new_state) 198 | except fsm.InvalidTransition: 199 | raise serializers.ValidationError("Invalid transition") 200 | instance = super().update(instance, validated_data) 201 | return instance 202 | 203 | 204 | Documentation 205 | ============= 206 | 207 | https://pyfsm.readthedocs.org/ 208 | 209 | Development 210 | =========== 211 | 212 | To run the tests run:: 213 | 214 | tox 215 | 216 | Note, to combine the coverage data from all the tox environments run: 217 | 218 | .. list-table:: 219 | :widths: 10 90 220 | :stub-columns: 1 221 | 222 | - - Windows 223 | - :: 224 | 225 | set PYTEST_ADDOPTS=--cov-append 226 | tox 227 | 228 | - - Other 229 | - :: 230 | 231 | PYTEST_ADDOPTS=--cov-append tox 232 | -------------------------------------------------------------------------------- /ci/bootstrap.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | from __future__ import absolute_import, print_function, unicode_literals 4 | 5 | import os 6 | import sys 7 | from os.path import exists 8 | from os.path import join 9 | from os.path import dirname 10 | from os.path import abspath 11 | 12 | 13 | if __name__ == "__main__": 14 | base_path = dirname(dirname(abspath(__file__))) 15 | print("Project path: {0}".format(base_path)) 16 | env_path = join(base_path, ".tox", "bootstrap") 17 | if sys.platform == "win32": 18 | bin_path = join(env_path, "Scripts") 19 | else: 20 | bin_path = join(env_path, "bin") 21 | if not exists(env_path): 22 | import subprocess 23 | print("Making bootstrap env in: {0} ...".format(env_path)) 24 | try: 25 | subprocess.check_call(["virtualenv", env_path]) 26 | except Exception: 27 | subprocess.check_call([sys.executable, "-m", "virtualenv", env_path]) 28 | print("Installing `jinja2` into bootstrap environment ...") 29 | subprocess.check_call([join(bin_path, "pip"), "install", "jinja2"]) 30 | activate = join(bin_path, "activate_this.py") 31 | exec(compile(open(activate, "rb").read(), activate, "exec"), dict(__file__=activate)) 32 | 33 | import jinja2 34 | 35 | import subprocess 36 | 37 | 38 | jinja = jinja2.Environment( 39 | loader=jinja2.FileSystemLoader(join(base_path, "ci", "templates")), 40 | trim_blocks=True, 41 | lstrip_blocks=True, 42 | keep_trailing_newline=True 43 | ) 44 | 45 | tox_environments = [ 46 | line.strip() 47 | for line in subprocess.check_output(['tox', '--listenvs'], universal_newlines=True).splitlines() 48 | ] 49 | tox_environments = [line for line in tox_environments if line not in ['clean', 'report', 'docs', 'check']] 50 | 51 | 52 | for name in os.listdir(join("ci", "templates")): 53 | with open(join(base_path, name), "w") as fh: 54 | fh.write(jinja.get_template(name).render(tox_environments=tox_environments)) 55 | print("Wrote {}".format(name)) 56 | print("DONE.") 57 | -------------------------------------------------------------------------------- /ci/templates/.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | python: '3.5' 3 | sudo: false 4 | env: 5 | global: 6 | - LD_PRELOAD=/lib/x86_64-linux-gnu/libSegFault.so 7 | - SEGFAULT_SIGNALS=all 8 | matrix: 9 | - TOXENV=check 10 | - TOXENV=docs 11 | {% for env in tox_environments %}{{ '' }} 12 | - TOXENV={{ env }},codecov 13 | {% endfor %} 14 | 15 | before_install: 16 | - python --version 17 | - uname -a 18 | - lsb_release -a 19 | install: 20 | - pip install tox 21 | - virtualenv --version 22 | - easy_install --version 23 | - pip --version 24 | - tox --version 25 | script: 26 | - tox -v 27 | after_failure: 28 | - more .tox/log/* | cat 29 | - more .tox/*/log/* | cat 30 | before_cache: 31 | - rm -rf $HOME/.cache/pip/log 32 | cache: 33 | directories: 34 | - $HOME/.cache/pip 35 | notifications: 36 | email: 37 | on_success: never 38 | on_failure: always 39 | -------------------------------------------------------------------------------- /docs/authors.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../AUTHORS.rst 2 | -------------------------------------------------------------------------------- /docs/changelog.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../CHANGELOG.rst 2 | -------------------------------------------------------------------------------- /docs/conf.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | from __future__ import unicode_literals 3 | 4 | import os 5 | 6 | 7 | extensions = [ 8 | 'sphinx.ext.autodoc', 9 | 'sphinx.ext.autosummary', 10 | 'sphinx.ext.coverage', 11 | 'sphinx.ext.doctest', 12 | 'sphinx.ext.extlinks', 13 | 'sphinx.ext.ifconfig', 14 | 'sphinx.ext.napoleon', 15 | 'sphinx.ext.todo', 16 | 'sphinx.ext.viewcode', 17 | ] 18 | if os.getenv('SPELLCHECK'): 19 | extensions += 'sphinxcontrib.spelling', 20 | spelling_show_suggestions = True 21 | spelling_lang = 'en_US' 22 | 23 | source_suffix = '.rst' 24 | master_doc = 'index' 25 | project = 'Python Finite State Machine' 26 | year = '2016' 27 | author = 'Santiago Fraire Willemoes' 28 | copyright = '{0}, {1}'.format(year, author) 29 | version = release = '2.1.0' 30 | 31 | pygments_style = 'trac' 32 | templates_path = ['.'] 33 | extlinks = { 34 | 'issue': ('https://github.com/Woile/pyfsm/issues/%s', '#'), 35 | 'pr': ('https://github.com/Woile/pyfsm/pull/%s', 'PR #'), 36 | } 37 | # import sphinx_rtd_theme 38 | html_theme = "sphinx_rtd_theme" 39 | html_theme_options = { 40 | 'githuburl': 'https://github.com/Woile/pyfsm/' 41 | } 42 | 43 | html_use_smartypants = True 44 | html_last_updated_fmt = '%b %d, %Y' 45 | html_split_index = False 46 | html_sidebars = { 47 | '**': ['searchbox.html', 'globaltoc.html', 'sourcelink.html'], 48 | } 49 | html_short_title = '%s-%s' % (project, version) 50 | 51 | napoleon_use_ivar = True 52 | napoleon_use_rtype = False 53 | napoleon_use_param = False 54 | -------------------------------------------------------------------------------- /docs/contributing.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../CONTRIBUTING.rst 2 | -------------------------------------------------------------------------------- /docs/django.rst: -------------------------------------------------------------------------------- 1 | Django integration 2 | ================== 3 | 4 | .. code-block:: python 5 | 6 | import fsm 7 | from django.db import models 8 | 9 | 10 | class MyModel(models.Model, fsm.FiniteStateMachineMixin): 11 | """An example to test the state machine. 12 | 13 | Contains transitions to everywhere, nowhere and specific states. 14 | """ 15 | 16 | CHOICES = ( 17 | ('created', 'CREATED'), 18 | ('pending', 'PENDING'), 19 | ('running', 'RUNNING'), 20 | ('success', 'SUCCESS'), 21 | ('failed', 'FAILED'), 22 | ('retry', 'RETRY'), 23 | ) 24 | 25 | state_machine = { 26 | 'created': '__all__', 27 | 'pending': ('running',), 28 | 'running': ('success', 'failed'), 29 | 'success': None, 30 | 'failed': ('retry',), 31 | 'retry': ('pending', 'retry'), 32 | } 33 | 34 | state = models.CharField(max_length=30, choices=CHOICES, default='created') 35 | 36 | def on_change_state(self, previous_state, next_state, **kwargs): 37 | self.save() 38 | 39 | Django Rest Framework 40 | --------------------- 41 | 42 | If you are using :code:`serializers`, they usually perform the :code:`save`, so saving inside :code:`on_change_state` is not necessary. 43 | 44 | One simple solution is to do this: 45 | 46 | .. code-block:: python 47 | 48 | class MySerializer(serializers.ModelSerializer): 49 | 50 | def update(self, instance, validated_data): 51 | new_state = validated_data.get('state', instance.state) 52 | try: 53 | instance.change_state(new_state) 54 | except fsm.InvalidTransition: 55 | raise serializers.ValidationError("Invalid transition") 56 | instance = super().update(instance, validated_data) 57 | return instance 58 | -------------------------------------------------------------------------------- /docs/index.rst: -------------------------------------------------------------------------------- 1 | ======== 2 | Contents 3 | ======== 4 | 5 | .. toctree:: 6 | :maxdepth: 2 7 | 8 | readme 9 | installation 10 | usage 11 | django 12 | reference/index 13 | contributing 14 | authors 15 | changelog 16 | 17 | Indices and tables 18 | ================== 19 | 20 | * :ref:`genindex` 21 | * :ref:`modindex` 22 | * :ref:`search` 23 | 24 | -------------------------------------------------------------------------------- /docs/installation.rst: -------------------------------------------------------------------------------- 1 | ============ 2 | Installation 3 | ============ 4 | 5 | At the command line:: 6 | 7 | pip install fsmpy 8 | -------------------------------------------------------------------------------- /docs/readme.rst: -------------------------------------------------------------------------------- 1 | .. include:: ../README.rst 2 | -------------------------------------------------------------------------------- /docs/reference/fsm.rst: -------------------------------------------------------------------------------- 1 | fsm package 2 | =========== 3 | 4 | Submodules 5 | ---------- 6 | 7 | fsm module 8 | ---------------------- 9 | 10 | .. autoclass:: fsm.InvalidTransition 11 | :members: 12 | :undoc-members: 13 | :show-inheritance: 14 | 15 | .. autoclass:: fsm.FiniteStateMachineMixin 16 | :members: 17 | :undoc-members: 18 | :show-inheritance: 19 | 20 | .. autoclass:: fsm.BaseFiniteStateMachineMixin 21 | :members: 22 | :undoc-members: 23 | :show-inheritance: 24 | 25 | 26 | Module contents 27 | --------------- 28 | 29 | .. automodule:: fsm 30 | :members: 31 | :undoc-members: 32 | :show-inheritance: 33 | -------------------------------------------------------------------------------- /docs/reference/index.rst: -------------------------------------------------------------------------------- 1 | Reference 2 | ========= 3 | 4 | .. toctree:: 5 | :glob: 6 | 7 | fsm* 8 | -------------------------------------------------------------------------------- /docs/requirements.txt: -------------------------------------------------------------------------------- 1 | sphinx>=1.3 2 | sphinx_rtd_theme 3 | requests[security] 4 | -e . 5 | -------------------------------------------------------------------------------- /docs/spelling_wordlist.txt: -------------------------------------------------------------------------------- 1 | builtin 2 | builtins 3 | classmethod 4 | staticmethod 5 | classmethods 6 | staticmethods 7 | args 8 | kwargs 9 | callstack 10 | Changelog 11 | Indices 12 | -------------------------------------------------------------------------------- /docs/usage.rst: -------------------------------------------------------------------------------- 1 | ===== 2 | Usage 3 | ===== 4 | 5 | 1. Define in a class the :code:`state_machine` 6 | 2. Initialize :code:`state`, either with a value, using :code:`__init__` or as a django field 7 | 3. Add hooks: 8 | 9 | +------------------------+-------------------------------------------------------------------------------------------------------------+ 10 | | Method | Description | 11 | +------------------------+-------------------------------------------------------------------------------------------------------------+ 12 | | on_before_change_state | Before transitioning to the state | 13 | +------------------------+-------------------------------------------------------------------------------------------------------------+ 14 | | on_change_state | After transitioning to the state, if no failure, runs for every state | 15 | +------------------------+-------------------------------------------------------------------------------------------------------------+ 16 | | pre_ | Runs before a particular state, where :code:`state_name` is the specified name in the :code:`state_machine` | 17 | +------------------------+-------------------------------------------------------------------------------------------------------------+ 18 | | post_ | Runs after a particular state, where :code:`state_name` is the specified name in the :code:`state_machine` | 19 | +------------------------+-------------------------------------------------------------------------------------------------------------+ 20 | 21 | This hooks will receive any extra argument given to :code:`change_state` 22 | 23 | 24 | E.g: 25 | 26 | Running :code:`m.change_state('pending', name='john')` will trigger :code:`pre_pending(name='john')` 27 | 28 | Raising AbortTransition in `pre_` method will result in no state change and `on_before_change_state` not called. 29 | 30 | In your code 31 | ------------ 32 | 33 | 34 | To use Python Finite State Machine in a project:: 35 | 36 | import fsm 37 | 38 | 39 | Then add the Mixin to any class where the state machine is required. 40 | 41 | .. code:: python 42 | 43 | class Foo(fsm.FiniteStateMachineMixin): 44 | 45 | state_machine = { 46 | 'my_first_state': '__all__', 47 | 'my_state': ('my_second_state',), 48 | 'my_second_state': ('my_state', 'my_second_state', 'last_state'), 49 | 'last_state': None 50 | } 51 | 52 | state = 'my_first_state' 53 | 54 | 55 | Instanciate the class and use it. Remember that in order to work as intended, :code:`change_state` 56 | must be used to transition from one state to the other. 57 | 58 | .. code:: 59 | 60 | >>> foo = Foo() 61 | 62 | >>> foo.current_state() 63 | 'my_first_state' 64 | 65 | >>> foo.change_state('my_state') 66 | 'my_state' 67 | 68 | >>> foo.current_state() 69 | 'my_state' 70 | 71 | >>> foo.can_change('last_state') 72 | False 73 | 74 | >>> foo.get_valid_transitions() 75 | ('my_second_state',) 76 | 77 | 78 | 79 | You can also use :code:`BaseFiniteStateMachineMixin` for more flexibility. 80 | Implementing :code:`current_state` and :code:`set_state` is required. 81 | Doing this allows using more complex behavior, but it is **not recommended**. 82 | -------------------------------------------------------------------------------- /fsm/__init__.py: -------------------------------------------------------------------------------- 1 | """Initializing package.""" 2 | 3 | from .exceptions import InvalidTransition # NOQA 4 | from .fsm import FiniteStateMachineMixin, BaseFiniteStateMachineMixin # NOQA 5 | 6 | __version__ = "2.1.0" 7 | -------------------------------------------------------------------------------- /fsm/exceptions.py: -------------------------------------------------------------------------------- 1 | __all__ = ["InvalidTransition", "AbortTransition"] 2 | 3 | 4 | class InvalidTransition(Exception): 5 | """Moving from an state to another is not possible.""" 6 | 7 | pass 8 | 9 | 10 | class AbortTransition(Exception): 11 | """Changing state should be aborted""" 12 | 13 | pass 14 | -------------------------------------------------------------------------------- /fsm/fsm.py: -------------------------------------------------------------------------------- 1 | from .exceptions import AbortTransition, InvalidTransition 2 | 3 | __all__ = ["FiniteStateMachineMixin", "BaseFiniteStateMachineMixin"] 4 | 5 | 6 | class BaseFiniteStateMachineMixin: 7 | """Base Mixin to add a state_machine behavior. 8 | 9 | Represents the state machine for the object. 10 | 11 | The states and transitions should be specified in the following way: 12 | 13 | .. code-block:: python 14 | 15 | state_machine = { 16 | 'some_state': '__all__' 17 | 'another_state': ('some_state', 'one_more_state') 18 | 'one_more_state': None 19 | } 20 | 21 | Requires the implementation of :code:`current_state` and :code:`set_state` 22 | """ 23 | 24 | state_machine = None 25 | 26 | def current_state(self): 27 | """Returns the current state in the FSM.""" 28 | raise NotImplementedError("Subclass must implement this method!") 29 | 30 | def set_state(self, state): 31 | """Update the internal state field. 32 | 33 | :param state: type depends on the definition of the states. 34 | :type state: str or int 35 | """ 36 | raise NotImplementedError("Subclass must implement this method!") 37 | 38 | def can_change(self, next_state): 39 | """Validates if the next_state can be executed or not. 40 | 41 | It uses the state_machine attribute in the class. 42 | """ 43 | valid_transitions = self.get_valid_transitions() 44 | 45 | if not valid_transitions: 46 | return False 47 | 48 | return next_state in valid_transitions 49 | 50 | def get_valid_transitions(self): 51 | """Return possible states to whom a product can transition. 52 | 53 | :returns: valid transitions 54 | :rtype: tuple or list 55 | """ 56 | current = self.current_state() 57 | valid_transitions = self.state_machine[current] 58 | 59 | if valid_transitions == "__all__": 60 | return self.state_machine.keys() 61 | 62 | return self.state_machine[current] 63 | 64 | def on_before_change_state(self, previous_state, next_state, **kwargs): 65 | """Called before a state changes. 66 | 67 | :param previous_state: type depends on the definition of the states. 68 | :type previous_state: str or int 69 | :param next_state: type depends on the definition of the states. 70 | :type next_state: str or int 71 | """ 72 | pass 73 | 74 | def on_change_state(self, previous_state, next_state, **kwargs): 75 | """Called after a state changes. 76 | 77 | :param previous_state: type depends on the definition of the states. 78 | :type previous_state: str or int 79 | :param next_state: type depends on the definition of the states. 80 | :type next_state: str or int 81 | """ 82 | pass 83 | 84 | def change_state(self, next_state, **kwargs): 85 | """Performs a transition from current state to the given next state if 86 | possible. 87 | 88 | Callbacks will be exacuted before an after changing the state. 89 | Specific state callbacks will also be called if they are implemented 90 | in the subclass. 91 | 92 | :param next_state: where the state must go 93 | :type next_state: str or int 94 | :returns: new state. 95 | :rtype: str or int 96 | :raises InvalidTransition: If transitioning is not possible 97 | """ 98 | previous_state = self.current_state() 99 | 100 | if not self.can_change(next_state): 101 | msg = "The transition from {0} to {1} is not valid".format( 102 | previous_state, next_state 103 | ) 104 | raise InvalidTransition(msg) 105 | 106 | name = "pre_{0}".format(next_state) 107 | callback = getattr(self, name, None) 108 | if callback: 109 | try: 110 | callback(**kwargs) 111 | except AbortTransition: 112 | return previous_state 113 | 114 | self.on_before_change_state(previous_state, next_state, **kwargs) 115 | 116 | self.set_state(next_state) 117 | 118 | name = "post_{0}".format(next_state) 119 | callback = getattr(self, name, None) 120 | if callback: 121 | callback(**kwargs) 122 | 123 | self.on_change_state(previous_state, next_state, **kwargs) 124 | return next_state 125 | 126 | 127 | class FiniteStateMachineMixin(BaseFiniteStateMachineMixin): 128 | """A drop in implementation. Ready to be used. 129 | 130 | Replace :code:`FIELD_NAME` in order to automatically retrieve or set 131 | from a different field. 132 | 133 | In order to use with django, just add a field :code:`state` 134 | or as defined in :code:`FIELD_NAME` 135 | and remember to use :code:`change_state` instead of simply assigning it 136 | """ 137 | 138 | FIELD_NAME = "state" 139 | 140 | def current_state(self): 141 | return getattr(self, self.FIELD_NAME) 142 | 143 | def set_state(self, state): 144 | setattr(self, self.FIELD_NAME, state) 145 | -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [tool.poetry] 2 | name = "fsmpy" 3 | version = "2.1.0" 4 | description = "Minimal state machine" 5 | authors = ["Santiago Fraire Willemoes "] 6 | license = "MIT" 7 | readme = "README.rst" 8 | keywords=["finite", "state", "machine", "minimal"] 9 | classifiers=[ 10 | 'Development Status :: 5 - Production/Stable', 11 | 'Intended Audience :: Developers', 12 | ] 13 | packages = [ 14 | { include = "fsm" } 15 | ] 16 | homepage = "https://github.com/Woile/pyfsm" 17 | repository = "https://github.com/Woile/pyfsm" 18 | documentation = "https://pyfsm.readthedocs.io/en/latest/" 19 | 20 | [tool.poetry.dependencies] 21 | python = "*" 22 | 23 | [tool.poetry.dev-dependencies] 24 | tox = "^3.2" 25 | bumpversion = "^0.6.0" 26 | flake8 = "^3.5" 27 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- encoding: utf-8 -*- 3 | from __future__ import absolute_import 4 | from __future__ import print_function 5 | 6 | import io 7 | import re 8 | from os.path import dirname 9 | from os.path import join 10 | 11 | from setuptools import setup 12 | 13 | 14 | def read(*names, **kwargs): 15 | return io.open( 16 | join(dirname(__file__), *names), encoding=kwargs.get("encoding", "utf8") 17 | ).read() 18 | 19 | 20 | setup( 21 | name="fsmpy", 22 | version="2.1.0", 23 | license="BSD", 24 | description="Minimal state machine", 25 | long_description="%s\n%s" 26 | % ( 27 | re.compile("^.. start-badges.*^.. end-badges", re.M | re.S).sub( 28 | "", read("README.rst") 29 | ), 30 | re.sub(":[a-z]+:`~?(.*?)`", r"``\1``", read("CHANGELOG.rst")), 31 | ), 32 | author="Santiago Fraire Willemoes", 33 | author_email="santiwilly@gmail.com", 34 | url="https://github.com/Woile/pyfsm", 35 | download_url="https://github.com/Woile/pyfsm/tree/2.1.0", 36 | include_package_data=True, 37 | classifiers=[ 38 | # complete classifier list: http://pypi.python.org/pypi?%3Aaction=list_classifiers 39 | "Development Status :: 5 - Production/Stable", 40 | "Intended Audience :: Developers", 41 | "Topic :: Utilities", 42 | ], 43 | keywords="finite state machine minimal", 44 | ) 45 | -------------------------------------------------------------------------------- /tests/test_fsm.py: -------------------------------------------------------------------------------- 1 | import unittest 2 | 3 | import fsm 4 | 5 | 6 | class FooBar(fsm.BaseFiniteStateMachineMixin): 7 | state_machine = {} 8 | 9 | 10 | class ProgramExecution(fsm.FiniteStateMachineMixin): 11 | """An example to test the state machine. 12 | 13 | Contains transitions to everywhere, nowhere and specific states. 14 | """ 15 | 16 | state_machine = { 17 | 'created': '__all__', 18 | 'pending': ('running',), 19 | 'running': ('success', 'failed'), 20 | 'success': None, 21 | 'failed': ('retry',), 22 | 'retry': ('pending', 'retry'), 23 | } 24 | 25 | def __init__(self, state): 26 | """Initialize setting a state.""" 27 | self.state = state 28 | 29 | def pre_pending(self): 30 | return 31 | 32 | def post_pending(self): 33 | return 34 | 35 | 36 | class TestStateMachine(unittest.TestCase): 37 | 38 | def setUp(self): 39 | self.program_execution = ProgramExecution('created') 40 | 41 | def transition_anywhere(self): 42 | """Test when a state can go anywhere. 43 | 44 | Defined as __all__ 45 | """ 46 | state = self.program_execution.change_state('pending') 47 | assert state == 'pending' 48 | 49 | def test_current_state_not_set(self): 50 | """Test current_state exception when not implemented.""" 51 | foo = FooBar() 52 | self.assertRaises(NotImplementedError, foo.current_state) 53 | 54 | def test_set_state_fails_with_no_implementation(self): 55 | foo = FooBar() 56 | self.assertRaises(NotImplementedError, foo.set_state, 'init') 57 | 58 | def test_successful_specific_transition(self): 59 | """Test a succesful state transition.""" 60 | self.program_execution.change_state('pending') 61 | state = self.program_execution.change_state('running') 62 | assert state == 'running' 63 | 64 | def test_failed_specific_transition(self): 65 | """Test a failed state transition.""" 66 | self.program_execution.change_state('pending') 67 | try: 68 | state = self.program_execution.change_state('success') 69 | except fsm.InvalidTransition: 70 | state = None 71 | assert state is None 72 | 73 | def test_succesful_transition_to_self(self): 74 | """Succesful transition from a state to the same state.""" 75 | self.program_execution.change_state('pending') 76 | self.program_execution.change_state('running') 77 | self.program_execution.change_state('failed') 78 | self.program_execution.change_state('retry') 79 | state = self.program_execution.change_state('retry') 80 | assert state == 'retry' 81 | 82 | def test_failed_transition_to_self(self): 83 | """Succesful transition from a state to the same state.""" 84 | self.program_execution.change_state('pending') 85 | self.program_execution.change_state('running') 86 | try: 87 | state = self.program_execution.change_state('running') 88 | except fsm.InvalidTransition: 89 | state = None 90 | assert state is None 91 | 92 | def test_failed_nowhere_transition_to_created(self): 93 | """Test that a nowhere transition always fails (created).""" 94 | self.program_execution.change_state('pending') 95 | self.program_execution.change_state('running') 96 | self.program_execution.change_state('success') 97 | try: 98 | state = self.program_execution.change_state('created') 99 | except fsm.InvalidTransition: 100 | state = None 101 | assert state is None 102 | 103 | def test_failed_nowhere_transition_to_pending(self): 104 | """Test that a nowhere transition always fails (pending).""" 105 | self.program_execution.change_state('pending') 106 | self.program_execution.change_state('running') 107 | self.program_execution.change_state('success') 108 | try: 109 | state = self.program_execution.change_state('pending') 110 | except fsm.InvalidTransition: 111 | state = None 112 | assert state is None 113 | 114 | def test_failed_nowhere_transition_to_running(self): 115 | """Test that a nowhere transition always fails (running).""" 116 | self.program_execution.change_state('pending') 117 | self.program_execution.change_state('running') 118 | self.program_execution.change_state('success') 119 | try: 120 | state = self.program_execution.change_state('running') 121 | except fsm.InvalidTransition: 122 | state = None 123 | assert state is None 124 | 125 | def test_failed_nowhere_transition_to_success(self): 126 | """Test that a nowhere transition always fails (success).""" 127 | self.program_execution.change_state('pending') 128 | self.program_execution.change_state('running') 129 | self.program_execution.change_state('success') 130 | try: 131 | state = self.program_execution.change_state('success') 132 | except fsm.InvalidTransition: 133 | state = None 134 | assert state is None 135 | 136 | def test_failed_nowhere_transition_to_failed(self): 137 | """Test that a nowhere transition always fails (failed).""" 138 | self.program_execution.change_state('pending') 139 | self.program_execution.change_state('running') 140 | self.program_execution.change_state('success') 141 | try: 142 | state = self.program_execution.change_state('failed') 143 | except fsm.InvalidTransition: 144 | state = None 145 | assert state is None 146 | 147 | def test_failed_nowhere_transition_to_retry(self): 148 | """Test that a nowhere transition always fails (retry).""" 149 | self.program_execution.change_state('pending') 150 | self.program_execution.change_state('running') 151 | self.program_execution.change_state('success') 152 | try: 153 | state = self.program_execution.change_state('retry') 154 | except fsm.InvalidTransition: 155 | state = None 156 | assert state is None 157 | 158 | def test_abort_transition(self): 159 | """Test aborting transition from pre_ method.""" 160 | 161 | def abort(): 162 | raise fsm.exceptions.AbortTransition 163 | 164 | self.program_execution.pre_pending = abort 165 | state = self.program_execution.change_state('pending') 166 | assert state == 'created' 167 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | ; a generative tox configuration, see: https://testrun.org/tox/latest/config.html#generative-envlist 2 | 3 | [tox] 4 | skipsdist = True 5 | envlist = 6 | clean, 7 | check, 8 | {py27,py34,py35,py36,py37,py38,pypy}, 9 | report, 10 | docs 11 | 12 | [testenv] 13 | basepython = 14 | pypy: {env:TOXPYTHON:pypy} 15 | {py27,docs,spell}: {env:TOXPYTHON:python2.7} 16 | py34: {env:TOXPYTHON:python3.4} 17 | py35: {env:TOXPYTHON:python3.5} 18 | py36: {env:TOXPYTHON:python3.6} 19 | py37: {env:TOXPYTHON:python3.7} 20 | py38: {env:TOXPYTHON:python3.8} 21 | {clean,check,report,coveralls,codecov}: python3.6 22 | bootstrap: python 23 | setenv = 24 | PYTHONPATH={toxinidir}/tests 25 | PYTHONUNBUFFERED=yes 26 | passenv = 27 | * 28 | usedevelop = false 29 | deps = 30 | pytest 31 | pytest-travis-fold 32 | pytest-cov 33 | commands = 34 | {posargs:python -m pytest --cov=fsm --cov-report=term-missing -vv tests/} 35 | 36 | [testenv:bootstrap] 37 | deps = 38 | jinja2 39 | matrix 40 | skip_install = true 41 | commands = 42 | python ci/bootstrap.py 43 | passenv = 44 | * 45 | 46 | [testenv:spell] 47 | setenv = 48 | SPELLCHECK=1 49 | commands = 50 | sphinx-build -b spelling docs dist/docs 51 | skip_install = true 52 | deps = 53 | -r{toxinidir}/docs/requirements.txt 54 | sphinxcontrib-spelling 55 | pyenchant 56 | 57 | [testenv:docs] 58 | deps = 59 | -r{toxinidir}/docs/requirements.txt 60 | commands = 61 | sphinx-build {posargs:-E} -b html docs dist/docs 62 | sphinx-build -b linkcheck docs dist/docs 63 | 64 | [testenv:check] 65 | deps = 66 | docutils 67 | check-manifest 68 | flake8 69 | readme-renderer 70 | pygments 71 | isort 72 | skip_install = true 73 | commands = 74 | check-manifest {toxinidir} 75 | flake8 fsm tests --ignore F401,E121,E123,E126,E226,E24,E704 76 | 77 | [testenv:coveralls] 78 | deps = 79 | coveralls 80 | skip_install = true 81 | commands = 82 | coverage combine 83 | coverage report 84 | coveralls [] 85 | 86 | [testenv:codecov] 87 | deps = 88 | codecov 89 | skip_install = true 90 | commands = 91 | codecov [] 92 | 93 | 94 | [testenv:report] 95 | deps = coverage 96 | skip_install = true 97 | commands = 98 | coverage combine 99 | coverage report 100 | coverage html 101 | 102 | [testenv:clean] 103 | commands = coverage erase 104 | skip_install = true 105 | deps = coverage 106 | 107 | --------------------------------------------------------------------------------