diff --git a/.github/workflows/code-quality.yml b/.github/workflows/code-quality.yml index 6adff44..2a6dd1b 100644 --- a/.github/workflows/code-quality.yml +++ b/.github/workflows/code-quality.yml @@ -8,9 +8,11 @@ jobs: - uses: actions/checkout@v2 - uses: actions/setup-python@v2 with: - python-version: 3.7 + python-version: "3.7" - run: pip install --upgrade pip - - run: pip install types-setuptools "black<23" "pylint<3" "mypy<1" pytest "aiohttp<4" pyzmq "requests<3" "types-requests<3" websockets - - run: black --diff --check $(git ls-files -- '*.py' ':!:docs/*' ':!:examples/requests_client_py310.py') - - run: pylint $(git ls-files -- '*.py' ':!:docs/*' ':!:examples/requests_client_py310.py') - - run: mypy --strict $(git ls-files -- '*.py' ':!:docs/*' ':!:examples/requests_client_py310.py') + - run: pip install types-setuptools "ruff<1" "mypy<2" "black<23" "isort<6" pytest "aiohttp<3.8" pyzmq "requests<3" "types-requests<3" websockets + - run: ruff check . + - run: mypy --strict --exclude 'docs' --exclude 'examples/requests_client_py310.py' . + - run: black --check --exclude 'docs' . + - run: isort --check --profile black . + - run: pytest tests diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 116c7ee..0555fb2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,22 +1,13 @@ default_language_version: python: python3.7 -exclude: (^docs|^examples/requests_client_py310.py) +exclude: (^docs) fail_fast: true repos: - - repo: https://github.com/ambv/black - rev: 22.8.0 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: v0.1.8 hooks: - - id: black - args: [--diff, --check] - - - repo: local - hooks: - - id: pylint - name: pylint - entry: pylint - language: system + - id: ruff types: [python] - require_serial: true - repo: https://github.com/pre-commit/mirrors-mypy rev: v0.971 @@ -24,10 +15,25 @@ repos: - id: mypy args: [--strict] additional_dependencies: - - aiohttp<4 + - aiohttp<3.8 - pytest - pyzmq - requests<3 - types-requests<3 - types-setuptools - websockets + + - repo: https://github.com/ambv/black + rev: 22.8.0 + hooks: + - id: black + args: [--check] + + - repo: local + hooks: + - id: isort + name: isort + entry: isort + language: system + args: [--check,--profile,black] + types: [python] diff --git a/examples/aiohttp_client.py b/examples/aiohttp_client.py index 0c16035..1cae302 100644 --- a/examples/aiohttp_client.py +++ b/examples/aiohttp_client.py @@ -3,7 +3,8 @@ import logging from aiohttp import ClientSession -from jsonrpcclient import Ok, Error, request, parse + +from jsonrpcclient import Error, Ok, parse, request async def main() -> None: diff --git a/examples/requests_client.py b/examples/requests_client.py index 746928a..dd15484 100644 --- a/examples/requests_client.py +++ b/examples/requests_client.py @@ -1,9 +1,9 @@ """Requests client""" import logging -import requests -from jsonrpcclient import request, parse, Ok, Error +import requests +from jsonrpcclient import Error, Ok, parse, request response = requests.post("http://localhost:5000/", json=request("ping"), timeout=10) parsed = parse(response.json()) diff --git a/examples/requests_client_batch.py b/examples/requests_client_batch.py index b3803e4..3f4ff7b 100644 --- a/examples/requests_client_batch.py +++ b/examples/requests_client_batch.py @@ -2,8 +2,8 @@ import logging import requests -from jsonrpcclient import request, parse, Ok, Error +from jsonrpcclient import Error, Ok, parse, request response = requests.post( "http://localhost:5000/", json=[request("ping") for _ in range(5)], timeout=10 diff --git a/examples/requests_client_py310.py b/examples/requests_client_py310.py index dc58dee..95314ad 100644 --- a/examples/requests_client_py310.py +++ b/examples/requests_client_py310.py @@ -2,8 +2,8 @@ import logging import requests -from jsonrpcclient import request, parse, Ok, Error +from jsonrpcclient import Error, Ok, parse, request response = requests.post("http://localhost:5000/", json=request("ping"), timeout=10) diff --git a/examples/websockets_client.py b/examples/websockets_client.py index 223eccf..554dc35 100644 --- a/examples/websockets_client.py +++ b/examples/websockets_client.py @@ -3,7 +3,8 @@ import logging from websockets.client import connect -from jsonrpcclient import Ok, Error, parse_json, request_json + +from jsonrpcclient import Error, Ok, parse_json, request_json async def main() -> None: diff --git a/examples/zeromq_client.py b/examples/zeromq_client.py index 8254c68..3e0d0b9 100644 --- a/examples/zeromq_client.py +++ b/examples/zeromq_client.py @@ -3,10 +3,9 @@ import zmq -from jsonrpcclient import request_json, parse_json, Ok +from jsonrpcclient import Ok, parse_json, request_json - -socket = zmq.Context().socket(zmq.REQ) # pylint: disable=abstract-class-instantiated +socket = zmq.Context().socket(zmq.REQ) socket.connect("tcp://localhost:5000") socket.send_string(request_json("ping")) response = parse_json(socket.recv().decode()) diff --git a/jsonrpcclient/__init__.py b/jsonrpcclient/__init__.py index 80f87f7..e8d4c7f 100644 --- a/jsonrpcclient/__init__.py +++ b/jsonrpcclient/__init__.py @@ -11,7 +11,7 @@ request_random, request_uuid, ) -from .responses import Ok, Error, parse, parse_json +from .responses import Error, Ok, parse, parse_json __all__ = [ "notification", diff --git a/jsonrpcclient/requests.py b/jsonrpcclient/requests.py index 226658a..16993b5 100644 --- a/jsonrpcclient/requests.py +++ b/jsonrpcclient/requests.py @@ -34,7 +34,7 @@ def request_pure( id_generator: Iterator[Any], method: str, params: Union[Dict[str, Any], Tuple[Any, ...]], - id: Any, # pylint: disable=redefined-builtin, invalid-name + id: Any, ) -> Dict[str, Any]: """Create a request""" return { @@ -53,7 +53,7 @@ def request_impure( id_generator: Iterator[Any], method: str, params: Union[Dict[str, Any], Tuple[Any, ...], None] = None, - id: Any = NOID, # pylint: disable=redefined-builtin, invalid-name + id: Any = NOID, ) -> Dict[str, Any]: """Create a request, optionally passing params and id""" return request_pure( diff --git a/jsonrpcclient/responses.py b/jsonrpcclient/responses.py index 973bf70..b8c5d0e 100644 --- a/jsonrpcclient/responses.py +++ b/jsonrpcclient/responses.py @@ -1,6 +1,6 @@ """Responses""" -from typing import Any, Dict, Iterable, List, Union, NamedTuple import json +from typing import Any, Dict, Iterable, List, NamedTuple, Union from .utils import compose diff --git a/jsonrpcclient/sentinels.py b/jsonrpcclient/sentinels.py index 5bbb01b..a536215 100644 --- a/jsonrpcclient/sentinels.py +++ b/jsonrpcclient/sentinels.py @@ -11,7 +11,6 @@ class Sentinel: Has a nicer repr than `object()`. """ - # pylint: disable=too-few-public-methods def __init__(self, name: str): self.name = name diff --git a/jsonrpcclient/utils.py b/jsonrpcclient/utils.py index 6ab321b..8c89bbf 100644 --- a/jsonrpcclient/utils.py +++ b/jsonrpcclient/utils.py @@ -5,6 +5,4 @@ def compose(*funcs: Callable[..., Any]) -> Callable[..., Any]: """Compose two or more functions producing a single composite function.""" - return reduce( - lambda f, g: lambda *a, **kw: f(g(*a, **kw)), funcs - ) # pylint: disable=invalid-name + return reduce(lambda f, g: lambda *a, **kw: f(g(*a, **kw)), funcs) diff --git a/pyproject.toml b/pyproject.toml index 27e1af4..9e100b0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -38,3 +38,14 @@ packages = [ "jsonrpcclient" ] zip-safe = false + +[tool.ruff] +# Same as Black. +line-length = 88 +indent-width = 4 + +[tool.mypy] +python_version = "3.7" +exclude = [ + '^examples\/requests_client_py310\.py$', +] diff --git a/tests/test_id_generators.py b/tests/test_id_generators.py index 618da18..dd25bb3 100644 --- a/tests/test_id_generators.py +++ b/tests/test_id_generators.py @@ -1,5 +1,4 @@ """Test id_generators.py""" -# pylint: disable=missing-function-docstring import re from uuid import UUID diff --git a/tests/test_requests.py b/tests/test_requests.py index a0f89ac..d6928a6 100644 --- a/tests/test_requests.py +++ b/tests/test_requests.py @@ -1,5 +1,4 @@ """Test requests.py""" -# pylint: disable=missing-function-docstring from typing import Any, Dict import pytest diff --git a/tests/test_responses.py b/tests/test_responses.py index b53f44e..e885ee9 100644 --- a/tests/test_responses.py +++ b/tests/test_responses.py @@ -1,5 +1,4 @@ """Test responses.py""" -# pylint: disable=missing-function-docstring from typing import Dict import pytest diff --git a/tests/test_sentinels.py b/tests/test_sentinels.py index d9850de..af96832 100644 --- a/tests/test_sentinels.py +++ b/tests/test_sentinels.py @@ -1,5 +1,4 @@ """Test sentinels.py""" -# pylint: disable=missing-function-docstring from jsonrpcclient.sentinels import Sentinel