Skip to content

Commit

Permalink
Replace flake8 and black with ruff (#118)
Browse files Browse the repository at this point in the history
* Lint with ruff

* Update precommit config

* Remove setup.cfg

* Update CI for use with ruff

* Remove --check from pre-commit step

* Enable line-too-long check

* Also apply fixes for linting on pre-commit

* Tryout using ruff/isort default settings

* Cleanup pyproject.toml
  • Loading branch information
berendkleinhaneveld authored Dec 2, 2023
1 parent fb7c682 commit 3fcc63c
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 279 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@ jobs:
- name: Install dependencies
run: poetry install
- name: Lint
run: poetry run flake8
run: poetry run ruff .
- name: Format
run: poetry run ruff format --check .

test:
name: Test on ${{ matrix.name }}
Expand Down
16 changes: 10 additions & 6 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
repos:
- repo: local
hooks:
- id: flake8
name: Linting
entry: poetry run flake8
- id: ruff (format)
name: Format
entry: poetry run ruff format
language: system
types: [python]
require_serial: true
- id: ruff (lint)
name: Lint
entry: poetry run ruff --fix
language: system
types: [python]
require_serial: true
- repo: local
hooks:
- id: pytest
name: Tests
name: Test
entry: poetry run pytest tests
language: system
types: [python]
Expand Down
2 changes: 1 addition & 1 deletion examples/store_with_undo_redo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
for undo/redo functionality
"""
from observ import watch
from observ.store import computed, mutation, Store
from observ.store import Store, computed, mutation


class CounterStore(Store):
Expand Down
2 changes: 1 addition & 1 deletion observ/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@
to_raw,
)
from .scheduler import scheduler
from .watcher import computed, watch, watch_effect, Watcher
from .watcher import Watcher, computed, watch, watch_effect
6 changes: 4 additions & 2 deletions observ/dep.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
Deps implement the classic observable pattern, and
are attached to observable datastructures.
"""
from typing import List
from __future__ import annotations

from typing import ClassVar
from weakref import WeakSet


class Dep:
__slots__ = ("_subs", "__weakref__")
stack: List["Watcher"] = [] # noqa: F821
stack: ClassVar[list["Watcher"]] = [] # noqa: F821

def __init__(self) -> None:
self._subs: WeakSet["Watcher"] = None # noqa: F821
Expand Down
3 changes: 1 addition & 2 deletions observ/dict_proxy.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from .proxy import Proxy, TYPE_LOOKUP
from .proxy import TYPE_LOOKUP, Proxy
from .proxy_db import proxy_db
from .traps import construct_methods_traps_dict, trap_map, trap_map_readonly


dict_traps = {
"READERS": {
"copy",
Expand Down
3 changes: 1 addition & 2 deletions observ/list_proxy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from .proxy import Proxy, TYPE_LOOKUP
from .proxy import TYPE_LOOKUP, Proxy
from .traps import construct_methods_traps_dict, trap_map, trap_map_readonly


list_traps = {
"READERS": {
"count",
Expand Down
2 changes: 1 addition & 1 deletion observ/proxy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from functools import partial
from typing import cast, Generic, Literal, TypedDict, TypeVar
from typing import Generic, Literal, TypedDict, TypeVar, cast

from .proxy_db import proxy_db

Expand Down
8 changes: 4 additions & 4 deletions observ/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
and should be integrated in the event loop of your choosing.
"""
import asyncio
from bisect import bisect
from collections import defaultdict
import importlib
import warnings
from bisect import bisect
from collections import defaultdict


class Scheduler:
Expand Down Expand Up @@ -65,7 +65,7 @@ def register_qt(self):
"""
for qt in ("PySide6", "PyQt6", "PySide2", "PyQt5", "PySide", "PyQt4"):
try:
QtCore = importlib.import_module(f"{qt}.QtCore")
QtCore = importlib.import_module(f"{qt}.QtCore") # noqa: N806
break
except ImportError:
continue
Expand All @@ -78,7 +78,7 @@ def register_qt(self):
warnings.warn(
"QtAsyncio module available: please consider using `register_asyncio` "
"and call the following code:\n"
f" from {qt} import QtAsyncio\n" # noqa: E272
f" from {qt} import QtAsyncio\n"
" asyncio.set_event_loop_policy(QtAsyncio.QAsyncioEventLoopPolicy())"
""
)
Expand Down
3 changes: 1 addition & 2 deletions observ/set_proxy.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from .proxy import Proxy, TYPE_LOOKUP
from .proxy import TYPE_LOOKUP, Proxy
from .traps import construct_methods_traps_dict, trap_map, trap_map_readonly


set_traps = {
"READERS": {
"copy",
Expand Down
1 change: 0 additions & 1 deletion observ/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
)
from .watcher import computed as computed_expression


T = TypeVar("T", bound=Callable)


Expand Down
5 changes: 2 additions & 3 deletions observ/watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,19 @@
from __future__ import annotations

import asyncio
import inspect
from collections.abc import Awaitable, Container
from functools import partial, wraps
import inspect
from itertools import count
from typing import Any, Callable, Generic, Optional, TypeVar, Union
from weakref import ref, WeakSet
from weakref import WeakSet, ref

from .dep import Dep
from .dict_proxy import DictProxyBase
from .list_proxy import ListProxyBase
from .scheduler import scheduler
from .set_proxy import SetProxyBase


T = TypeVar("T")
Watchable = Union[
Callable[[], T],
Expand Down
Loading

0 comments on commit 3fcc63c

Please sign in to comment.