diff --git a/cookbook.yaml b/cookbook.yaml index 8e3cd60..6f697c2 100644 --- a/cookbook.yaml +++ b/cookbook.yaml @@ -1,6 +1,6 @@ $globals: shell: bash - version: "7.0" + version: "8.1" vars: p_sync: --sync @@ -26,7 +26,7 @@ lint: - install commands: - black --check . - - p check + - p check --lockfile - ruff check . - mypy . diff --git a/pyproject.toml b/pyproject.toml index 31b7cb7..03ee0bd 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [build-system] requires = [ - "phosphorus>=0.3", + "phosphorus>=0.5", ] build-backend = "phosphorus.construction.api" @@ -23,6 +23,8 @@ keywords = [ classifiers = [ "Development Status :: 4 - Beta", "Operating System :: OS Independent", + "Programming Language :: Python :: 3 :: Only", + "License :: OSI Approved :: BSD License", "Intended Audience :: Developers", ] @@ -40,25 +42,25 @@ documentation = "https://tvdb-api-client.readthedocs.io/en/stable/" [tool.phosphorus.dev-dependencies] dev = [ - "ipdb~=0.13; python_version>='3.10'", - "ipython~=8.21; python_version>='3.10'", + "ipdb~=0.13", + "ipython~=8.18", ] lint = [ - "black~=24.1", - "mypy~=1.8", - "ruff~=0.5", + "black~=24.10", + "mypy~=1.12", + "ruff~=0.7", "types-requests~=2.0", ] test = [ - "pytest~=8.0", + "pytest~=8.3", "pytest-cov~=5.0", ] docs = [ "mkdocs~=1.6", "mkdocs-material~=9.5", "mkdocs-material-extensions~=1.3", - "Pygments~=2.17", - "pymdown-extensions~=10.8", + "pygments~=2.18", + "pymdown-extensions~=10.11", ] [tool.black] @@ -122,11 +124,10 @@ select = [ "PGH", "PERF", "PIE", - "PLC", - "PLE", - "PLW", + "PL", "PT", "PTH", + "PYI", "Q", "RET", "RSE", @@ -151,6 +152,7 @@ ignore = [ "COM812", "E501", "FIX002", + "PLR09", "TD002", "TD003", "TRY003", @@ -159,6 +161,7 @@ ignore = [ [tool.ruff.lint.per-file-ignores] "tests/**" = [ "FBT001", + "PLR2004", "PT011", "S101", ] @@ -178,16 +181,20 @@ forced-separate = [ split-on-trailing-comma = false [tool.pytest.ini_options] -addopts = "-vv" +addopts = "-ra -v --cov" testpaths = "tests" [tool.coverage.run] +branch = true source = [ "src/", ] data_file = ".cov_cache/coverage.dat" [tool.coverage.report] +exclude_also = [ + "if TYPE_CHECKING:", +] show_missing = true skip_covered = true skip_empty = true diff --git a/src/tvdb_api_client/client.py b/src/tvdb_api_client/client.py index 5006d93..68b47b5 100644 --- a/src/tvdb_api_client/client.py +++ b/src/tvdb_api_client/client.py @@ -2,6 +2,7 @@ import json from base64 import urlsafe_b64decode +from http import HTTPStatus from typing import Any, Protocol, cast import requests @@ -55,11 +56,11 @@ def _generate_token(self) -> str: data=json.dumps(self._auth_data), timeout=(60, 120), ) - if response.status_code == 401: + if response.status_code == HTTPStatus.UNAUTHORIZED: msg = "Invalid credentials." raise ConnectionRefusedError(msg) - if response.status_code != 200: + if response.status_code != HTTPStatus.OK: msg = "Unexpected Response." raise ConnectionError(msg) @@ -75,14 +76,14 @@ def _get(self, url: URL) -> dict[str, Any]: headers = {"accept": "application/json", "Authorization": f"Bearer {token}"} response = requests.get(url.string, headers=headers, timeout=(60, 120)) - if response.status_code == 200: + if response.status_code == HTTPStatus.OK: return cast(dict[str, Any], response.json()) - if response.status_code in {400, 404}: + if response.status_code in {HTTPStatus.BAD_REQUEST, HTTPStatus.NOT_FOUND}: msg = "There are no data for this term." raise LookupError(msg) - if response.status_code == 401: + if response.status_code == HTTPStatus.UNAUTHORIZED: msg = "Invalid credentials." raise ConnectionRefusedError(msg)