Remove usage of deprecated pkg_resources interface (#18910)

This commit is contained in:
Andrew Morgan
2025-09-12 11:57:04 +02:00
committed by GitHub
parent ec64c3e88d
commit 8c98cf7e55
7 changed files with 31 additions and 23 deletions

View File

@@ -18,12 +18,12 @@
#
#
import email.message
import importlib.resources as importlib_resources
import os
from http import HTTPStatus
from typing import Any, Dict, List, Sequence, Tuple
import attr
import pkg_resources
from parameterized import parameterized
from twisted.internet.defer import Deferred
@@ -59,11 +59,12 @@ class EmailPusherTests(HomeserverTestCase):
def make_homeserver(self, reactor: MemoryReactor, clock: Clock) -> HomeServer:
config = self.default_config()
templates = (
importlib_resources.files("synapse").joinpath("res").joinpath("templates")
)
config["email"] = {
"enable_notifs": True,
"template_dir": os.path.abspath(
pkg_resources.resource_filename("synapse", "res/templates")
),
"template_dir": os.path.abspath(str(templates)),
"expiry_template_html": "notice_expiry.html",
"expiry_template_text": "notice_expiry.txt",
"notif_template_html": "notif_mail.html",

View File

@@ -18,6 +18,7 @@
# [This file includes modifications made by New Vector Limited]
#
#
import importlib.resources as importlib_resources
import os
import re
from email.parser import Parser
@@ -25,8 +26,6 @@ from http import HTTPStatus
from typing import Any, Dict, List, Optional, Union
from unittest.mock import Mock
import pkg_resources
from twisted.internet.interfaces import IReactorTCP
from twisted.internet.testing import MemoryReactor
@@ -59,11 +58,12 @@ class PasswordResetTestCase(unittest.HomeserverTestCase):
config = self.default_config()
# Email config.
templates = (
importlib_resources.files("synapse").joinpath("res").joinpath("templates")
)
config["email"] = {
"enable_notifs": False,
"template_dir": os.path.abspath(
pkg_resources.resource_filename("synapse", "res/templates")
),
"template_dir": os.path.abspath(str(templates)),
"smtp_host": "127.0.0.1",
"smtp_port": 20,
"require_transport_security": False,
@@ -798,11 +798,12 @@ class ThreepidEmailRestTestCase(unittest.HomeserverTestCase):
config = self.default_config()
# Email config.
templates = (
importlib_resources.files("synapse").joinpath("res").joinpath("templates")
)
config["email"] = {
"enable_notifs": False,
"template_dir": os.path.abspath(
pkg_resources.resource_filename("synapse", "res/templates")
),
"template_dir": os.path.abspath(str(templates)),
"smtp_host": "127.0.0.1",
"smtp_port": 20,
"require_transport_security": False,

View File

@@ -20,12 +20,11 @@
#
#
import datetime
import importlib.resources as importlib_resources
import os
from typing import Any, Dict, List, Tuple
from unittest.mock import AsyncMock
import pkg_resources
from twisted.internet.testing import MemoryReactor
import synapse.rest.admin
@@ -981,11 +980,12 @@ class AccountValidityRenewalByEmailTestCase(unittest.HomeserverTestCase):
# Email config.
templates = (
importlib_resources.files("synapse").joinpath("res").joinpath("templates")
)
config["email"] = {
"enable_notifs": True,
"template_dir": os.path.abspath(
pkg_resources.resource_filename("synapse", "res/templates")
),
"template_dir": os.path.abspath(str(templates)),
"expiry_template_html": "notice_expiry.html",
"expiry_template_text": "notice_expiry.txt",
"notif_template_html": "notif_mail.html",