Skip to content

Commit 92c7203

Browse files
authored
Merge pull request #38 from reagento/refactor/setup_ci
pyproject.toml, ruff
2 parents 448746d + 508ccf1 commit 92c7203

23 files changed

+188
-96
lines changed

.github/workflows/setup.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@ jobs:
3232
run: |
3333
python -m pip install --upgrade pip
3434
pip install '.' -r requirements_dev.txt
35-
35+
36+
- name: Run ruff
37+
run: |
38+
ruff check .
39+
3640
- name: Run tests
3741
run: |
3842
pytest

.ruff.toml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
line-length = 79
2+
target-version="py38"
3+
src = ["src"]
4+
5+
include = ["src/**.py", "tests/**.py"]
6+
exclude = ["src/dishka/_adaptix/**"]
7+
8+
lint.select = [
9+
"ALL"
10+
]
11+
lint.ignore = [
12+
"ARG",
13+
"ANN",
14+
"D",
15+
"EM101",
16+
"EM102",
17+
"PT001",
18+
"PT023",
19+
"SIM108",
20+
"SIM114",
21+
"TRY003",
22+
"PLW2901",
23+
"RET505",
24+
"RET506",
25+
"PLR0913",
26+
"UP038",
27+
"TCH001",
28+
"FA100",
29+
# tempraty disabled
30+
"PGH005",
31+
"PLR2004",
32+
"N818", # compatibility issue
33+
]
34+
35+
[lint.per-file-ignores]
36+
"tests/**" = ["TID252", "PLR2004", "S101", "A002"]
37+
38+
[lint.isort]
39+
no-lines-before = ["local-folder"]
40+
41+
[lint.flake8-tidy-imports]
42+
ban-relative-imports = "parents"

pyproject.toml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
[build-system]
2+
requires = ["setuptools>=66.0"]
3+
build-backend = "setuptools.build_meta"
4+
5+
[tool.setuptools]
6+
include-package-data = true
7+
8+
[tool.setuptools.packages.find]
9+
where = ["src"]
10+
11+
[project]
12+
name = "dataclass_rest"
13+
version = "0.4"
14+
readme = "README.md"
15+
authors = [
16+
{ name = "Andrey Tikhonov", email = "[email protected]" },
17+
]
18+
license = { text = "Apache-2.0" }
19+
description = "An utility for writing simple clients for REST like APIs"
20+
requires-python = ">=3.8"
21+
classifiers = [
22+
"Programming Language :: Python :: 3",
23+
"Topic :: Software Development :: Libraries",
24+
"Typing :: Typed",
25+
"Intended Audience :: Developers",
26+
"License :: OSI Approved :: Apache Software License",
27+
"Operating System :: OS Independent",
28+
]
29+
dependencies = [
30+
"adaptix",
31+
]
32+
33+
[project.urls]
34+
"Source" = "https://github.com/reagento/dataclass-rest"
35+
"Homepage" = "https://github.com/reagento/dataclass-rest"
36+
"Bug Tracker" = "https://github.com/reagento/dataclass-rest/issues"
37+
38+

requirements_dev.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,6 @@ requests
55
requests-mock
66
mypy
77
pytest
8-
pytest-asyncio
8+
pytest-asyncio
9+
10+
ruff==0.5.*

setup.py

Lines changed: 0 additions & 37 deletions
This file was deleted.

dataclass_rest/__init__.py renamed to src/dataclass_rest/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
]
66

77
from .http_request import File
8-
from .rest import rest, get, put, post, patch, delete
8+
from .rest import delete, get, patch, post, put, rest

dataclass_rest/base_client.py renamed to src/dataclass_rest/base_client.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
from adaptix import Retort
22

33
from .client_protocol import (
4-
ClientProtocol, FactoryProtocol,
4+
ClientProtocol,
5+
FactoryProtocol,
56
)
67

78

dataclass_rest/boundmethod.py renamed to src/dataclass_rest/boundmethod.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
from abc import ABC, abstractmethod
22
from inspect import getcallargs
33
from logging import getLogger
4-
from typing import Dict, Any, Callable, Optional, NoReturn, Type
4+
from typing import Any, Callable, Dict, NoReturn, Optional, Type
55

6-
from .client_protocol import ClientProtocol, ClientMethodProtocol
7-
from .exceptions import MalformedResponse
8-
from .http_request import HttpRequest, File
6+
from .client_protocol import ClientMethodProtocol, ClientProtocol
7+
from .exceptions import ClientLibraryError, MalformedResponse
8+
from .http_request import File, HttpRequest
99
from .methodspec import MethodSpec
1010

1111
logger = getLogger(__name__)
@@ -74,7 +74,7 @@ def __call__(self, *args, **kwargs):
7474
raise NotImplementedError
7575

7676
def _on_error_default(self, response: Any) -> Any:
77-
raise RuntimeError # TODO exceptions
77+
raise ClientLibraryError
7878

7979

8080
class SyncMethod(BoundMethod):
@@ -90,8 +90,7 @@ def __call__(self, *args, **kwargs):
9090
request = self._pre_process_request(request)
9191
raw_response = self.client.do_request(request)
9292
response = self._pre_process_response(raw_response)
93-
response = self._post_process_response(response)
94-
return response
93+
return self._post_process_response(response)
9594

9695
def _pre_process_request(self, request: HttpRequest) -> HttpRequest:
9796
return request
@@ -135,8 +134,7 @@ async def __call__(self, *args, **kwargs):
135134
raw_response = await self.client.do_request(request)
136135
response = await self._pre_process_response(raw_response)
137136
await self._release_raw_response(raw_response)
138-
response = await self._post_process_response(response)
139-
return response
137+
return await self._post_process_response(response)
140138

141139
async def _pre_process_request(self, request: HttpRequest) -> HttpRequest:
142140
return request
@@ -162,7 +160,7 @@ async def _pre_process_response(self, response: Any) -> Any:
162160
raise MalformedResponse from e
163161

164162
async def _on_error_default(self, response: Any) -> NoReturn:
165-
raise RuntimeError # TODO exceptions
163+
raise ClientLibraryError
166164

167165
@abstractmethod
168166
async def _response_body(self, response: Any) -> Any:

dataclass_rest/client_protocol.py renamed to src/dataclass_rest/client_protocol.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
from typing import (
2-
Protocol, Any, Optional, Callable, Type, runtime_checkable, TypeVar,
2+
Any,
3+
Callable,
4+
Optional,
5+
Protocol,
6+
Type,
7+
TypeVar,
8+
runtime_checkable,
39
)
410

511
from .http_request import HttpRequest
@@ -18,7 +24,9 @@ class FactoryProtocol(Protocol):
1824
def load(self, data: Any, class_: Type[TypeT]) -> TypeT:
1925
raise NotImplementedError
2026

21-
def dump(self, data: TypeT, class_: Type[TypeT] = None) -> Any:
27+
def dump(
28+
self, data: TypeT, class_: Optional[Type[TypeT]] = None,
29+
) -> Any:
2230
raise NotImplementedError
2331

2432

File renamed without changes.

0 commit comments

Comments
 (0)