diff --git a/docker/Dockerfile b/docker/Dockerfile index 7b8664f9..47e17f69 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -57,7 +57,7 @@ RUN --mount=type=cache,target=/root/.cache/pip \ pip install --prefix="/install" --no-deps --no-warn-script-location -r /sygnal/requirements.txt # Copy over the rest of the sygnal source code. -COPY sygnal /sygnal/sygnal/ +COPY matrix_sygnal /sygnal/matrix_sygnal/ # ... and what we need to `pip install`. COPY pyproject.toml README.md /sygnal/ @@ -85,4 +85,4 @@ COPY --from=builder /install /usr/local EXPOSE 5000/tcp -ENTRYPOINT ["python", "-m", "sygnal.sygnal"] +ENTRYPOINT ["python", "-m", "matrix_sygnal.sygnal"] diff --git a/sygnal/__init__.py b/matrix_sygnal/__init__.py similarity index 100% rename from sygnal/__init__.py rename to matrix_sygnal/__init__.py diff --git a/sygnal/apnspushkin.py b/matrix_sygnal/apnspushkin.py similarity index 98% rename from sygnal/apnspushkin.py rename to matrix_sygnal/apnspushkin.py index a9c2d5f1..4ce8ca2a 100644 --- a/sygnal/apnspushkin.py +++ b/matrix_sygnal/apnspushkin.py @@ -32,23 +32,23 @@ from prometheus_client import Counter, Gauge, Histogram from twisted.internet.defer import Deferred -from sygnal import apnstruncate -from sygnal.exceptions import ( +from matrix_sygnal import apnstruncate +from matrix_sygnal.exceptions import ( NotificationDispatchException, PushkinSetupException, TemporaryNotificationDispatchException, ) -from sygnal.helper.proxy.proxy_asyncio import ProxyingEventLoopWrapper -from sygnal.notifications import ( +from matrix_sygnal.helper.proxy.proxy_asyncio import ProxyingEventLoopWrapper +from matrix_sygnal.notifications import ( ConcurrencyLimitedPushkin, Device, Notification, NotificationContext, ) -from sygnal.utils import NotificationLoggerAdapter, twisted_sleep +from matrix_sygnal.utils import NotificationLoggerAdapter, twisted_sleep if TYPE_CHECKING: - from sygnal.sygnal import Sygnal + from matrix_sygnal.sygnal import Sygnal logger = logging.getLogger(__name__) diff --git a/sygnal/apnstruncate.py b/matrix_sygnal/apnstruncate.py similarity index 100% rename from sygnal/apnstruncate.py rename to matrix_sygnal/apnstruncate.py diff --git a/sygnal/exceptions.py b/matrix_sygnal/exceptions.py similarity index 100% rename from sygnal/exceptions.py rename to matrix_sygnal/exceptions.py diff --git a/sygnal/gcmpushkin.py b/matrix_sygnal/gcmpushkin.py similarity index 98% rename from sygnal/gcmpushkin.py rename to matrix_sygnal/gcmpushkin.py index fa3360ec..5b0e5699 100644 --- a/sygnal/gcmpushkin.py +++ b/matrix_sygnal/gcmpushkin.py @@ -36,24 +36,24 @@ from twisted.web.http_headers import Headers from twisted.web.iweb import IResponse -from sygnal.exceptions import ( +from matrix_sygnal.exceptions import ( NotificationDispatchException, NotificationQuotaDispatchException, PushkinSetupException, TemporaryNotificationDispatchException, ) -from sygnal.helper.context_factory import ClientTLSOptionsFactory -from sygnal.helper.proxy.proxyagent_twisted import ProxyAgent -from sygnal.notifications import ( +from matrix_sygnal.helper.context_factory import ClientTLSOptionsFactory +from matrix_sygnal.helper.proxy.proxyagent_twisted import ProxyAgent +from matrix_sygnal.notifications import ( ConcurrencyLimitedPushkin, Device, Notification, NotificationContext, ) -from sygnal.utils import NotificationLoggerAdapter, json_decoder, twisted_sleep +from matrix_sygnal.utils import NotificationLoggerAdapter, json_decoder, twisted_sleep if TYPE_CHECKING: - from sygnal.sygnal import Sygnal + from matrix_sygnal.sygnal import Sygnal QUEUE_TIME_HISTOGRAM = Histogram( "sygnal_gcm_queue_time", "Time taken waiting for a connection to GCM" diff --git a/sygnal/helper/__init__.py b/matrix_sygnal/helper/__init__.py similarity index 100% rename from sygnal/helper/__init__.py rename to matrix_sygnal/helper/__init__.py diff --git a/sygnal/helper/context_factory.py b/matrix_sygnal/helper/context_factory.py similarity index 100% rename from sygnal/helper/context_factory.py rename to matrix_sygnal/helper/context_factory.py diff --git a/sygnal/helper/proxy/__init__.py b/matrix_sygnal/helper/proxy/__init__.py similarity index 100% rename from sygnal/helper/proxy/__init__.py rename to matrix_sygnal/helper/proxy/__init__.py diff --git a/sygnal/helper/proxy/connectproxyclient_twisted.py b/matrix_sygnal/helper/proxy/connectproxyclient_twisted.py similarity index 99% rename from sygnal/helper/proxy/connectproxyclient_twisted.py rename to matrix_sygnal/helper/proxy/connectproxyclient_twisted.py index 1cf8c697..cbc981b4 100644 --- a/sygnal/helper/proxy/connectproxyclient_twisted.py +++ b/matrix_sygnal/helper/proxy/connectproxyclient_twisted.py @@ -34,7 +34,7 @@ from twisted.web import http from zope.interface import implementer -from sygnal.exceptions import ProxyConnectError +from matrix_sygnal.exceptions import ProxyConnectError logger = logging.getLogger(__name__) diff --git a/sygnal/helper/proxy/proxy_asyncio.py b/matrix_sygnal/helper/proxy/proxy_asyncio.py similarity index 99% rename from sygnal/helper/proxy/proxy_asyncio.py rename to matrix_sygnal/helper/proxy/proxy_asyncio.py index 31c97659..30160012 100644 --- a/sygnal/helper/proxy/proxy_asyncio.py +++ b/matrix_sygnal/helper/proxy/proxy_asyncio.py @@ -24,8 +24,8 @@ import attr -from sygnal.exceptions import ProxyConnectError -from sygnal.helper.proxy import decompose_http_proxy_url +from matrix_sygnal.exceptions import ProxyConnectError +from matrix_sygnal.helper.proxy import decompose_http_proxy_url logger = logging.getLogger(__name__) diff --git a/sygnal/helper/proxy/proxyagent_twisted.py b/matrix_sygnal/helper/proxy/proxyagent_twisted.py similarity index 97% rename from sygnal/helper/proxy/proxyagent_twisted.py rename to matrix_sygnal/helper/proxy/proxyagent_twisted.py index 325a0f71..12cf2c68 100644 --- a/sygnal/helper/proxy/proxyagent_twisted.py +++ b/matrix_sygnal/helper/proxy/proxyagent_twisted.py @@ -34,8 +34,10 @@ from twisted.web.iweb import IAgent, IBodyProducer, IPolicyForHTTPS, IResponse from zope.interface import implementer -from sygnal.helper.proxy import decompose_http_proxy_url -from sygnal.helper.proxy.connectproxyclient_twisted import HTTPConnectProxyEndpoint +from matrix_sygnal.helper.proxy import decompose_http_proxy_url +from matrix_sygnal.helper.proxy.connectproxyclient_twisted import ( + HTTPConnectProxyEndpoint, +) logger = logging.getLogger(__name__) diff --git a/sygnal/http.py b/matrix_sygnal/http.py similarity index 96% rename from sygnal/http.py rename to matrix_sygnal/http.py index 9669b71d..ce8fc2b0 100644 --- a/sygnal/http.py +++ b/matrix_sygnal/http.py @@ -19,7 +19,7 @@ import sys import time import traceback -from typing import TYPE_CHECKING, Callable, List, Union +from typing import TYPE_CHECKING, Any, Callable, List, Union from uuid import uuid4 from opentracing import Format, Span, logs, tags @@ -35,15 +35,15 @@ from twisted.web.resource import Resource from twisted.web.server import NOT_DONE_YET -from sygnal.exceptions import ( +from matrix_sygnal.exceptions import ( InvalidNotificationException, NotificationDispatchException, ) -from sygnal.notifications import Notification, NotificationContext, Pushkin -from sygnal.utils import NotificationLoggerAdapter, json_decoder +from matrix_sygnal.notifications import Notification, NotificationContext, Pushkin +from matrix_sygnal.utils import NotificationLoggerAdapter, json_decoder if TYPE_CHECKING: - from sygnal.sygnal import Sygnal + from matrix_sygnal.sygnal import Sygnal logger = logging.getLogger(__name__) @@ -177,7 +177,7 @@ def _handle_request(self, request: Request) -> Union[int, bytes]: root_span_accounted_for = True - async def cb(): + async def cb() -> None: with REQUESTS_IN_FLIGHT_GUAGE.labels( self.__class__.__name__ ).track_inprogress(): @@ -342,7 +342,10 @@ class SygnalLoggedSite(server.Site): """ def __init__( - self, *args, log_formatter: Callable[[str, server.Request], str], **kwargs + self, + *args: Any, + log_formatter: Callable[[str, server.Request], str], + **kwargs: Any, ): super().__init__(*args, **kwargs) self.log_formatter = log_formatter diff --git a/sygnal/notifications.py b/matrix_sygnal/notifications.py similarity index 96% rename from sygnal/notifications.py rename to matrix_sygnal/notifications.py index ec734174..12b5385f 100644 --- a/sygnal/notifications.py +++ b/matrix_sygnal/notifications.py @@ -15,20 +15,30 @@ # See the License for the specific language governing permissions and # limitations under the License. import abc -from typing import TYPE_CHECKING, Any, Dict, List, Optional, Type, TypeVar, overload +from typing import ( + TYPE_CHECKING, + Any, + Dict, + List, + Optional, + Self, + Type, + TypeVar, + overload, +) from matrix_common.regex import glob_to_regex from opentracing import Span from prometheus_client import Counter -from sygnal.exceptions import ( +from matrix_sygnal.exceptions import ( InvalidNotificationException, NotificationDispatchException, PushkinSetupException, ) if TYPE_CHECKING: - from sygnal.sygnal import Sygnal + from matrix_sygnal.sygnal import Sygnal T = TypeVar("T") @@ -83,7 +93,7 @@ def __init__(self, raw: Dict[str, Any]): class Notification: - def __init__(self, notif): + def __init__(self, notif: dict): # optional attributes self.room_name: Optional[str] = notif.get("room_name") self.room_alias: Optional[str] = notif.get("room_alias") @@ -155,7 +165,7 @@ async def dispatch_notification( ... @classmethod - async def create(cls, name: str, sygnal: "Sygnal", config: Dict[str, Any]): + async def create(cls, name: str, sygnal: "Sygnal", config: Dict[str, Any]) -> Self: """ Override this if your pushkin needs to call async code in order to be constructed. Otherwise, it defaults to just invoking the Python-standard diff --git a/sygnal/sygnal.py b/matrix_sygnal/sygnal.py similarity index 97% rename from sygnal/sygnal.py rename to matrix_sygnal/sygnal.py index ce3ca5cf..375c45bc 100644 --- a/sygnal/sygnal.py +++ b/matrix_sygnal/sygnal.py @@ -20,7 +20,7 @@ import logging.config import os import sys -from typing import Any, Dict, Set, cast +from typing import Any, Dict, Generator, Set, cast import opentracing import prometheus_client @@ -28,7 +28,7 @@ from opentracing import Tracer from opentracing.scope_managers.asyncio import AsyncioScopeManager from twisted.internet import asyncioreactor, defer -from twisted.internet.defer import ensureDeferred +from twisted.internet.defer import Deferred, ensureDeferred from twisted.internet.interfaces import ( IReactorCore, IReactorFDSet, @@ -40,8 +40,8 @@ from twisted.python.failure import Failure from zope.interface import Interface -from sygnal.http import PushGatewayApiServer -from sygnal.notifications import Pushkin +from matrix_sygnal.http import PushGatewayApiServer +from matrix_sygnal.notifications import Pushkin logger = logging.getLogger(__name__) @@ -185,7 +185,7 @@ async def _make_pushkin(self, app_name: str, app_config: Dict[str, Any]) -> Push to_import = kind_split[0] to_construct = kind_split[1] else: - to_import = f"sygnal.{app_type}pushkin" + to_import = f"matrix_sygnal.{app_type}pushkin" to_construct = f"{app_type.capitalize()}Pushkin" logger.info("Importing pushkin module: %s", to_import) @@ -223,7 +223,7 @@ def run(self) -> None: """ @defer.inlineCallbacks - def start(): + def start() -> Generator[Deferred[Any], Any, Any]: try: yield ensureDeferred(self.make_pushkins_then_start()) except Exception: @@ -337,7 +337,7 @@ def merge_left_with_defaults( return result -def main(): +def main() -> None: # TODO we don't want to have to install the reactor, when we can get away with # it asyncioreactor.install() diff --git a/sygnal/utils.py b/matrix_sygnal/utils.py similarity index 97% rename from sygnal/utils.py rename to matrix_sygnal/utils.py index 1cd30f76..0c3fc3fe 100644 --- a/sygnal/utils.py +++ b/matrix_sygnal/utils.py @@ -19,7 +19,7 @@ from twisted.internet.defer import Deferred if TYPE_CHECKING: - from sygnal.sygnal import SygnalReactor + from matrix_sygnal.sygnal import SygnalReactor async def twisted_sleep(delay: float, twisted_reactor: "SygnalReactor") -> None: diff --git a/sygnal/webpushpushkin.py b/matrix_sygnal/webpushpushkin.py similarity index 98% rename from sygnal/webpushpushkin.py rename to matrix_sygnal/webpushpushkin.py index 074a34da..ea0cbc13 100644 --- a/sygnal/webpushpushkin.py +++ b/matrix_sygnal/webpushpushkin.py @@ -31,10 +31,10 @@ from twisted.web.http_headers import Headers from twisted.web.iweb import IResponse -from sygnal.exceptions import PushkinSetupException -from sygnal.helper.context_factory import ClientTLSOptionsFactory -from sygnal.helper.proxy.proxyagent_twisted import ProxyAgent -from sygnal.notifications import ( +from matrix_sygnal.exceptions import PushkinSetupException +from matrix_sygnal.helper.context_factory import ClientTLSOptionsFactory +from matrix_sygnal.helper.proxy.proxyagent_twisted import ProxyAgent +from matrix_sygnal.notifications import ( ConcurrencyLimitedPushkin, Device, Notification, @@ -42,7 +42,7 @@ ) if TYPE_CHECKING: - from sygnal.sygnal import Sygnal + from matrix_sygnal.sygnal import Sygnal QUEUE_TIME_HISTOGRAM = Histogram( "sygnal_webpush_queue_time", diff --git a/pyproject.toml b/pyproject.toml index 778cfee6..de93f458 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -108,4 +108,4 @@ typing-extensions = ">=3.7.4" "changelog" = "https://github.com/matrix-org/sygnal/blob/main/CHANGELOG.md" [tool.poetry.scripts] -sygnal = "sygnal.sygnal:main" +sygnal = "matrix_sygnal.sygnal:main" diff --git a/tests/test_apns.py b/tests/test_apns.py index 6a6653e3..6ce84194 100644 --- a/tests/test_apns.py +++ b/tests/test_apns.py @@ -17,8 +17,8 @@ from aioapns.common import NotificationResult, PushType -from sygnal import apnstruncate -from sygnal.apnspushkin import ApnsPushkin +from matrix_sygnal import apnstruncate +from matrix_sygnal.apnspushkin import ApnsPushkin from tests import testutils @@ -58,14 +58,16 @@ class ApnsTestCase(testutils.TestCase): def setUp(self) -> None: - self.apns_mock_class = patch("sygnal.apnspushkin.APNs").start() + self.apns_mock_class = patch("matrix_sygnal.apnspushkin.APNs").start() self.apns_mock = MagicMock() self.apns_mock_class.return_value = self.apns_mock # pretend our certificate exists patch("os.path.exists", lambda x: x == TEST_CERTFILE_PATH).start() # Since no certificate exists, don't try to read it. - patch("sygnal.apnspushkin.ApnsPushkin._report_certificate_expiration").start() + patch( + "matrix_sygnal.apnspushkin.ApnsPushkin._report_certificate_expiration" + ).start() self.addCleanup(patch.stopall) super().setUp() diff --git a/tests/test_apnstruncate.py b/tests/test_apnstruncate.py index bc0c0ba8..0e66efa7 100644 --- a/tests/test_apnstruncate.py +++ b/tests/test_apnstruncate.py @@ -21,7 +21,7 @@ import unittest from typing import Any, Dict -from sygnal.apnstruncate import json_encode, truncate +from matrix_sygnal.apnstruncate import json_encode, truncate def simplestring(length: int, offset: int = 0) -> str: diff --git a/tests/test_concurrency_limit.py b/tests/test_concurrency_limit.py index ee6aa958..c53c9ee5 100644 --- a/tests/test_concurrency_limit.py +++ b/tests/test_concurrency_limit.py @@ -14,13 +14,13 @@ from typing import Any, Dict, List -from sygnal.notifications import ( +from matrix_sygnal.notifications import ( ConcurrencyLimitedPushkin, Device, Notification, NotificationContext, ) -from sygnal.utils import twisted_sleep +from matrix_sygnal.utils import twisted_sleep from tests.testutils import TestCase diff --git a/tests/test_gcm.py b/tests/test_gcm.py index aa35f015..603e785c 100644 --- a/tests/test_gcm.py +++ b/tests/test_gcm.py @@ -17,13 +17,13 @@ from typing import TYPE_CHECKING, Any, AnyStr, Dict, List, Tuple from unittest.mock import MagicMock -from sygnal.gcmpushkin import APIVersion, GcmPushkin +from matrix_sygnal.gcmpushkin import APIVersion, GcmPushkin from tests import testutils from tests.testutils import DummyResponse if TYPE_CHECKING: - from sygnal.sygnal import Sygnal + from matrix_sygnal.sygnal import Sygnal DEVICE_EXAMPLE = {"app_id": "com.example.gcm", "pushkey": "spqr", "pushkey_ts": 42} DEVICE_EXAMPLE2 = {"app_id": "com.example.gcm", "pushkey": "spqr2", "pushkey_ts": 42} diff --git a/tests/test_http.py b/tests/test_http.py index c190a204..f463a5f8 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -16,7 +16,7 @@ from aioapns.common import NotificationResult -from sygnal.apnspushkin import ApnsPushkin +from matrix_sygnal.apnspushkin import ApnsPushkin from tests import testutils @@ -50,14 +50,16 @@ class HttpTestCase(testutils.TestCase): def setUp(self) -> None: - self.apns_mock_class = patch("sygnal.apnspushkin.APNs").start() + self.apns_mock_class = patch("matrix_sygnal.apnspushkin.APNs").start() self.apns_mock = MagicMock() self.apns_mock_class.return_value = self.apns_mock # pretend our certificate exists patch("os.path.exists", lambda x: x == TEST_CERTFILE_PATH).start() # Since no certificate exists, don't try to read it. - patch("sygnal.apnspushkin.ApnsPushkin._report_certificate_expiration").start() + patch( + "matrix_sygnal.apnspushkin.ApnsPushkin._report_certificate_expiration" + ).start() self.addCleanup(patch.stopall) super().setUp() diff --git a/tests/test_httpproxy_asyncio.py b/tests/test_httpproxy_asyncio.py index c8b02d62..7ff8bcd0 100644 --- a/tests/test_httpproxy_asyncio.py +++ b/tests/test_httpproxy_asyncio.py @@ -17,8 +17,8 @@ from asyncio import AbstractEventLoop, BaseTransport, Protocol, Task from typing import Optional, Tuple, cast -from sygnal.exceptions import ProxyConnectError -from sygnal.helper.proxy.proxy_asyncio import HttpConnectProtocol +from matrix_sygnal.exceptions import ProxyConnectError +from matrix_sygnal.helper.proxy.proxy_asyncio import HttpConnectProtocol from tests import testutils from tests.asyncio_test_helpers import ( diff --git a/tests/test_httpproxy_twisted.py b/tests/test_httpproxy_twisted.py index 2a1dc047..7f95d077 100644 --- a/tests/test_httpproxy_twisted.py +++ b/tests/test_httpproxy_twisted.py @@ -22,7 +22,7 @@ from twisted.web.client import readBody from twisted.web.http import HTTPChannel -from sygnal.helper.proxy.proxyagent_twisted import ProxyAgent +from matrix_sygnal.helper.proxy.proxyagent_twisted import ProxyAgent from tests.testutils import TestCase from tests.twisted_test_helpers import ( diff --git a/tests/test_proxy_url_parsing.py b/tests/test_proxy_url_parsing.py index 03e90b71..8635a578 100644 --- a/tests/test_proxy_url_parsing.py +++ b/tests/test_proxy_url_parsing.py @@ -14,7 +14,7 @@ # limitations under the License. import unittest -from sygnal.helper.proxy import HttpProxyUrl, decompose_http_proxy_url +from matrix_sygnal.helper.proxy import HttpProxyUrl, decompose_http_proxy_url class ProxyUrlTestCase(unittest.TestCase): diff --git a/tests/test_pushgateway_api_v1.py b/tests/test_pushgateway_api_v1.py index ab4ee7cf..0fdb8edd 100644 --- a/tests/test_pushgateway_api_v1.py +++ b/tests/test_pushgateway_api_v1.py @@ -17,11 +17,16 @@ from twisted.internet.address import IPv6Address from twisted.internet.testing import StringTransport -from sygnal.exceptions import ( +from matrix_sygnal.exceptions import ( NotificationDispatchException, TemporaryNotificationDispatchException, ) -from sygnal.notifications import Device, Notification, NotificationContext, Pushkin +from matrix_sygnal.notifications import ( + Device, + Notification, + NotificationContext, + Pushkin, +) from tests import testutils diff --git a/tests/testutils.py b/tests/testutils.py index cbeca643..ce08b46b 100644 --- a/tests/testutils.py +++ b/tests/testutils.py @@ -30,7 +30,7 @@ from twisted.web.server import Request from zope.interface.declarations import implementer -from sygnal.sygnal import CONFIG_DEFAULTS, Sygnal, merge_left_with_defaults +from matrix_sygnal.sygnal import CONFIG_DEFAULTS, Sygnal, merge_left_with_defaults REQ_PATH = b"/_matrix/push/v1/notify" diff --git a/tox.ini b/tox.ini index e8d2ace9..9ac1f4b7 100644 --- a/tox.ini +++ b/tox.ini @@ -18,7 +18,7 @@ extras = allowlist_externals = poetry commands = - poetry run coverage run --source=sygnal -m twisted.trial tests + poetry run coverage run --source=matrix_sygnal -m twisted.trial tests poetry run coverage report --sort=cover poetry run coverage html @@ -27,13 +27,13 @@ commands = allowlist_externals = poetry commands = - poetry run ruff sygnal/ tests/ stubs - poetry run black --check --diff sygnal/ tests/ stubs - poetry run isort --check-only --diff sygnal/ tests/ stubs + poetry run ruff matrix_sygnal/ tests/ stubs + poetry run black --check --diff matrix_sygnal/ tests/ stubs + poetry run isort --check-only --diff matrix_sygnal/ tests/ stubs [testenv:check_types] allowlist_externals = poetry commands = - poetry run mypy sygnal/ tests/ stubs + poetry run mypy matrix_sygnal/ tests/ stubs