Skip to content

Commit

Permalink
add ruff and precommit
Browse files Browse the repository at this point in the history
  • Loading branch information
diceroll123 committed Dec 9, 2024
1 parent 8e8c664 commit 6411175
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 38 deletions.
15 changes: 15 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,18 @@ jobs:
shell: bash
run: |
uv run --frozen pytest
pre-commit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Install uv
uses: astral-sh/setup-uv@v4

- name: Install deps
shell: bash
run: |
uv sync --frozen --only-dev
- uses: pre-commit/action@v3.0.1
24 changes: 24 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
repos:
- repo: "https://github.com/pre-commit/pre-commit-hooks"
rev: v5.0.0
hooks:
- id: trailing-whitespace
- id: check-merge-conflict
- id: check-case-conflict
- id: check-yaml
- id: check-ast
- id: debug-statements
- id: name-tests-test
args: [--pytest-test-first]
- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.8.2
hooks:
- id: ruff
args: [--fix]
- id: ruff-format
- repo: https://gitlab.com/vojko.pribudic.foss/pre-commit-update
rev: v0.6.0post1
hooks:
- id: pre-commit-update
args: []
2 changes: 1 addition & 1 deletion dti/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from typing import TYPE_CHECKING, Any, TypeVar

if TYPE_CHECKING:
from typing_extensions import Self
from typing import Self

__all__: tuple[str, ...] = (
"AppearanceLayerKnownGlitch",
Expand Down
14 changes: 0 additions & 14 deletions dti/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,69 +2,55 @@ class DTIException(Exception):
"""Base exception class for dti.py"""



class NeopetNotFound(DTIException):
"""An exception that is thrown when searching a neopet by name returns nothing"""



class GlitchedNeopet(DTIException):
"""An exception that is thrown when a glitched neopet is requested, such as an Asparagus Hissi."""

# ideally we will never have an actual Asparagus Hissi, but this is a good example of a glitched neopet



class MissingModelData(DTIException):
"""An exception that is thrown when a pet's data isn't in DTI's database yet."""



class OutfitNotFound(DTIException):
"""An exception that is thrown when searching a DTI outfit by ID returns nothing"""



class MissingPetAppearance(DTIException):
"""An exception that is thrown when a pet appearance (species + color + pose) does not exist"""



class InvalidColor(DTIException):
"""An exception that is thrown when an invalid color is passed into the color cache."""



class InvalidSpecies(DTIException):
"""An exception that is thrown when an invalid species is passed into the species cache."""



class InvalidColorSpeciesPair(DTIException):
"""An exception that is thrown when trying to create an invalid Color/Species pair"""



class InvalidPairBytes(DTIException):
"""An exception that is thrown when the valid pet poses table data does not match. This means DTI has changed how the bit table is set up."""



class NoIteratorsFound(DTIException):
"""An exception that is thrown when search parameters are unable to form a proper search query"""



class NullAssetImage(DTIException):
"""An exception that is thrown when the biology/object image is null and must be reported to fix. Alternatively, the item does not have a PNG/SVG appearance, and only a Movie appearance."""



class InvalidItemID(DTIException):
"""An exception that is thrown when an invalid item ID is searched. The whole search query fails."""



class HTTPException(DTIException):
"""An exception that is thrown when an HTTP request operation fails."""

2 changes: 1 addition & 1 deletion dti/iterators.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
from .models import Item

if TYPE_CHECKING:
from typing_extensions import Self
from typing import Self

from .state import State
from .types import ItemPayload
Expand Down
2 changes: 0 additions & 2 deletions dti/mixins.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@


class Object:
__slots__ = ()
id: int
Expand Down
23 changes: 10 additions & 13 deletions dti/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,13 +527,10 @@ def _layer_filter(layer: AppearanceLayer) -> bool:

# A pet appearance can also restrict its own zones. The Wraith Uni is an
# interesting example: it has a horn, but its zone restrictions hide it!
if (
return not (
layer.asset_type == AppearanceLayerType.BIOLOGY
and layer.zone in self.restricted_zones
):
return False

return True
)

layer_sorter: dict[int, AppearanceLayer] = {}
for layer in filter(_layer_filter, all_layers):
Expand Down Expand Up @@ -948,8 +945,7 @@ async def _from_appearance(
/,
*,
item: Item | None = None,
) -> Neopet:
...
) -> Neopet: ...

@overload
@classmethod
Expand All @@ -959,8 +955,7 @@ async def _from_appearance(
/,
*,
items: Sequence[Item] | None = None,
) -> Neopet:
...
) -> Neopet: ...

@classmethod
async def _from_appearance(
Expand Down Expand Up @@ -1062,7 +1057,9 @@ def closet_url(self) -> str:
objects, closet = _render_items(self.items)
params["objects[]"] = [item.id for item in objects]
params["closet[]"] = [item.id for item in closet]
return f"https://impress.openneo.net/outfits/new?{urlencode(params, doseq=True)}"
return (
f"https://impress.openneo.net/outfits/new?{urlencode(params, doseq=True)}"
)

@property
def worn_items(self) -> list[Item]:
Expand Down Expand Up @@ -1308,10 +1305,10 @@ def __init__(
# for more info see https://discuss.python.org/t/parse-z-timezone-suffix-in-datetime/2220
self.created_at: datetime.datetime = datetime.datetime.fromisoformat(
data["createdAt"][:-1],
).replace(tzinfo=datetime.timezone.utc)
).replace(tzinfo=datetime.UTC)
self.updated_at: datetime.datetime = datetime.datetime.fromisoformat(
data["updatedAt"][:-1],
).replace(tzinfo=datetime.timezone.utc)
).replace(tzinfo=datetime.UTC)

@property
def legacy_url(self) -> str:
Expand All @@ -1321,7 +1318,7 @@ def legacy_url(self) -> str:
@property
def url(self) -> str:
""":class:`str`: Returns the outfit URL for the ID provided.
Since the 2020 site is soon to be deprecated, this will redirect to the legacy URL.
"""
return self.legacy_url
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ readme = "README.md"
requires-python = ">=3.10"
dependencies = [
"httpx[brotli,http2,zstd]==0.27.2",
"typing-extensions>=4.12.2",
]
license = { file = "LICENSE" }

Expand Down
2 changes: 1 addition & 1 deletion tests/test_outfit.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ def test_outfit(client: Client, outfit_data: dict[str, Any]) -> None:
2,
37,
32,
tzinfo=datetime.timezone.utc,
tzinfo=datetime.UTC,
)
6 changes: 1 addition & 5 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 6411175

Please sign in to comment.