Skip to content

Commit

Permalink
Rename package fully to matrix-sygnal
Browse files Browse the repository at this point in the history
  • Loading branch information
devonh committed Jun 21, 2024
1 parent 3928be5 commit d7b14dd
Show file tree
Hide file tree
Showing 29 changed files with 93 additions and 69 deletions.
4 changes: 2 additions & 2 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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/

Expand Down Expand Up @@ -85,4 +85,4 @@ COPY --from=builder /install /usr/local

EXPOSE 5000/tcp

ENTRYPOINT ["python", "-m", "sygnal.sygnal"]
ENTRYPOINT ["python", "-m", "matrix_sygnal.sygnal"]
File renamed without changes.
12 changes: 6 additions & 6 deletions sygnal/apnspushkin.py → matrix_sygnal/apnspushkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions sygnal/gcmpushkin.py → matrix_sygnal/gcmpushkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down
17 changes: 10 additions & 7 deletions sygnal/http.py → matrix_sygnal/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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__)

Expand Down Expand Up @@ -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():
Expand Down Expand Up @@ -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
Expand Down
20 changes: 15 additions & 5 deletions sygnal/notifications.py → matrix_sygnal/notifications.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions sygnal/sygnal.py → matrix_sygnal/sygnal.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@
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
import yaml
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,
Expand All @@ -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__)

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion sygnal/utils.py → matrix_sygnal/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 5 additions & 5 deletions sygnal/webpushpushkin.py → matrix_sygnal/webpushpushkin.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,18 @@
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,
NotificationContext,
)

if TYPE_CHECKING:
from sygnal.sygnal import Sygnal
from matrix_sygnal.sygnal import Sygnal

QUEUE_TIME_HISTOGRAM = Histogram(
"sygnal_webpush_queue_time",
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
10 changes: 6 additions & 4 deletions tests/test_apns.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion tests/test_apnstruncate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions tests/test_concurrency_limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions tests/test_gcm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
Loading

0 comments on commit d7b14dd

Please sign in to comment.