diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 6c989b7..0cea6a1 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -6,11 +6,11 @@ repos: - id: end-of-file-fixer - id: trailing-whitespace - repo: https://github.com/psf/black - rev: 23.12.1 + rev: 24.2.0 hooks: - id: black - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.1.14 + rev: v0.2.1 hooks: - id: ruff - repo: https://github.com/pre-commit/mirrors-mypy diff --git a/horde_sdk/__init__.py b/horde_sdk/__init__.py index abcb2bb..4029df7 100644 --- a/horde_sdk/__init__.py +++ b/horde_sdk/__init__.py @@ -1,4 +1,5 @@ """Any model or helper useful for creating or interacting with a horde API.""" + # isort: off # We import dotenv first so that we can use it to load environment variables before importing anything else. import dotenv diff --git a/horde_sdk/ai_horde_api/ai_horde_clients.py b/horde_sdk/ai_horde_api/ai_horde_clients.py index e8e77b1..b832794 100644 --- a/horde_sdk/ai_horde_api/ai_horde_clients.py +++ b/horde_sdk/ai_horde_api/ai_horde_clients.py @@ -1,4 +1,5 @@ """Definitions to help interact with the AI-Horde API.""" + from __future__ import annotations import asyncio diff --git a/horde_sdk/ai_horde_api/apimodels/__init__.py b/horde_sdk/ai_horde_api/apimodels/__init__.py index f89431f..b899b9f 100644 --- a/horde_sdk/ai_horde_api/apimodels/__init__.py +++ b/horde_sdk/ai_horde_api/apimodels/__init__.py @@ -1,4 +1,5 @@ """All requests, responses and API models defined for the AI Horde API.""" + from horde_sdk.ai_horde_api.apimodels._find_user import ( ContributionsDetails, FindUserRequest, diff --git a/horde_sdk/ai_horde_api/apimodels/base.py b/horde_sdk/ai_horde_api/apimodels/base.py index 05b2bea..331eb52 100644 --- a/horde_sdk/ai_horde_api/apimodels/base.py +++ b/horde_sdk/ai_horde_api/apimodels/base.py @@ -1,4 +1,5 @@ """The base classes for all AI Horde API requests/responses.""" + from __future__ import annotations import os diff --git a/horde_sdk/ai_horde_api/apimodels/generate/_async.py b/horde_sdk/ai_horde_api/apimodels/generate/_async.py index 730140a..1d9ccc3 100644 --- a/horde_sdk/ai_horde_api/apimodels/generate/_async.py +++ b/horde_sdk/ai_horde_api/apimodels/generate/_async.py @@ -128,7 +128,7 @@ class ImageGenerateAsyncRequest( @model_validator(mode="before") def validate_censor_nsfw(cls, values: dict) -> dict: - if values.get("censor_nsfw", None) and values.get("nsfw", None): + if values.get("censor_nsfw") and values.get("nsfw"): raise ValueError("censor_nsfw is only valid when nsfw is False") return values diff --git a/horde_sdk/ai_horde_api/fields.py b/horde_sdk/ai_horde_api/fields.py index 045dcd1..417b51e 100644 --- a/horde_sdk/ai_horde_api/fields.py +++ b/horde_sdk/ai_horde_api/fields.py @@ -3,6 +3,7 @@ However, this module may still assist in the construction of valid requests to the API, primarily by providing additional type hints for the request and response payloads and validation. """ + import uuid from typing import Any, ClassVar diff --git a/horde_sdk/ai_horde_api/metadata.py b/horde_sdk/ai_horde_api/metadata.py index 56d921a..fcf6752 100644 --- a/horde_sdk/ai_horde_api/metadata.py +++ b/horde_sdk/ai_horde_api/metadata.py @@ -1,4 +1,5 @@ """Request metadata specific to the AI-Horde API.""" + from horde_sdk.generic_api.metadata import GenericPathFields diff --git a/horde_sdk/generic_api/apimodels.py b/horde_sdk/generic_api/apimodels.py index 49fe999..61c6889 100644 --- a/horde_sdk/generic_api/apimodels.py +++ b/horde_sdk/generic_api/apimodels.py @@ -1,4 +1,5 @@ """API data model bases applicable across all (or many) horde APIs.""" + from __future__ import annotations import abc diff --git a/horde_sdk/ratings_api/apimodels.py b/horde_sdk/ratings_api/apimodels.py index 351a65c..969f7e0 100644 --- a/horde_sdk/ratings_api/apimodels.py +++ b/horde_sdk/ratings_api/apimodels.py @@ -1,4 +1,5 @@ """Model definitions for AI Horde Ratings API.""" + import uuid from enum import auto diff --git a/horde_sdk/ratings_api/endpoints.py b/horde_sdk/ratings_api/endpoints.py index 9051a5a..6d3fbb8 100644 --- a/horde_sdk/ratings_api/endpoints.py +++ b/horde_sdk/ratings_api/endpoints.py @@ -1,6 +1,5 @@ """Information and helper functions for URL endpoints to horde APIs.""" - # TODO make RATING_API_BASE_URL a env variable? from horde_sdk.generic_api.endpoints import GENERIC_API_ENDPOINT_SUBPATH diff --git a/horde_sdk/ratings_api/metadata.py b/horde_sdk/ratings_api/metadata.py index 4925b5d..f523175 100644 --- a/horde_sdk/ratings_api/metadata.py +++ b/horde_sdk/ratings_api/metadata.py @@ -1,4 +1,5 @@ """Request metadata specific to the Ratings API.""" + from enum import auto from horde_sdk.generic_api.metadata import GenericPathFields, GenericQueryFields diff --git a/horde_sdk/scripts/write_all_payload_examples_for_tests.py b/horde_sdk/scripts/write_all_payload_examples_for_tests.py index 65e44f2..d3ee0ae 100644 --- a/horde_sdk/scripts/write_all_payload_examples_for_tests.py +++ b/horde_sdk/scripts/write_all_payload_examples_for_tests.py @@ -1,4 +1,5 @@ """Write all example payloads to a file in the tests/test_data directory.""" + from pathlib import Path from horde_sdk.ai_horde_api.endpoints import get_ai_horde_swagger_url diff --git a/horde_sdk/scripts/write_all_response_examples_for_tests.py b/horde_sdk/scripts/write_all_response_examples_for_tests.py index c8c2fcb..c47e905 100644 --- a/horde_sdk/scripts/write_all_response_examples_for_tests.py +++ b/horde_sdk/scripts/write_all_response_examples_for_tests.py @@ -1,4 +1,5 @@ """Write all example responses to a file in the tests/test_data directory.""" + from pathlib import Path from horde_sdk.ai_horde_api.endpoints import get_ai_horde_swagger_url diff --git a/tests/ai_horde_api/test_ai_horde_api_calls.py b/tests/ai_horde_api/test_ai_horde_api_calls.py index 79068c4..8f961ff 100644 --- a/tests/ai_horde_api/test_ai_horde_api_calls.py +++ b/tests/ai_horde_api/test_ai_horde_api_calls.py @@ -113,9 +113,12 @@ def test_HordeRequestSession_cleanup(self, simple_image_gen_request: ImageGenera @pytest.mark.asyncio async def test_HordeRequestSession_async(self, simple_image_gen_request: ImageGenerateAsyncRequest) -> None: """Test that the context manager cleans up correctly asynchronously.""" - async with aiohttp.ClientSession() as aiohttp_session, AIHordeAPIAsyncClientSession( - aiohttp_session=aiohttp_session, - ) as horde_session: + async with ( + aiohttp.ClientSession() as aiohttp_session, + AIHordeAPIAsyncClientSession( + aiohttp_session=aiohttp_session, + ) as horde_session, + ): api_response = await horde_session.submit_request( # noqa: F841 simple_image_gen_request, simple_image_gen_request.get_default_success_response_type(), @@ -128,9 +131,12 @@ async def test_HordeRequestSession_async_exception_raised( ) -> None: """Test that the context manager cleans up correctly asynchronously when an exception is raised.""" with pytest.raises(HordeTestException): - async with aiohttp.ClientSession() as aiohttp_session, AIHordeAPIAsyncClientSession( - aiohttp_session=aiohttp_session, - ) as horde_session: + async with ( + aiohttp.ClientSession() as aiohttp_session, + AIHordeAPIAsyncClientSession( + aiohttp_session=aiohttp_session, + ) as horde_session, + ): api_response = await horde_session.submit_request( # noqa: F841 simple_image_gen_request, simple_image_gen_request.get_default_success_response_type(), diff --git a/tests/ai_horde_api/test_ai_horde_api_models.py b/tests/ai_horde_api/test_ai_horde_api_models.py index 4e05a47..2507d3d 100644 --- a/tests/ai_horde_api/test_ai_horde_api_models.py +++ b/tests/ai_horde_api/test_ai_horde_api_models.py @@ -1,4 +1,5 @@ """Unit tests for AI-Horde API models.""" + import json from uuid import UUID diff --git a/tests/test_dynamically_check_apimodels.py b/tests/test_dynamically_check_apimodels.py index 54217c9..c6ad836 100644 --- a/tests/test_dynamically_check_apimodels.py +++ b/tests/test_dynamically_check_apimodels.py @@ -1,4 +1,5 @@ """Check that all models defined in all APIs `apimodels` module/subpackage can be instantiated from example JSON.""" + import json import os from pathlib import Path diff --git a/tests/test_generic.py b/tests/test_generic.py index e8b85f8..b8dd11e 100644 --- a/tests/test_generic.py +++ b/tests/test_generic.py @@ -1,4 +1,5 @@ """Test generic API models not specific to a particular API.""" + import json from horde_sdk.generic_api.apimodels import RequestErrorResponse diff --git a/tests/test_ratings_api_models.py b/tests/test_ratings_api_models.py index 0cc7344..3a7ecb1 100644 --- a/tests/test_ratings_api_models.py +++ b/tests/test_ratings_api_models.py @@ -1,6 +1,5 @@ """Unit tests for Ratings API models.""" - import pydantic import pytest