From 9c7de9d8f81028c9121e5a50f6ad8bb3e15de3b6 Mon Sep 17 00:00:00 2001 From: BuriedInCode <6057651+Buried-In-Code@users.noreply.github.com> Date: Fri, 6 Oct 2023 09:42:53 +1300 Subject: [PATCH 1/3] Support Py3.12 --- .github/workflows/publishing.yaml | 4 ++-- .github/workflows/testing.yaml | 3 ++- .pre-commit-config.yaml | 12 +++-------- .readthedocs.yaml | 14 ++++++------ pyproject.toml | 24 +++++++++++---------- simyan/comicvine.py | 6 ++---- simyan/sqlite_cache.py | 36 ++++++++++++++++--------------- tests/test_exceptions.py | 2 +- 8 files changed, 49 insertions(+), 52 deletions(-) diff --git a/.github/workflows/publishing.yaml b/.github/workflows/publishing.yaml index d39158e..4256778 100644 --- a/.github/workflows/publishing.yaml +++ b/.github/workflows/publishing.yaml @@ -12,13 +12,13 @@ jobs: fail-fast: false matrix: python-version: - - '3.11' + - '3.12' os: - ubuntu-latest runs-on: ${{ matrix.os }} steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup python uses: actions/setup-python@v4 with: diff --git a/.github/workflows/testing.yaml b/.github/workflows/testing.yaml index 7e7edc6..3a06412 100644 --- a/.github/workflows/testing.yaml +++ b/.github/workflows/testing.yaml @@ -26,6 +26,7 @@ jobs: - 3.9 - '3.10' - '3.11' + - '3.12' os: - ubuntu-latest - macos-latest @@ -33,7 +34,7 @@ jobs: runs-on: ${{ matrix.os }} steps: - name: Checkout repository - uses: actions/checkout@v3 + uses: actions/checkout@v4 - name: Setup python uses: actions/setup-python@v4 with: diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 425c2a7..076ccc2 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,10 +1,10 @@ repos: - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.0.285 + rev: v0.0.292 hooks: - id: ruff - repo: https://github.com/executablebooks/mdformat - rev: 0.7.16 + rev: 0.7.17 hooks: - id: mdformat additional_dependencies: @@ -20,10 +20,8 @@ repos: - id: check-builtin-literals - id: check-case-conflict - id: check-docstring-first -# - id: check-json - id: check-merge-conflict - id: check-toml -# - id: check-xml - id: check-yaml args: - --allow-multiple-documents @@ -40,12 +38,8 @@ repos: - id: trailing-whitespace args: - --markdown-linebreak-ext=md -# - id: pretty-format-json -# args: -# - --autofix -# - --indent=2 - repo: https://github.com/psf/black - rev: 23.7.0 + rev: 23.9.1 hooks: - id: black - repo: https://github.com/pappasam/toml-sort diff --git a/.readthedocs.yaml b/.readthedocs.yaml index 0556dc6..d4594fc 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -1,19 +1,19 @@ -# .readthedocs.yaml -# Read the Docs configuration file +# Read the Docs configuration file for MkDocs projects # See https://docs.readthedocs.io/en/stable/config-file/v2.html for details # Required version: 2 -mkdocs: - configuration: mkdocs.yaml - +# Set the version of Python and other tools you might need build: os: ubuntu-22.04 tools: - python: '3.11' + python: "3.11" + +mkdocs: + configuration: mkdocs.yml -# Optionally set the version of Python and requirements required to build your docs +# Optionally declare the Python requirements required to build your docs python: install: - method: pip diff --git a/pyproject.toml b/pyproject.toml index b6835b1..c0070e2 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -17,6 +17,7 @@ classifiers = [ "Operating System :: POSIX :: Linux", "Programming Language :: Python :: 3.10", "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python", @@ -24,7 +25,7 @@ classifiers = [ "Typing :: Typed" ] dependencies = [ - "pydantic >= 2.2.1", + "pydantic >= 2.4.2", "ratelimit >= 2.2.1", "requests >= 2.31.0" ] @@ -41,16 +42,16 @@ requires-python = ">= 3.8" [project.optional-dependencies] dev = [ - "pre-commit >= 3.3.3" + "pre-commit >= 3.4.0" ] docs = [ - "mkdocs >= 1.5.2", - "mkdocs-include-markdown-plugin >= 6.0.0", - "mkdocs-material >= 9.2.1", - "mkdocstrings[python] >= 0.22.0" + "mkdocs >= 1.5.3", + "mkdocs-include-markdown-plugin >= 6.0.1", + "mkdocs-material >= 9.4.4", + "mkdocstrings[python] >= 0.23.0" ] test = [ - "pytest >= 7.4.0", + "pytest >= 7.4.2", "pytest-cov >= 4.1.0", "pytest-pretty >= 1.2.0" ] @@ -63,7 +64,7 @@ Source = "https://github.com/Metron-Project/Simyan" [tool.black] line-length = 100 -target-version = ["py310", "py311", "py38", "py39"] +target-version = ["py310", "py311", "py312", "py38", "py39"] [tool.coverage.report] show_missing = true @@ -79,14 +80,15 @@ addopts = ["--cov"] [tool.ruff] fix = true -format = "grouped" ignore = [ "D107", "EXE", "FBT", - "PLR2004" + "PLR2004", + "TCH" ] line-length = 100 +output-format = "grouped" select = ["ALL"] show-fixes = true target-version = "py38" @@ -109,7 +111,7 @@ classmethod-decorators = ["classmethod", "pydantic.field_validator"] [tool.ruff.per-file-ignores] "simyan/schemas/*.py" = ["FA100"] -"tests/test_*.py" = ["S101", "SLF001"] +"tests/test_*.py" = ["S101"] [tool.ruff.pydocstyle] convention = "google" diff --git a/simyan/comicvine.py b/simyan/comicvine.py index e2a51c5..54d924d 100644 --- a/simyan/comicvine.py +++ b/simyan/comicvine.py @@ -12,7 +12,7 @@ import re from enum import Enum from json import JSONDecodeError -from typing import TYPE_CHECKING, Any, List, TypeVar +from typing import Any, List, TypeVar from urllib.parse import urlencode from pydantic import TypeAdapter, ValidationError @@ -34,9 +34,7 @@ from simyan.schemas.story_arc import StoryArc, StoryArcEntry from simyan.schemas.team import Team, TeamEntry from simyan.schemas.volume import Volume, VolumeEntry - -if TYPE_CHECKING: - from simyan.sqlite_cache import SQLiteCache +from simyan.sqlite_cache import SQLiteCache MINUTE = 60 T = TypeVar("T") diff --git a/simyan/sqlite_cache.py b/simyan/sqlite_cache.py index 70ead05..16ab04a 100644 --- a/simyan/sqlite_cache.py +++ b/simyan/sqlite_cache.py @@ -10,13 +10,11 @@ import json import sqlite3 from datetime import datetime, timedelta, timezone -from typing import TYPE_CHECKING, Any +from pathlib import Path +from typing import Any from simyan import get_cache_root -if TYPE_CHECKING: - from pathlib import Path - class SQLiteCache: """The SQLiteCache object to cache search results from Comicvine. @@ -27,7 +25,7 @@ class SQLiteCache: Attributes: expiry (int | None): How long to keep cache results. - con (sqlite3.Connection): Database connection + connection (sqlite3.Connection): Database connection """ def __init__( @@ -36,10 +34,10 @@ def __init__( expiry: int | None = 14, ): self.expiry = expiry - self.con = sqlite3.connect(path or get_cache_root() / "cache.sqlite") - self.con.row_factory = sqlite3.Row + self.connection = sqlite3.connect(path or get_cache_root() / "cache.sqlite") + self.connection.row_factory = sqlite3.Row - self.con.execute("CREATE TABLE IF NOT EXISTS queries (query, response, query_date);") + self.connection.execute("CREATE TABLE IF NOT EXISTS queries (query, response, query_date);") self.delete() def select(self: SQLiteCache, query: str) -> dict[str, Any]: @@ -51,13 +49,13 @@ def select(self: SQLiteCache, query: str) -> dict[str, Any]: Empty dict or select results. """ if self.expiry: - expiry = datetime.now(tz=timezone.utc).date() - timedelta(days=self.expiry) - cursor = self.con.execute( + expiry = datetime.now(tz=timezone.utc).astimezone().date() - timedelta(days=self.expiry) + cursor = self.connection.execute( "SELECT * FROM queries WHERE query = ? and query_date > ?;", (query, expiry.isoformat()), ) else: - cursor = self.con.execute("SELECT * FROM queries WHERE query = ?;", (query,)) + cursor = self.connection.execute("SELECT * FROM queries WHERE query = ?;", (query,)) if results := cursor.fetchone(): return json.loads(results["response"]) return {} @@ -69,16 +67,20 @@ def insert(self: SQLiteCache, query: str, response: dict[str, Any]) -> None: query: Search string response: Data to save """ - self.con.execute( + self.connection.execute( "INSERT INTO queries (query, response, query_date) VALUES (?, ?, ?);", - (query, json.dumps(response), datetime.now(tz=timezone.utc).date().isoformat()), + ( + query, + json.dumps(response), + datetime.now(tz=timezone.utc).astimezone().date().isoformat(), + ), ) - self.con.commit() + self.connection.commit() def delete(self: SQLiteCache) -> None: """Remove all expired data from the cache database.""" if not self.expiry: return - expiry = datetime.now(tz=timezone.utc).date() - timedelta(days=self.expiry) - self.con.execute("DELETE FROM queries WHERE query_date < ?;", (expiry.isoformat(),)) - self.con.commit() + expiry = datetime.now(tz=timezone.utc).astimezone().date() - timedelta(days=self.expiry) + self.connection.execute("DELETE FROM queries WHERE query_date < ?;", (expiry.isoformat(),)) + self.connection.commit() diff --git a/tests/test_exceptions.py b/tests/test_exceptions.py index 6886965..48c02de 100644 --- a/tests/test_exceptions.py +++ b/tests/test_exceptions.py @@ -18,7 +18,7 @@ def test_unauthorized() -> None: def test_not_found(session: Comicvine) -> None: """Test a 404 Not Found raises a ServiceError.""" with pytest.raises(ServiceError): - session._get_request(endpoint="/invalid") + session._get_request(endpoint="/invalid") # noqa: SLF001 def test_timeout(comicvine_api_key: str) -> None: From 72600d0dacd460b6e57c3d65d1b8632392106f0a Mon Sep 17 00:00:00 2001 From: BuriedInCode <6057651+Buried-In-Code@users.noreply.github.com> Date: Fri, 6 Oct 2023 09:46:52 +1300 Subject: [PATCH 2/3] Version bump --- simyan/__init__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/simyan/__init__.py b/simyan/__init__.py index a142e37..8c4fbd5 100644 --- a/simyan/__init__.py +++ b/simyan/__init__.py @@ -1,5 +1,5 @@ """simyan package entry file.""" -__version__ = "1.1.0" +__version__ = "1.2.0" __all__ = ["__version__", "get_cache_root"] import os From 46679402aaf84bbc117730c4e4d582a259cea1f3 Mon Sep 17 00:00:00 2001 From: BuriedInCode <6057651+Buried-In-Code@users.noreply.github.com> Date: Fri, 6 Oct 2023 09:52:30 +1300 Subject: [PATCH 3/3] Fix readthedocs config --- .readthedocs.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.readthedocs.yaml b/.readthedocs.yaml index d4594fc..08557f9 100644 --- a/.readthedocs.yaml +++ b/.readthedocs.yaml @@ -11,7 +11,7 @@ build: python: "3.11" mkdocs: - configuration: mkdocs.yml + configuration: mkdocs.yaml # Optionally declare the Python requirements required to build your docs python: