Compare commits

...

6 Commits

Author SHA1 Message Date
Hendrik Wiese
2222f6ce69
Merge 6e5e40e7e4 into 65be63fdd2 2024-08-29 15:42:08 +07:00
jkhsjdhjs
65be63fdd2
Fix PluginWebApp base path handling (#240)
Previously, the webapp handler would match without respect to the trailing slash, e.g. matching "foo"
for "foo2". This behavior is changed to respect the trailing slash.

Fixes #239
2024-08-24 18:47:24 +03:00
Tulir Asokan
c218c8cf61 Bump version to 0.5.0 2024-08-24 12:10:19 +03:00
Hendrik Wiese
6e5e40e7e4
fix: use resources.files...
read_text is deprecated

Co-authored-by: chayleaf <chayleaf@pavluk.org>
2024-06-09 10:58:34 +02:00
Hendrik Wiese
61f528d9b3 fix: Use files instead of open_binary
open_binary is deprecated

Co-authored-by: chayleaf <chayleaf@pavluk.org>
2024-06-09 10:25:44 +02:00
Hendrik Wiese
5ea499430b fix: replace pkg_resources with importlib
pkg_resources is deprecated.
2024-06-09 09:03:05 +02:00
6 changed files with 19 additions and 15 deletions

View File

@ -1,5 +1,9 @@
# v0.5.0 (unreleased)
# v0.5.0 (2024-08-24)
* Dropped Python 3.9 support.
* Updated Docker image to Alpine 3.20.
* Updated mautrix-python to 0.20.6 to support authenticated media.
* Removed hard dependency on SQLAlchemy.
* Fixed `main_class` to default to being loaded from the last module instead of
the first if a module name is not explicitly specified.
* This was already the [documented behavior](https://docs.mau.fi/maubot/dev/reference/plugin-metadata.html),

View File

@ -1 +1 @@
__version__ = "0.4.2"
__version__ = "0.5.0"

View File

@ -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.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

View File

@ -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.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)

View File

@ -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
@ -64,14 +64,14 @@ class MaubotServer:
if request.path.startswith(path):
request = request.clone(
rel_url=request.rel_url.with_path(
request.rel_url.path[len(path) :]
request.rel_url.path[len(path) - 1 :]
).with_query(request.query_string)
)
return await app.handle(request)
return web.Response(status=404)
def get_instance_subapp(self, instance_id: str) -> tuple[PluginWebApp, str]:
subpath = self.config["server.plugin_base_path"] + instance_id
subpath = self.config["server.plugin_base_path"] + instance_id + "/"
url = self.config["server.public_url"] + subpath
try:
return self.plugin_routes[subpath], url
@ -82,7 +82,7 @@ class MaubotServer:
def remove_instance_webapp(self, instance_id: str) -> None:
try:
subpath = self.config["server.plugin_base_path"] + instance_id
subpath = self.config["server.plugin_base_path"] + instance_id + "/"
self.plugin_routes.pop(subpath).clear()
except KeyError:
return
@ -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)

View File

@ -41,7 +41,7 @@ setuptools.setup(
install_requires=install_requires,
extras_require=extras_require,
python_requires="~=3.9",
python_requires="~=3.10",
classifiers=[
"Development Status :: 4 - Beta",
@ -50,9 +50,9 @@ setuptools.setup(
"Framework :: AsyncIO",
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
],
entry_points="""
[console_scripts]