Skip to content

Commit

Permalink
use uv (#2)
Browse files Browse the repository at this point in the history
* use uv

* fix tests

* Update test.yml

* add ruff and precommit

* Update pyproject.toml

* Update models.py

* Update test_outfit.py
  • Loading branch information
diceroll123 authored Dec 9, 2024
1 parent 7c5e6be commit d6ce508
Show file tree
Hide file tree
Showing 12 changed files with 667 additions and 104 deletions.
30 changes: 19 additions & 11 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,25 +11,33 @@ jobs:
strategy:
fail-fast: false
matrix:
python-version: [ '3.10', '3.x' ]
python-version: [ '3.10', '3.11', '3.12', '3.13' ]

name: pytest ${{ matrix.python-version }}
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions/checkout@v4

- name: Set up CPython ${{ matrix.python-version }}
uses: actions/setup-python@v2
- name: Install uv
uses: astral-sh/setup-uv@v4
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
- name: Run tests
shell: bash
run: |
python -m pip install --upgrade pip setuptools wheel pytest pytest-asyncio
pip install -U -r requirements.txt
uv run --frozen pytest
- name: Run tests
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: |
PYTHONPATH="$(pwd)" pytest
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: []
3 changes: 0 additions & 3 deletions dev-requirements.txt

This file was deleted.

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
19 changes: 8 additions & 11 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 @@ -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
42 changes: 42 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,38 @@
[project]
name = "dti-py"
version = "0.0.1"
description = "A Python wrapper for the Dress To Impress API"
readme = "README.md"
requires-python = ">=3.10"
dependencies = [
"httpx[brotli,http2,zstd]==0.27.2",
]
license = { file = "LICENSE" }

[tool.ruff]
show-fixes = true
target-version = "py310"

[tool.ruff.lint]
extend-select = [
"C4",
"SIM",
"TC",
"UP",
"ANN201",
"ANN202",
"ANN204",
"ANN205",
"ANN206",
]
ignore = ["E501", "F403"]

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"

[tool.pytest.ini_options]
asyncio_mode = "strict"

Expand All @@ -13,3 +48,10 @@ reportUnnecessaryTypeIgnoreComment = "warning"
reportUnusedImport = "error"
pythonVersion = "3.10"
typeCheckingMode = "basic"

[dependency-groups]
dev = [
"pillow>=11.0.0",
"pytest>=8.3.4",
"pytest-asyncio>=0.24.0",
]
3 changes: 0 additions & 3 deletions requirements.txt

This file was deleted.

58 changes: 0 additions & 58 deletions setup.py

This file was deleted.

Loading

0 comments on commit d6ce508

Please sign in to comment.