diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..d4c7e37 --- /dev/null +++ b/.flake8 @@ -0,0 +1,10 @@ +[flake8] +# https://lintlyci.github.io/Flake8Rules/ +# E231 missing whitespace after ',' +# E266 Too many leading '#' for block comment +# E501 Line too long (82 > 79 characters) +# W503 Line break occurred before a binary operator <- This one is flipping to the reverse as best-practice, which is how Black currently formats +# W605 Invalid escape sequence 'x' +ignore = E203, E231, E266, E501, W503, W605, E704 +max-line-length = 100 +exclude = .git, .venv, __pycache__, docs, gitlab-ci-includes diff --git a/requirements.txt b/requirements.txt index 673d161..a66ee29 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,3 @@ -aiohttp==3.8.4 -pydantic==1.10.2 +aiohttp>=3.8.4 +pydantic>=2.11.5 +pydantic-core>=2.33.2 diff --git a/rtex/__init__.py b/rtex/__init__.py index 27fdca4..034f46c 100644 --- a/rtex/__init__.py +++ b/rtex/__init__.py @@ -1 +1 @@ -__version__ = "0.0.3" +__version__ = "0.0.6" diff --git a/rtex/client.py b/rtex/client.py index 85cae41..769f2a2 100644 --- a/rtex/client.py +++ b/rtex/client.py @@ -5,7 +5,7 @@ import textwrap from typing import Optional import aiohttp -from pydantic import validate_arguments +from pydantic import validate_call from rtex.constants import DEFAULT_API_HOST, FORMAT_MIME from rtex.exceptions import RtexError, YouNeedToUseAContextManager @@ -73,7 +73,7 @@ class AsyncRtexClient: ) ) - @validate_arguments + @validate_call async def create_render( self, code: str, @@ -99,16 +99,16 @@ class AsyncRtexClient: res = await self.session.post( "/api/v2", headers={"Accept": "application/json"}, - data=request_body.json( + data=request_body.model_dump_json( exclude_defaults=True, exclude_none=True, exclude_unset=True, ), ) - return CreateLaTeXDocumentResponse.parse_obj(await res.json()).__root__ + return CreateLaTeXDocumentResponse.model_validate(await res.json()).root - @validate_arguments(config={"arbitrary_types_allowed": True}) + @validate_call(config={"arbitrary_types_allowed": True}) async def save_render( self, filename: str, @@ -127,7 +127,7 @@ class AsyncRtexClient: async for chunk, _ in res.content.iter_chunks(): output_fd.write(chunk) - @validate_arguments + @validate_call async def get_render( self, filename: str, @@ -139,7 +139,7 @@ class AsyncRtexClient: return buf - @validate_arguments + @validate_call async def render_math( self, code: str, diff --git a/rtex/models.py b/rtex/models.py index a3f91d8..06b61e8 100644 --- a/rtex/models.py +++ b/rtex/models.py @@ -1,6 +1,6 @@ from typing import Annotated, Literal, Optional, Union -from pydantic import BaseModel, Field, conint +from pydantic import BaseModel, Field, RootModel, conint RenderFormat = Literal["png", "jpg", "pdf"] RenderQuality = Annotated[int, conint(gt=0, le=100)] @@ -26,8 +26,8 @@ class CreateLaTeXDocumentErrorResponse(BaseModel): description: str -class CreateLaTeXDocumentResponse(BaseModel): - __root__: Union[ +class CreateLaTeXDocumentResponse(RootModel): + root: Union[ CreateLaTeXDocumentSuccessResponse, CreateLaTeXDocumentErrorResponse, ] = Field(discriminator="status")