From f12e403c67c5158b368ce777f36702181a5c0e45 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alban=20F=C3=A9ron?= Date: Sun, 19 May 2024 15:59:40 +0200 Subject: [PATCH] Add Python 3.12 support --- .github/workflows/tests.yaml | 3 ++- setup.cfg | 1 + supysonic/db.py | 38 ++++++++++++++++++++++++++++++------ 3 files changed, 35 insertions(+), 7 deletions(-) diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index f03f07d..3a68b88 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -29,7 +29,8 @@ jobs: - 3.8 - 3.9 - "3.10" - - 3.11 + - "3.11" + - "3.12" fail-fast: false steps: - name: Checkout diff --git a/setup.cfg b/setup.cfg index 2a47c05..d951e08 100644 --- a/setup.cfg +++ b/setup.cfg @@ -46,6 +46,7 @@ classifiers = Programming Language :: Python :: 3.9 Programming Language :: Python :: 3.10 Programming Language :: Python :: 3.11 + Programming Language :: Python :: 3.12 Topic :: Multimedia :: Sound/Audio [options] diff --git a/supysonic/db.py b/supysonic/db.py index 9ed4ccf..306290b 100644 --- a/supysonic/db.py +++ b/supysonic/db.py @@ -1,14 +1,14 @@ # This file is part of Supysonic. # Supysonic is a Python implementation of the Subsonic server API. # -# Copyright (C) 2013-2023 Alban 'spl0k' Féron +# Copyright (C) 2013-2024 Alban 'spl0k' Féron # # Distributed under terms of the GNU AGPLv3 license. import importlib import mimetypes import os.path -import pkg_resources +import sys import time from datetime import datetime @@ -616,8 +616,36 @@ class RadioStation(_Model): return info +if sys.version_info < (3, 9): + import pkg_resources + + def get_resource_text(respath): + return pkg_resources.resource_string(__package__, respath).decode("utf-8") + + def list_migrations(provider): + return pkg_resources.resource_listdir( + __package__, f"schema/migration/{provider}" + ) + +else: + import importlib.resources + + def get_resource_text(respath): + return ( + importlib.resources.files(__package__).joinpath(respath).read_text("utf-8") + ) + + def list_migrations(provider): + return ( + e.name + for e in importlib.resources.files(__package__) + .joinpath(f"schema/migration/{provider}") + .iterdir() + ) + + def execute_sql_resource_script(respath): - sql = pkg_resources.resource_string(__package__, respath).decode("utf-8") + sql = get_resource_text(respath) for statement in sql.split(";"): statement = statement.strip() if statement and not statement.startswith("--"): @@ -655,9 +683,7 @@ def init_database(database_uri): version = Meta["schema_version"] if version.value < SCHEMA_VERSION: args.pop("pragmas", ()) - migrations = sorted( - pkg_resources.resource_listdir(__package__, f"schema/migration/{provider}") - ) + migrations = sorted(list_migrations(provider)) for migration in migrations: if migration[0] in ("_", "."): continue