Skip to content

Commit

Permalink
chore/style: update precommit hooks + fix style
Browse files Browse the repository at this point in the history
  • Loading branch information
tazlin committed Feb 17, 2024
1 parent f9db4aa commit 39eebd2
Show file tree
Hide file tree
Showing 19 changed files with 29 additions and 11 deletions.
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions horde_sdk/__init__.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions horde_sdk/ai_horde_api/ai_horde_clients.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Definitions to help interact with the AI-Horde API."""

from __future__ import annotations

import asyncio
Expand Down
1 change: 1 addition & 0 deletions horde_sdk/ai_horde_api/apimodels/__init__.py
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
1 change: 1 addition & 0 deletions horde_sdk/ai_horde_api/apimodels/base.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""The base classes for all AI Horde API requests/responses."""

from __future__ import annotations

import os
Expand Down
2 changes: 1 addition & 1 deletion horde_sdk/ai_horde_api/apimodels/generate/_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions horde_sdk/ai_horde_api/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions horde_sdk/ai_horde_api/metadata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Request metadata specific to the AI-Horde API."""

from horde_sdk.generic_api.metadata import GenericPathFields


Expand Down
1 change: 1 addition & 0 deletions horde_sdk/generic_api/apimodels.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""API data model bases applicable across all (or many) horde APIs."""

from __future__ import annotations

import abc
Expand Down
1 change: 1 addition & 0 deletions horde_sdk/ratings_api/apimodels.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Model definitions for AI Horde Ratings API."""

import uuid
from enum import auto

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

Expand Down
1 change: 1 addition & 0 deletions horde_sdk/ratings_api/metadata.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Request metadata specific to the Ratings API."""

from enum import auto

from horde_sdk.generic_api.metadata import GenericPathFields, GenericQueryFields
Expand Down
1 change: 1 addition & 0 deletions horde_sdk/scripts/write_all_payload_examples_for_tests.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions horde_sdk/scripts/write_all_response_examples_for_tests.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
18 changes: 12 additions & 6 deletions tests/ai_horde_api/test_ai_horde_api_calls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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(),
Expand Down
1 change: 1 addition & 0 deletions tests/ai_horde_api/test_ai_horde_api_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Unit tests for AI-Horde API models."""

import json
from uuid import UUID

Expand Down
1 change: 1 addition & 0 deletions tests/test_dynamically_check_apimodels.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down
1 change: 1 addition & 0 deletions tests/test_generic.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Test generic API models not specific to a particular API."""

import json

from horde_sdk.generic_api.apimodels import RequestErrorResponse
Expand Down
1 change: 0 additions & 1 deletion tests/test_ratings_api_models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"""Unit tests for Ratings API models."""


import pydantic
import pytest

Expand Down

0 comments on commit 39eebd2

Please sign in to comment.