Skip to content

Commit

Permalink
Merge branch 'origin/main' into fix-strings-in-api
Browse files Browse the repository at this point in the history
- adds support for python 3.8
  • Loading branch information
Dr-Blank committed Nov 1, 2023
2 parents e6b80d3 + ce32b76 commit 022c64c
Show file tree
Hide file tree
Showing 9 changed files with 216 additions and 206 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
python-version: ["3.10", "3.11"]
python-version: ["3.8", "3.11"]

runs-on: ${{ matrix.os }}

Expand Down
1 change: 1 addition & 0 deletions lrclib/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""LrcLib - A Python library for interacting with the LrcLib.net API."""

from .api import LrcLibAPI

__all__ = ["LrcLibAPI"]
35 changes: 16 additions & 19 deletions lrclib/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ class LrcLibAPI:
def __init__(
self,
user_agent: str,
base_url: str | None = None,
session: requests.Session | None = None,
base_url: "str | None" = None,
session: "requests.Session | None" = None,
):
self._base_url = base_url or BASE_URL
self.session = session or requests.Session()
Expand All @@ -62,18 +62,15 @@ def _make_request(
response.raise_for_status()
except requests.exceptions.HTTPError as exc:
response = exc.response # type: ignore
match response.status_code:
case HTTPStatus.NOT_FOUND:
raise NotFoundError(response) from exc
case HTTPStatus.TOO_MANY_REQUESTS:
raise RateLimitError(response) from exc
case HTTPStatus.BAD_REQUEST:
raise IncorrectPublishTokenError(response) from exc
case _ if 500 <= response.status_code < 600:
raise ServerError(response) from exc
case _:
raise APIError(response) from exc

if response.status_code == HTTPStatus.NOT_FOUND:
raise NotFoundError(response) from exc
if response.status_code == HTTPStatus.TOO_MANY_REQUESTS:
raise RateLimitError(response) from exc
if response.status_code == HTTPStatus.BAD_REQUEST:
raise IncorrectPublishTokenError(response) from exc
if 500 <= response.status_code < 600:
raise ServerError(response) from exc
raise APIError(response) from exc
return response

def get_lyrics( # pylint: disable=too-many-arguments
Expand Down Expand Up @@ -111,7 +108,7 @@ def get_lyrics( # pylint: disable=too-many-arguments
response = self._make_request("GET", endpoint, params=params)
return Lyrics.from_dict(response.json())

def get_lyrics_by_id(self, lrclib_id: str | int) -> Lyrics:
def get_lyrics_by_id(self, lrclib_id: "str | int") -> Lyrics:
"""
Get lyrics from LRCLIB by ID.
Expand All @@ -126,10 +123,10 @@ def get_lyrics_by_id(self, lrclib_id: str | int) -> Lyrics:

def search_lyrics(
self,
query: str | None = None,
track_name: str | None = None,
artist_name: str | None = None,
album_name: str | None = None,
query: "str | None" = None,
track_name: "str | None" = None,
artist_name: "str | None" = None,
album_name: "str | None" = None,
) -> SearchResult:
"""
Search lyrics from LRCLIB.
Expand Down
3 changes: 2 additions & 1 deletion lrclib/cryptographic_challenge_solver.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
""" A module that provides a class to solve a cryptographic challenge. """

# https://github.com/tranxuanthang/lrcget/blob/main/src-tauri/src/lrclib/challenge_solver.rs

import hashlib
Expand All @@ -21,7 +22,7 @@ def is_solved(self) -> bool:
return self.nonce is not None


def is_nonce_valid(prefix: str, nonce: int | str, target: bytes) -> bool:
def is_nonce_valid(prefix: str, nonce: "int | str", target: bytes) -> bool:
"""Check if the given nonce satisfies the target hash.
:param prefix: The prefix string of the challenge.
Expand Down
1 change: 1 addition & 0 deletions lrclib/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Exceptions for the LRC API."""

import requests


Expand Down
3 changes: 2 additions & 1 deletion lrclib/models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Models for api.py"""

from __future__ import annotations

from dataclasses import dataclass, field
Expand Down Expand Up @@ -116,7 +117,7 @@ class ErrorResponse(BaseModel["ErrorResponse"]):
}


class SearchResult(list[LyricsMinimal]):
class SearchResult(List[LyricsMinimal]):
"""Search result"""

def __init__(self, data: List[LyricsMinimal]) -> None:
Expand Down
369 changes: 189 additions & 180 deletions poetry.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ classifiers = [
]

[tool.poetry.dependencies]
python = "^3.10"
python = "^3.8.10"
requests = "^2.31.0"

[tool.poetry.group.dev.dependencies]
Expand All @@ -48,7 +48,7 @@ wrapt = "^1.15.0"
dill = "^0.3.7"
mypy = "^1.5.1"
vcrpy = "^5.1.0"
types-requests = "^2.31.0.7"
types-requests = "^2.31.0"



Expand Down
4 changes: 2 additions & 2 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tox]
isolated_build = true
envlist = py{310,311}, pylint, mypy, flake8
envlist = py{38,311}, pylint, mypy, flake8

[testenv]
deps =
Expand Down Expand Up @@ -33,5 +33,5 @@ commands =

[gh-actions]
python =
3.10: py310
3.8: py38
3.11: py311, pylint, mypy, flake8

0 comments on commit 022c64c

Please sign in to comment.