Files
nixpkgs/pkgs/by-name/ma/mautrix-telegram/0002-use-importlib-resources.patch
LuoChen 3068460c4f mautrix-telegram: fix crash and unbreak default-python build
Two independent issues currently break mautrix-telegram on master:

1. setuptools 81+ removed the pkg_resources module, causing a crash on
   startup (ModuleNotFoundError: No module named 'pkg_resources'). The
   upstream Python version is unmaintained (the main branch was rewritten
   in Go), so pkg_resources is replaced with the standard library
   importlib.resources, available since Python 3.9.

2. The default python3 is now 3.14, but telethon is
   `disabled = pythonAtLeast "3.14"` (only because telethon's *tests*
   fail on 3.14). mautrix-telegram's tulir-telethon fork was derived via
   telethon.overrideAttrs and thus inherited the disable, breaking the
   default build. Build tulir-telethon standalone so it is no longer
   affected by telethon's test-only disable (this fork already skips the
   test suite).

Assisted-by: opencode (glm-5.2)
2026-07-16 21:59:05 +08:00

37 lines
1.6 KiB
Diff

diff --git a/mautrix_telegram/web/public/__init__.py b/mautrix_telegram/web/public/__init__.py
index cde3735..d911779 100644
--- a/mautrix_telegram/web/public/__init__.py
+++ b/mautrix_telegram/web/public/__init__.py
@@ -23,7 +23,7 @@ import time
from aiohttp import web
from mako.template import Template
-import pkg_resources
+from importlib.resources import files
from mautrix.types import UserID
from mautrix.util.signed_token import sign_token, verify_token
@@ -45,11 +45,11 @@ class PublicBridgeWebsite(AuthAPI):
self.secret_key = "".join(random.choices(string.ascii_lowercase + string.digits, k=64))
self.login = Template(
- pkg_resources.resource_string("mautrix_telegram", "web/public/login.html.mako")
+ files("mautrix_telegram").joinpath("web/public/login.html.mako").read_bytes()
)
self.mx_login = Template(
- pkg_resources.resource_string("mautrix_telegram", "web/public/matrix-login.html.mako")
+ files("mautrix_telegram").joinpath("web/public/matrix-login.html.mako").read_bytes()
)
self.app = web.Application(loop=loop)
@@ -58,7 +58,7 @@ class PublicBridgeWebsite(AuthAPI):
self.app.router.add_route("GET", "/matrix-login", self.get_matrix_login)
self.app.router.add_route("POST", "/matrix-login", self.post_matrix_login)
self.app.router.add_static(
- "/", pkg_resources.resource_filename("mautrix_telegram", "web/public/")
+ "/", str(files("mautrix_telegram").joinpath("web/public/"))
)
def make_token(self, mxid: str, endpoint: str = "/login", expires_in: int = 900) -> str: