Skip to content

Commit 2b53451

Browse files
authored
use ruff for formatting (#162)
1 parent f141a4c commit 2b53451

28 files changed

+583
-1130
lines changed

.github/workflows/pull-request.yaml

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ on:
44
push:
55
branches: [ main ]
66
jobs:
7-
lint-format-types-unit:
7+
lint-format-types:
88
runs-on: ubuntu-latest
99
strategy:
1010
matrix:
11-
python-version: ["3.8", "3.13"]
11+
python-version: ["3.13"]
1212
steps:
1313
- uses: actions/checkout@v4
1414
- name: Install uv
@@ -20,29 +20,32 @@ jobs:
2020
run: uv python install ${{ matrix.python-version }}
2121
- name: Install dependencies
2222
run: uv sync --extra dev
23-
- name: Pylint
24-
run: uv run pylint dune_client/
25-
- name: Black
26-
run: uv run black --check ./
23+
- name: Format Check
24+
run: make fmt
25+
- name: Lint
26+
run: make lint
2727
- name: Type Check (mypy)
28-
run: uv run mypy dune_client --strict
29-
- name: Unit Tests
30-
run: uv run python -m pytest tests/unit
28+
run: make types
3129

32-
e2e-tests:
30+
tests:
3331
runs-on: ubuntu-latest
32+
strategy:
33+
matrix:
34+
python-version: ["3.13"]
3435
steps:
3536
- uses: actions/checkout@v4
3637
- name: Install uv
3738
uses: astral-sh/setup-uv@v6
3839
with:
3940
enable-cache: true
4041
cache-dependency-glob: "uv.lock"
41-
- name: Set up Python 3.13
42-
run: uv python install 3.13
42+
- name: Set up Python ${{ matrix.python-version }}
43+
run: uv python install ${{ matrix.python-version }}
4344
- name: Install dependencies
4445
run: uv sync --extra dev
46+
- name: Unit Tests
47+
run: make test-unit
4548
- name: End to End Tests
4649
env:
4750
DUNE_API_KEY: ${{ secrets.DUNE_API_KEY }}
48-
run: uv run python -m pytest tests/e2e
51+
run: make test-e2e

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@ clean:
1313
rm -rf __pycache__
1414

1515
fmt:
16-
uv run black ./
16+
uv run ruff format
1717

1818
lint:
19-
uv run pylint dune_client/
19+
uv run ruff check
20+
21+
lint-fix:
22+
uv run ruff check --fix
2023

2124
types:
2225
uv run mypy dune_client/ --strict

dune_client/api/base.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
import logging.config
1010
import os
1111
from json import JSONDecodeError
12-
from typing import Any, Dict, List, Optional, Union, IO
12+
from typing import IO, Any
1313

1414
from requests import Response, Session
1515
from requests.adapters import HTTPAdapter, Retry
@@ -23,14 +23,13 @@
2323
MAX_NUM_ROWS_PER_BATCH = 32_000
2424

2525

26-
# pylint: disable=too-few-public-methods
2726
class BaseDuneClient:
2827
"""
2928
A Base Client for Dune which sets up default values
3029
and provides some convenient functions to use in other clients
3130
"""
3231

33-
def __init__( # pylint: disable=too-many-arguments
32+
def __init__(
3433
self,
3534
api_key: str,
3635
base_url: str = "https://api.dune.com",
@@ -67,15 +66,15 @@ def from_env(cls) -> BaseDuneClient:
6766
return cls(
6867
api_key=os.environ["DUNE_API_KEY"],
6968
base_url=os.environ.get("DUNE_API_BASE_URL", "https://api.dune.com"),
70-
request_timeout=float(os.environ.get("DUNE_API_REQUEST_TIMEOUT", 10)),
69+
request_timeout=float(os.environ.get("DUNE_API_REQUEST_TIMEOUT", "10")),
7170
)
7271

7372
@property
7473
def api_version(self) -> str:
7574
"""Returns client version string"""
7675
return f"/api/{self.client_version}"
7776

78-
def default_headers(self) -> Dict[str, str]:
77+
def default_headers(self) -> dict[str, str]:
7978
"""Return default headers containing Dune Api token"""
8079
client_version = get_package_version("dune-client") or "1.3.0"
8180
return {
@@ -89,15 +88,15 @@ def default_headers(self) -> Dict[str, str]:
8988

9089
def _build_parameters(
9190
self,
92-
params: Optional[Dict[str, Union[str, int]]] = None,
93-
columns: Optional[List[str]] = None,
94-
sample_count: Optional[int] = None,
95-
filters: Optional[str] = None,
96-
sort_by: Optional[List[str]] = None,
97-
limit: Optional[int] = None,
98-
offset: Optional[int] = None,
91+
params: dict[str, str | int] | None = None,
92+
columns: list[str] | None = None,
93+
sample_count: int | None = None,
94+
filters: str | None = None,
95+
sort_by: list[str] | None = None,
96+
limit: int | None = None,
97+
offset: int | None = None,
9998
allow_partial_results: str = "true",
100-
) -> Dict[str, Union[str, int]]:
99+
) -> dict[str, str | int]:
101100
"""
102101
Utility function that builds a dictionary of parameters to be used
103102
when retrieving advanced results (filters, pagination, sorting, etc.).
@@ -138,13 +137,14 @@ def _handle_response(self, response: Response) -> Any:
138137
# Some responses can be decoded and converted to DuneErrors
139138
response_json = response.json()
140139
self.logger.debug(f"received response {response_json}")
141-
return response_json
142140
except JSONDecodeError as err:
143141
# Others can't. Only raise HTTP error for not decodable errors
144142
response.raise_for_status()
145143
raise ValueError("Unreachable since previous line raises") from err
144+
else:
145+
return response_json
146146

147-
def _route_url(self, route: Optional[str] = None, url: Optional[str] = None) -> str:
147+
def _route_url(self, route: str | None = None, url: str | None = None) -> str:
148148
if route is not None:
149149
final_url = f"{self.base_url}{self.api_version}{route}"
150150
elif url is not None:
@@ -156,10 +156,10 @@ def _route_url(self, route: Optional[str] = None, url: Optional[str] = None) ->
156156

157157
def _get(
158158
self,
159-
route: Optional[str] = None,
160-
params: Optional[Any] = None,
159+
route: str | None = None,
160+
params: Any | None = None,
161161
raw: bool = False,
162-
url: Optional[str] = None,
162+
url: str | None = None,
163163
) -> Any:
164164
"""Generic interface for the GET method of a Dune API request"""
165165
final_url = self._route_url(route=route, url=url)
@@ -178,9 +178,9 @@ def _get(
178178
def _post(
179179
self,
180180
route: str,
181-
params: Optional[Any] = None,
182-
data: Optional[IO[bytes]] = None,
183-
headers: Optional[Dict[str, str]] = None,
181+
params: Any | None = None,
182+
data: IO[bytes] | None = None,
183+
headers: dict[str, str] | None = None,
184184
) -> Any:
185185
"""Generic interface for the POST method of a Dune API request"""
186186
url = self._route_url(route)

dune_client/api/custom.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
"""
55

66
from __future__ import annotations
7-
from typing import List, Optional
87

98
from dune_client.api.base import BaseRouter
109
from dune_client.models import (
@@ -13,7 +12,6 @@
1312
)
1413

1514

16-
# pylint: disable=duplicate-code
1715
class CustomEndpointAPI(BaseRouter):
1816
"""
1917
Custom endpoints API implementation.
@@ -25,12 +23,12 @@ def get_custom_endpoint_result(
2523
self,
2624
handle: str,
2725
endpoint: str,
28-
limit: Optional[int] = None,
29-
offset: Optional[int] = None,
30-
columns: Optional[List[str]] = None,
31-
sample_count: Optional[int] = None,
32-
filters: Optional[str] = None,
33-
sort_by: Optional[List[str]] = None,
26+
limit: int | None = None,
27+
offset: int | None = None,
28+
columns: list[str] | None = None,
29+
sample_count: int | None = None,
30+
filters: str | None = None,
31+
sort_by: list[str] | None = None,
3432
) -> ResultsResponse:
3533
"""
3634
Custom endpoints allow you to fetch and filter data from any

dune_client/api/execution.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@
1212
from deprecated import deprecated
1313

1414
from dune_client.api.base import (
15-
BaseRouter,
16-
DUNE_CSV_NEXT_URI_HEADER,
1715
DUNE_CSV_NEXT_OFFSET_HEADER,
16+
DUNE_CSV_NEXT_URI_HEADER,
17+
BaseRouter,
1818
)
1919
from dune_client.models import (
20+
DuneError,
2021
ExecutionResponse,
21-
ExecutionStatusResponse,
22-
ResultsResponse,
2322
ExecutionResultCSV,
24-
DuneError,
2523
ExecutionState,
24+
ExecutionStatusResponse,
25+
ResultsResponse,
2626
)
2727
from dune_client.query import QueryBase
2828

@@ -39,9 +39,7 @@ def execute_query(
3939
params = query.request_format()
4040
params["performance"] = performance or self.performance
4141

42-
self.logger.info(
43-
f"executing {query.query_id} on {performance or self.performance} cluster"
44-
)
42+
self.logger.info(f"executing {query.query_id} on {performance or self.performance} cluster")
4543
response_json = self._post(
4644
route=f"/query/{query.query_id}/execute",
4745
params=params,
@@ -60,9 +58,10 @@ def cancel_execution(self, job_id: str) -> bool:
6058
try:
6159
# No need to make a dataclass for this since it's just a boolean.
6260
success: bool = response_json["success"]
63-
return success
6461
except KeyError as err:
6562
raise DuneError(response_json, "CancellationResponse", err) from err
63+
else:
64+
return success
6665

6766
def get_execution_status(self, job_id: str) -> ExecutionStatusResponse:
6867
"""GET status from Dune API for `job_id` (aka `execution_id`)"""
@@ -144,9 +143,10 @@ def _get_execution_results_by_url(
144143
f"execution {result.execution_id} resulted in a partial "
145144
f"result set (i.e. results too large)."
146145
)
147-
return result
148146
except KeyError as err:
149147
raise DuneError(response_json, "ResultsResponse", err) from err
148+
else:
149+
return result
150150

151151
def _get_execution_results_csv_by_url(
152152
self,
@@ -177,9 +177,7 @@ def _get_execution_results_csv_by_url(
177177
# Deprecated Functions:
178178
#######################
179179
@deprecated(version="1.2.1", reason="Please use execute_query")
180-
def execute(
181-
self, query: QueryBase, performance: Optional[str] = None
182-
) -> ExecutionResponse:
180+
def execute(self, query: QueryBase, performance: Optional[str] = None) -> ExecutionResponse:
183181
"""Post's to Dune API for execute `query`"""
184182
return self.execute_query(query, performance)
185183

0 commit comments

Comments
 (0)