Skip to content

Commit

Permalink
Update deps - using ruff instead of black (#426)
Browse files Browse the repository at this point in the history
* deps: Update

* fmt: Applying ruff format instead of black. Updating deps.

* fmt: Applying ruff format instead of black on CI.

* deps: Upd deps for read the docs
  • Loading branch information
fgmacedo committed Apr 17, 2024
1 parent 6d90d2e commit f236cad
Show file tree
Hide file tree
Showing 41 changed files with 988 additions and 955 deletions.
17 changes: 5 additions & 12 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -46,18 +46,11 @@ jobs:
# run ruff
#----------------------------------------------
- name: Linter with ruff
if: matrix.python-version == 3.11
if: matrix.python-version == 3.12
run: |
source .venv/bin/activate
ruff .
#----------------------------------------------
# run black
#----------------------------------------------
- name: Linter with black
if: matrix.python-version == 3.11
run: |
source .venv/bin/activate
black . --check --diff
ruff check .
ruff format --check .
#----------------------------------------------
# run pytest
#----------------------------------------------
Expand All @@ -71,7 +64,7 @@ jobs:
#----------------------------------------------
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
if: matrix.python-version == 3.11
if: matrix.python-version == 3.12
with:
token: ${{ secrets.CODECOV_TOKEN }} # not required for public repos
directory: .
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -78,3 +78,4 @@ target/
# Sphinx-galery
docs/auto_examples/sg_execution_times.*
docs/auto_examples/*.pickle
docs/sg_execution_times.rst
10 changes: 5 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ repos:
exclude: docs/auto_examples
- repo: https://github.com/charliermarsh/ruff-pre-commit
# Ruff version.
rev: 'v0.0.257'
rev: v0.3.7
hooks:
# Run the linter.
- id: ruff
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
args: [ --fix ]
# Run the formatter.
- id: ruff-format

- repo: local
hooks:
Expand Down
13 changes: 5 additions & 8 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,23 @@ version: 2

# Set the version of Python and other tools you might need
build:
os: ubuntu-20.04
os: ubuntu-22.04
tools:
python: "3.11"
python: "3.12"
apt_packages:
- graphviz
jobs:
post_create_environment:
# Install poetry
# https://python-poetry.org/docs/#installing-manually
- pip install poetry
- python -m pip install poetry
# Tell poetry to not use a virtual environment
- poetry config virtualenvs.create false
post_install:
# Install dependencies with 'docs' dependency group
# https://python-poetry.org/docs/managing-dependencies/#dependency-groups
- poetry install --extras diagrams --with docs
- VIRTUAL_ENV=$READTHEDOCS_VIRTUALENV_PATH poetry install --extras diagrams --with docs

# Build documentation in the docs/ directory with Sphinx
sphinx:
configuration: docs/conf.py

python:
install:
- requirements: docs/requirements.txt
2 changes: 1 addition & 1 deletion docs/diagram.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ A handy shortcut to have the graph representation:
```py
>>> machine._graph()
<pydot.Dot ...
<pydot.core.Dot ...
```

Expand Down
Binary file modified docs/images/order_control_machine_initial.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/order_control_machine_processing.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/readme_trafficlightmachine.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified docs/images/test_state_machine_internal.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 0 additions & 4 deletions docs/requirements.txt

This file was deleted.

1,557 changes: 839 additions & 718 deletions poetry.lock

Large diffs are not rendered by default.

79 changes: 42 additions & 37 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,28 @@ classifiers = [
diagrams = ["pydot"]

[tool.poetry.dependencies]
python = ">=3.7, <3.13"
python = ">=3.9, <3.13"

[tool.poetry.group.dev.dependencies]
pytest = "^7.2.0"
pytest-cov = "^4.0.0"
pytest-sugar = "^0.9.6"
pydot = "^1.4.2"
ruff = "^0.0.257"
pre-commit = "^2.21.0"
mypy = "^0.991"
black = "^22.12.0"
pytest = "^8.1.1"
pytest-cov = "^5.0.0"
pytest-sugar = "^1.0.0"
pydot = "^2.0.0"
ruff = "^0.3.7"
pre-commit = "^3.7.0"
mypy = "^1.9.0"
pdbpp = "^0.10.3"
pytest-mock = "^3.10.0"
pytest-profiling = "^1.7.0"
pytest-benchmark = "^4.0.0"

[tool.poetry.group.docs.dependencies]
Sphinx = "4.5.0"
sphinx-rtd-theme = "1.1.1"
myst-parser = "^0.18.1"
sphinx-gallery = "^0.11.1"
pillow = "^9.4.0"
sphinx-autobuild = "^2021.3.14"
Sphinx = "7.2.6"
sphinx-rtd-theme = "2.0.0"
myst-parser = "^2.0.0"
sphinx-gallery = "^0.15.0"
pillow = "^10.3.0"
sphinx-autobuild = "^2024.4.16"

[build-system]
requires = ["poetry-core"]
Expand Down Expand Up @@ -91,24 +90,8 @@ max-line-length = 99
[tool.ruff]
src = ["statemachine"]

# Enable Pyflakes and pycodestyle rules.
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort
"UP", # pyupgrade
"C", # flake8-comprehensions
"B", # flake8-bugbear
"PT", # flake8-pytest-style
]
ignore = [
"UP006", # `use-pep585-annotation` Requires Python3.9+
"UP035", # `use-pep585-annotation` Requires Python3.9+
"UP038", # `use-pep585-annotation` Requires Python3.9+
]

line-length = 99
target-version = "py312"

# Exclude a variety of commonly ignored directories.
exclude = [
Expand All @@ -131,19 +114,41 @@ exclude = [
"venv",
]

[tool.ruff.lint]

# Enable Pyflakes and pycodestyle rules.
select = [
"E", # pycodestyle errors
"W", # pycodestyle warnings
"F", # pyflakes
"I", # isort
"UP", # pyupgrade
"C", # flake8-comprehensions
"B", # flake8-bugbear
"PT", # flake8-pytest-style
]
ignore = [
"UP006", # `use-pep585-annotation` Requires Python3.9+
"UP035", # `use-pep585-annotation` Requires Python3.9+
"UP038", # `use-pep585-annotation` Requires Python3.9+
]

# Allow unused variables when underscore-prefixed.
dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"

# Assume Python 3.11.
target-version = "py311"
[tool.ruff.lint.per-file-ignores]
# Ignore `E402` (import violations) in all `__init__.py` files, and in `path/to/file.py`.
"__init__.py" = ["E402"]
"path/to/file.py" = ["E402"]
"tests/examples/**.py" = ["B018"]

[tool.ruff.mccabe]
[tool.ruff.lint.mccabe]
max-complexity = 6

[tool.ruff.isort]
[tool.ruff.lint.isort]
force-single-line = true

[tool.ruff.pydocstyle]
[tool.ruff.lint.pydocstyle]
# Use Google-style docstrings.
convention = "google"

Expand Down
12 changes: 3 additions & 9 deletions statemachine/callbacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,7 @@ def build(self, resolver) -> "CallbackWrapper | None":

if not self.suppress_errors:
raise AttrNotFound(
_("Did not found name '{}' from model or statemachine").format(
self.func
)
_("Did not found name '{}' from model or statemachine").format(self.func)
)
return None

Expand Down Expand Up @@ -226,9 +224,7 @@ def add(self, items: CallbackMetaList, resolver: Callable):

def call(self, *args, **kwargs):
return [
callback(*args, **kwargs)
for callback in self
if callback.condition(*args, **kwargs)
callback(*args, **kwargs) for callback in self if callback.condition(*args, **kwargs)
]

def all(self, *args, **kwargs):
Expand All @@ -237,9 +233,7 @@ def all(self, *args, **kwargs):

class CallbacksRegistry:
def __init__(self) -> None:
self._registry: Dict[CallbackMetaList, CallbacksExecutor] = defaultdict(
CallbacksExecutor
)
self._registry: Dict[CallbackMetaList, CallbacksExecutor] = defaultdict(CallbacksExecutor)

def register(self, callbacks: CallbackMetaList, resolver):
executor_list = self[callbacks]
Expand Down
4 changes: 1 addition & 3 deletions statemachine/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,7 @@ def search_callable(attr, *configs) -> WrapSearchResult:
func = config.getattr(attr)
if func is not None:
if not callable(func):
return AttributeCallableSearchResult(
attr, config.obj, config.resolver_id
)
return AttributeCallableSearchResult(attr, config.obj, config.resolver_id)

if getattr(func, "_is_sm_event", False):
return EventSearchResult(attr, func, config.resolver_id)
Expand Down
12 changes: 5 additions & 7 deletions statemachine/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ def __init__(
if TYPE_CHECKING:
"""Makes mypy happy with dynamic created attributes"""

def __getattr__(self, attribute: str) -> Any:
...
def __getattr__(self, attribute: str) -> Any: ...

def _check(cls):
has_states = bool(cls.states)
Expand Down Expand Up @@ -96,9 +95,9 @@ def _check_final_states(cls):

if final_state_with_invalid_transitions:
raise InvalidDefinition(
_(
"Cannot declare transitions from final state. Invalid state(s): {}"
).format([s.id for s in final_state_with_invalid_transitions])
_("Cannot declare transitions from final state. Invalid state(s): {}").format(
[s.id for s in final_state_with_invalid_transitions]
)
)

def _check_trap_states(cls):
Expand Down Expand Up @@ -131,8 +130,7 @@ def _states_without_path_to_final_states(cls):
return [
state
for state in cls.states
if not state.final
and not any(s.final for s in visit_connected_states(state))
if not state.final and not any(s.final for s in visit_connected_states(state))
]

def _disconnected_states(cls, starting_state):
Expand Down
4 changes: 1 addition & 3 deletions statemachine/mixins.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
if not self.state_machine_name:
raise ValueError(
_("{!r} is not a valid state machine name.").format(
self.state_machine_name
)
_("{!r} is not a valid state machine name.").format(self.state_machine_name)
)
machine_cls = registry.get_machine_cls(self.state_machine_name)
setattr(
Expand Down
4 changes: 1 addition & 3 deletions statemachine/signature.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def _make_key(method):


def signature_cache(user_function):

cache = {}
cache_get = cache.get

Expand Down Expand Up @@ -113,8 +112,7 @@ def bind_expected(self, *args: Any, **kwargs: Any) -> BoundArguments: # noqa: C
parameters_ex = (param,)
break
elif (
param.kind == Parameter.VAR_KEYWORD
or param.default is not Parameter.empty
param.kind == Parameter.VAR_KEYWORD or param.default is not Parameter.empty
):
# That's fine too - we have a default value for this
# parameter. So, lets start parsing `kwargs`, starting
Expand Down
24 changes: 6 additions & 18 deletions statemachine/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,7 @@ def __init__(
self.exit = CallbackMetaList().add(exit)

def __eq__(self, other):
return (
isinstance(other, State) and self.name == other.name and self.id == other.id
)
return isinstance(other, State) and self.name == other.name and self.id == other.id

def __hash__(self):
return hash(repr(self))
Expand All @@ -124,13 +122,9 @@ def _setup(self, register):
return self

def _add_observer(self, registry):
self.enter.add(
"on_enter_state", registry=registry, prepend=True, suppress_errors=True
)
self.enter.add("on_enter_state", registry=registry, prepend=True, suppress_errors=True)
self.enter.add(f"on_enter_{self.id}", registry=registry, suppress_errors=True)
self.exit.add(
"on_exit_state", registry=registry, prepend=True, suppress_errors=True
)
self.exit.add("on_exit_state", registry=registry, prepend=True, suppress_errors=True)
self.exit.add(f"on_exit_{self.id}", registry=registry, suppress_errors=True)

def __repr__(self):
Expand All @@ -146,14 +140,10 @@ def __get__(self, machine, owner):

def __set__(self, instance, value):
raise StateMachineError(
_("State overriding is not allowed. Trying to add '{}' to {}").format(
value, self.id
)
_("State overriding is not allowed. Trying to add '{}' to {}").format(value, self.id)
)

def for_instance(
self, machine: "StateMachine", cache: Dict["State", "State"]
) -> "State":
def for_instance(self, machine: "StateMachine", cache: Dict["State", "State"]) -> "State":
if self not in cache:
cache[self] = InstanceState(self, machine)

Expand All @@ -171,9 +161,7 @@ def _set_id(self, id: str):
self.name = self._id.replace("_", " ").capitalize()

def _to_(self, *states: "State", **kwargs):
transitions = TransitionList(
Transition(self, state, **kwargs) for state in states
)
transitions = TransitionList(Transition(self, state, **kwargs) for state in states)
self.transitions.add_transitions(transitions)
return transitions

Expand Down

0 comments on commit f236cad

Please sign in to comment.