Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Py3.12 #173

Merged
merged 3 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/publishing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/testing.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ jobs:
- 3.9
- '3.10'
- '3.11'
- '3.12'
os:
- ubuntu-latest
- macos-latest
- windows-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:
Expand Down
12 changes: 3 additions & 9 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -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
Expand All @@ -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
Expand Down
14 changes: 7 additions & 7 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -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.yaml

# 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
Expand Down
24 changes: 13 additions & 11 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@ 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",
"Topic :: Internet",
"Typing :: Typed"
]
dependencies = [
"pydantic >= 2.2.1",
"pydantic >= 2.4.2",
"ratelimit >= 2.2.1",
"requests >= 2.31.0"
]
Expand All @@ -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"
]
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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"
2 changes: 1 addition & 1 deletion simyan/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""simyan package entry file."""
__version__ = "1.1.0"
__version__ = "1.2.0"
__all__ = ["__version__", "get_cache_root"]

import os
Expand Down
6 changes: 2 additions & 4 deletions simyan/comicvine.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")
Expand Down
36 changes: 19 additions & 17 deletions simyan/sqlite_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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__(
Expand All @@ -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]:
Expand All @@ -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 {}
Expand All @@ -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()
2 changes: 1 addition & 1 deletion tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down