Skip to content

Commit

Permalink
Replace pylint with ruff (#225)
Browse files Browse the repository at this point in the history
* Replace pylint with ruff

Closes #221

* Adjust github actions

* Use python 3.10 in github workflow

* Fix "python 3.1"

* Fix pytest in github workflow

* Go back to Python 3.7
  • Loading branch information
bcb authored Dec 29, 2023
1 parent f9cf5d1 commit 25038ba
Show file tree
Hide file tree
Showing 18 changed files with 53 additions and 40 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
34 changes: 20 additions & 14 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,33 +1,39 @@
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
hooks:
- 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]
3 changes: 2 additions & 1 deletion examples/aiohttp_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions examples/requests_client.py
Original file line number Diff line number Diff line change
@@ -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())
Expand Down
2 changes: 1 addition & 1 deletion examples/requests_client_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion examples/requests_client_py310.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
3 changes: 2 additions & 1 deletion examples/websockets_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions examples/zeromq_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion jsonrpcclient/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions jsonrpcclient/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion jsonrpcclient/responses.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
1 change: 0 additions & 1 deletion jsonrpcclient/sentinels.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 1 addition & 3 deletions jsonrpcclient/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
11 changes: 11 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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$',
]
1 change: 0 additions & 1 deletion tests/test_id_generators.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Test id_generators.py"""
# pylint: disable=missing-function-docstring
import re
from uuid import UUID

Expand Down
1 change: 0 additions & 1 deletion tests/test_requests.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Test requests.py"""
# pylint: disable=missing-function-docstring
from typing import Any, Dict

import pytest
Expand Down
1 change: 0 additions & 1 deletion tests/test_responses.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Test responses.py"""
# pylint: disable=missing-function-docstring
from typing import Dict

import pytest
Expand Down
1 change: 0 additions & 1 deletion tests/test_sentinels.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Test sentinels.py"""
# pylint: disable=missing-function-docstring
from jsonrpcclient.sentinels import Sentinel


Expand Down

0 comments on commit 25038ba

Please sign in to comment.