From 5ea499430b0e35774de58a9cfa10e7c1ab76e7e5 Mon Sep 17 00:00:00 2001 From: Hendrik Wiese Date: Sun, 9 Jun 2024 08:56:43 +0200 Subject: [PATCH 1/3] fix: replace pkg_resources with importlib pkg_resources is deprecated. --- maubot/cli/commands/init.py | 8 ++++---- maubot/cli/util/spdx.py | 4 ++-- maubot/server.py | 4 ++-- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/maubot/cli/commands/init.py b/maubot/cli/commands/init.py index d24def9..4105d9c 100644 --- a/maubot/cli/commands/init.py +++ b/maubot/cli/commands/init.py @@ -17,7 +17,7 @@ import os from jinja2 import Template from packaging.version import Version -from pkg_resources import resource_string +import importlib.resources as resources from .. import cliq from ..cliq import SPDXValidator, VersionValidator @@ -33,9 +33,9 @@ def load_templates(): global mod_template, meta_template, base_config, loaded if loaded: return - meta_template = Template(resource_string("maubot.cli", "res/maubot.yaml.j2").decode("utf-8")) - mod_template = Template(resource_string("maubot.cli", "res/plugin.py.j2").decode("utf-8")) - base_config = resource_string("maubot.cli", "res/config.yaml").decode("utf-8") + meta_template = Template(resources.read_text("maubot.cli", "res/maubot.yaml.j2")) + mod_template = Template(resources.read_text("maubot.cli", "res/plugin.py.j2")) + base_config = resources.read_text("maubot.cli", "res/config.yaml") loaded = True diff --git a/maubot/cli/util/spdx.py b/maubot/cli/util/spdx.py index 69f58b7..4508e26 100644 --- a/maubot/cli/util/spdx.py +++ b/maubot/cli/util/spdx.py @@ -18,7 +18,7 @@ from __future__ import annotations import json import zipfile -import pkg_resources +import importlib.resources as resources spdx_list: dict[str, dict[str, str]] | None = None @@ -27,7 +27,7 @@ def load() -> None: global spdx_list if spdx_list is not None: return - with pkg_resources.resource_stream("maubot.cli", "res/spdx.json.zip") as disk_file: + with resources.open_binary("maubot.cli", "res/spdx.json.zip") as disk_file: with zipfile.ZipFile(disk_file) as zip_file: with zip_file.open("spdx.json") as file: spdx_list = json.load(file) diff --git a/maubot/server.py b/maubot/server.py index 097fe5b..64b5939 100644 --- a/maubot/server.py +++ b/maubot/server.py @@ -23,7 +23,7 @@ import logging from aiohttp import hdrs, web from aiohttp.abc import AbstractAccessLogger from yarl import URL -import pkg_resources +import importlib.resources as resources from mautrix.api import Method, PathBuilder @@ -103,7 +103,7 @@ class MaubotServer: ui_base = "" directory = self.config[ "server.override_resource_path" - ] or pkg_resources.resource_filename("maubot", "management/frontend/build") + ] or resources.files("maubot").joinpath("management/frontend/build") self.app.router.add_static(f"{ui_base}/static", f"{directory}/static") self.setup_static_root_files(directory, ui_base) From 61f528d9b32cb07e5297f02418cde237f772c646 Mon Sep 17 00:00:00 2001 From: Hendrik Wiese Date: Sun, 9 Jun 2024 10:20:19 +0200 Subject: [PATCH 2/3] fix: Use files instead of open_binary open_binary is deprecated Co-authored-by: chayleaf --- maubot/cli/util/spdx.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maubot/cli/util/spdx.py b/maubot/cli/util/spdx.py index 4508e26..1cae7a5 100644 --- a/maubot/cli/util/spdx.py +++ b/maubot/cli/util/spdx.py @@ -27,7 +27,7 @@ def load() -> None: global spdx_list if spdx_list is not None: return - with resources.open_binary("maubot.cli", "res/spdx.json.zip") as disk_file: + with resources.files("maubot.cli").joinpath("res/spdx.json.zip").open("rb") as disk_file: with zipfile.ZipFile(disk_file) as zip_file: with zip_file.open("spdx.json") as file: spdx_list = json.load(file) From 6e5e40e7e46e34179bedace2abc39f6e01107bd0 Mon Sep 17 00:00:00 2001 From: Hendrik Wiese Date: Sun, 9 Jun 2024 10:58:34 +0200 Subject: [PATCH 3/3] fix: use resources.files... read_text is deprecated Co-authored-by: chayleaf --- maubot/cli/commands/init.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/maubot/cli/commands/init.py b/maubot/cli/commands/init.py index 4105d9c..a65b76b 100644 --- a/maubot/cli/commands/init.py +++ b/maubot/cli/commands/init.py @@ -33,9 +33,9 @@ def load_templates(): global mod_template, meta_template, base_config, loaded if loaded: return - meta_template = Template(resources.read_text("maubot.cli", "res/maubot.yaml.j2")) - mod_template = Template(resources.read_text("maubot.cli", "res/plugin.py.j2")) - base_config = resources.read_text("maubot.cli", "res/config.yaml") + meta_template = Template(resources.files("maubot.cli").joinpath("res/maubot.yaml.j2").read_text(encoding="utf-8")) + mod_template = Template(resources.files("maubot.cli").joinpath("res/plugin.py.j2").read_text(encoding="utf-8")) + base_config = resources.files("maubot.cli").joinpath("res/config.yaml").read_text(encoding="utf-8") loaded = True