From c672ab3e42c78c38c25334af81c8aaba62867879 Mon Sep 17 00:00:00 2001 From: Devon Hudson Date: Fri, 21 Jun 2024 08:38:16 -0600 Subject: [PATCH] Fix usage to keep existing internal package name --- docker/Dockerfile | 4 ++-- pyproject.toml | 5 ++++- {matrix_sygnal => sygnal}/__init__.py | 0 {matrix_sygnal => sygnal}/apnspushkin.py | 12 ++++++------ {matrix_sygnal => sygnal}/apnstruncate.py | 0 {matrix_sygnal => sygnal}/exceptions.py | 0 {matrix_sygnal => sygnal}/gcmpushkin.py | 12 ++++++------ {matrix_sygnal => sygnal}/helper/__init__.py | 0 {matrix_sygnal => sygnal}/helper/context_factory.py | 0 {matrix_sygnal => sygnal}/helper/proxy/__init__.py | 0 .../helper/proxy/connectproxyclient_twisted.py | 2 +- .../helper/proxy/proxy_asyncio.py | 4 ++-- .../helper/proxy/proxyagent_twisted.py | 6 ++---- {matrix_sygnal => sygnal}/http.py | 8 ++++---- {matrix_sygnal => sygnal}/notifications.py | 4 ++-- {matrix_sygnal => sygnal}/sygnal.py | 6 +++--- {matrix_sygnal => sygnal}/utils.py | 2 +- {matrix_sygnal => sygnal}/webpushpushkin.py | 10 +++++----- tests/test_apns.py | 10 ++++------ tests/test_apnstruncate.py | 2 +- tests/test_concurrency_limit.py | 4 ++-- tests/test_gcm.py | 4 ++-- tests/test_http.py | 8 +++----- tests/test_httpproxy_asyncio.py | 4 ++-- tests/test_httpproxy_twisted.py | 2 +- tests/test_proxy_url_parsing.py | 2 +- tests/test_pushgateway_api_v1.py | 9 ++------- tests/testutils.py | 2 +- tox.ini | 10 +++++----- 29 files changed, 62 insertions(+), 70 deletions(-) rename {matrix_sygnal => sygnal}/__init__.py (100%) rename {matrix_sygnal => sygnal}/apnspushkin.py (98%) rename {matrix_sygnal => sygnal}/apnstruncate.py (100%) rename {matrix_sygnal => sygnal}/exceptions.py (100%) rename {matrix_sygnal => sygnal}/gcmpushkin.py (98%) rename {matrix_sygnal => sygnal}/helper/__init__.py (100%) rename {matrix_sygnal => sygnal}/helper/context_factory.py (100%) rename {matrix_sygnal => sygnal}/helper/proxy/__init__.py (100%) rename {matrix_sygnal => sygnal}/helper/proxy/connectproxyclient_twisted.py (99%) rename {matrix_sygnal => sygnal}/helper/proxy/proxy_asyncio.py (99%) rename {matrix_sygnal => sygnal}/helper/proxy/proxyagent_twisted.py (97%) rename {matrix_sygnal => sygnal}/http.py (98%) rename {matrix_sygnal => sygnal}/notifications.py (99%) rename {matrix_sygnal => sygnal}/sygnal.py (98%) rename {matrix_sygnal => sygnal}/utils.py (97%) rename {matrix_sygnal => sygnal}/webpushpushkin.py (98%) diff --git a/docker/Dockerfile b/docker/Dockerfile index 47e17f69..7b8664f9 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 matrix_sygnal /sygnal/matrix_sygnal/ +COPY sygnal /sygnal/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", "matrix_sygnal.sygnal"] +ENTRYPOINT ["python", "-m", "sygnal.sygnal"] diff --git a/pyproject.toml b/pyproject.toml index de93f458..1044527a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -61,6 +61,9 @@ description = "Reference Push Gateway for Matrix Notifications" authors = ["Matrix.org Team and Contributors "] readme = "README.md" license = "Apache-2.0" +packages = [ + { include = "sygnal" }, +] include = [ { path = "tests", format = "sdist" }, ] @@ -108,4 +111,4 @@ typing-extensions = ">=3.7.4" "changelog" = "https://github.com/matrix-org/sygnal/blob/main/CHANGELOG.md" [tool.poetry.scripts] -sygnal = "matrix_sygnal.sygnal:main" +sygnal = "sygnal.sygnal:main" diff --git a/matrix_sygnal/__init__.py b/sygnal/__init__.py similarity index 100% rename from matrix_sygnal/__init__.py rename to sygnal/__init__.py diff --git a/matrix_sygnal/apnspushkin.py b/sygnal/apnspushkin.py similarity index 98% rename from matrix_sygnal/apnspushkin.py rename to sygnal/apnspushkin.py index 4ce8ca2a..a9c2d5f1 100644 --- a/matrix_sygnal/apnspushkin.py +++ b/sygnal/apnspushkin.py @@ -32,23 +32,23 @@ from prometheus_client import Counter, Gauge, Histogram from twisted.internet.defer import Deferred -from matrix_sygnal import apnstruncate -from matrix_sygnal.exceptions import ( +from sygnal import apnstruncate +from sygnal.exceptions import ( NotificationDispatchException, PushkinSetupException, TemporaryNotificationDispatchException, ) -from matrix_sygnal.helper.proxy.proxy_asyncio import ProxyingEventLoopWrapper -from matrix_sygnal.notifications import ( +from sygnal.helper.proxy.proxy_asyncio import ProxyingEventLoopWrapper +from sygnal.notifications import ( ConcurrencyLimitedPushkin, Device, Notification, NotificationContext, ) -from matrix_sygnal.utils import NotificationLoggerAdapter, twisted_sleep +from sygnal.utils import NotificationLoggerAdapter, twisted_sleep if TYPE_CHECKING: - from matrix_sygnal.sygnal import Sygnal + from sygnal.sygnal import Sygnal logger = logging.getLogger(__name__) diff --git a/matrix_sygnal/apnstruncate.py b/sygnal/apnstruncate.py similarity index 100% rename from matrix_sygnal/apnstruncate.py rename to sygnal/apnstruncate.py diff --git a/matrix_sygnal/exceptions.py b/sygnal/exceptions.py similarity index 100% rename from matrix_sygnal/exceptions.py rename to sygnal/exceptions.py diff --git a/matrix_sygnal/gcmpushkin.py b/sygnal/gcmpushkin.py similarity index 98% rename from matrix_sygnal/gcmpushkin.py rename to sygnal/gcmpushkin.py index 5b0e5699..fa3360ec 100644 --- a/matrix_sygnal/gcmpushkin.py +++ b/sygnal/gcmpushkin.py @@ -36,24 +36,24 @@ from twisted.web.http_headers import Headers from twisted.web.iweb import IResponse -from matrix_sygnal.exceptions import ( +from sygnal.exceptions import ( NotificationDispatchException, NotificationQuotaDispatchException, PushkinSetupException, TemporaryNotificationDispatchException, ) -from matrix_sygnal.helper.context_factory import ClientTLSOptionsFactory -from matrix_sygnal.helper.proxy.proxyagent_twisted import ProxyAgent -from matrix_sygnal.notifications import ( +from sygnal.helper.context_factory import ClientTLSOptionsFactory +from sygnal.helper.proxy.proxyagent_twisted import ProxyAgent +from sygnal.notifications import ( ConcurrencyLimitedPushkin, Device, Notification, NotificationContext, ) -from matrix_sygnal.utils import NotificationLoggerAdapter, json_decoder, twisted_sleep +from sygnal.utils import NotificationLoggerAdapter, json_decoder, twisted_sleep if TYPE_CHECKING: - from matrix_sygnal.sygnal import Sygnal + from sygnal.sygnal import Sygnal QUEUE_TIME_HISTOGRAM = Histogram( "sygnal_gcm_queue_time", "Time taken waiting for a connection to GCM" diff --git a/matrix_sygnal/helper/__init__.py b/sygnal/helper/__init__.py similarity index 100% rename from matrix_sygnal/helper/__init__.py rename to sygnal/helper/__init__.py diff --git a/matrix_sygnal/helper/context_factory.py b/sygnal/helper/context_factory.py similarity index 100% rename from matrix_sygnal/helper/context_factory.py rename to sygnal/helper/context_factory.py diff --git a/matrix_sygnal/helper/proxy/__init__.py b/sygnal/helper/proxy/__init__.py similarity index 100% rename from matrix_sygnal/helper/proxy/__init__.py rename to sygnal/helper/proxy/__init__.py diff --git a/matrix_sygnal/helper/proxy/connectproxyclient_twisted.py b/sygnal/helper/proxy/connectproxyclient_twisted.py similarity index 99% rename from matrix_sygnal/helper/proxy/connectproxyclient_twisted.py rename to sygnal/helper/proxy/connectproxyclient_twisted.py index cbc981b4..1cf8c697 100644 --- a/matrix_sygnal/helper/proxy/connectproxyclient_twisted.py +++ b/sygnal/helper/proxy/connectproxyclient_twisted.py @@ -34,7 +34,7 @@ from twisted.web import http from zope.interface import implementer -from matrix_sygnal.exceptions import ProxyConnectError +from sygnal.exceptions import ProxyConnectError logger = logging.getLogger(__name__) diff --git a/matrix_sygnal/helper/proxy/proxy_asyncio.py b/sygnal/helper/proxy/proxy_asyncio.py similarity index 99% rename from matrix_sygnal/helper/proxy/proxy_asyncio.py rename to sygnal/helper/proxy/proxy_asyncio.py index 30160012..31c97659 100644 --- a/matrix_sygnal/helper/proxy/proxy_asyncio.py +++ b/sygnal/helper/proxy/proxy_asyncio.py @@ -24,8 +24,8 @@ import attr -from matrix_sygnal.exceptions import ProxyConnectError -from matrix_sygnal.helper.proxy import decompose_http_proxy_url +from sygnal.exceptions import ProxyConnectError +from sygnal.helper.proxy import decompose_http_proxy_url logger = logging.getLogger(__name__) diff --git a/matrix_sygnal/helper/proxy/proxyagent_twisted.py b/sygnal/helper/proxy/proxyagent_twisted.py similarity index 97% rename from matrix_sygnal/helper/proxy/proxyagent_twisted.py rename to sygnal/helper/proxy/proxyagent_twisted.py index 12cf2c68..325a0f71 100644 --- a/matrix_sygnal/helper/proxy/proxyagent_twisted.py +++ b/sygnal/helper/proxy/proxyagent_twisted.py @@ -34,10 +34,8 @@ from twisted.web.iweb import IAgent, IBodyProducer, IPolicyForHTTPS, IResponse from zope.interface import implementer -from matrix_sygnal.helper.proxy import decompose_http_proxy_url -from matrix_sygnal.helper.proxy.connectproxyclient_twisted import ( - HTTPConnectProxyEndpoint, -) +from sygnal.helper.proxy import decompose_http_proxy_url +from sygnal.helper.proxy.connectproxyclient_twisted import HTTPConnectProxyEndpoint logger = logging.getLogger(__name__) diff --git a/matrix_sygnal/http.py b/sygnal/http.py similarity index 98% rename from matrix_sygnal/http.py rename to sygnal/http.py index ce8fc2b0..bc348926 100644 --- a/matrix_sygnal/http.py +++ b/sygnal/http.py @@ -35,15 +35,15 @@ from twisted.web.resource import Resource from twisted.web.server import NOT_DONE_YET -from matrix_sygnal.exceptions import ( +from sygnal.exceptions import ( InvalidNotificationException, NotificationDispatchException, ) -from matrix_sygnal.notifications import Notification, NotificationContext, Pushkin -from matrix_sygnal.utils import NotificationLoggerAdapter, json_decoder +from sygnal.notifications import Notification, NotificationContext, Pushkin +from sygnal.utils import NotificationLoggerAdapter, json_decoder if TYPE_CHECKING: - from matrix_sygnal.sygnal import Sygnal + from sygnal.sygnal import Sygnal logger = logging.getLogger(__name__) diff --git a/matrix_sygnal/notifications.py b/sygnal/notifications.py similarity index 99% rename from matrix_sygnal/notifications.py rename to sygnal/notifications.py index 12b5385f..9ddcda98 100644 --- a/matrix_sygnal/notifications.py +++ b/sygnal/notifications.py @@ -31,14 +31,14 @@ from opentracing import Span from prometheus_client import Counter -from matrix_sygnal.exceptions import ( +from sygnal.exceptions import ( InvalidNotificationException, NotificationDispatchException, PushkinSetupException, ) if TYPE_CHECKING: - from matrix_sygnal.sygnal import Sygnal + from sygnal.sygnal import Sygnal T = TypeVar("T") diff --git a/matrix_sygnal/sygnal.py b/sygnal/sygnal.py similarity index 98% rename from matrix_sygnal/sygnal.py rename to sygnal/sygnal.py index 375c45bc..2921e1f6 100644 --- a/matrix_sygnal/sygnal.py +++ b/sygnal/sygnal.py @@ -40,8 +40,8 @@ from twisted.python.failure import Failure from zope.interface import Interface -from matrix_sygnal.http import PushGatewayApiServer -from matrix_sygnal.notifications import Pushkin +from sygnal.http import PushGatewayApiServer +from 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"matrix_sygnal.{app_type}pushkin" + to_import = f"sygnal.{app_type}pushkin" to_construct = f"{app_type.capitalize()}Pushkin" logger.info("Importing pushkin module: %s", to_import) diff --git a/matrix_sygnal/utils.py b/sygnal/utils.py similarity index 97% rename from matrix_sygnal/utils.py rename to sygnal/utils.py index 0c3fc3fe..1cd30f76 100644 --- a/matrix_sygnal/utils.py +++ b/sygnal/utils.py @@ -19,7 +19,7 @@ from twisted.internet.defer import Deferred if TYPE_CHECKING: - from matrix_sygnal.sygnal import SygnalReactor + from sygnal.sygnal import SygnalReactor async def twisted_sleep(delay: float, twisted_reactor: "SygnalReactor") -> None: diff --git a/matrix_sygnal/webpushpushkin.py b/sygnal/webpushpushkin.py similarity index 98% rename from matrix_sygnal/webpushpushkin.py rename to sygnal/webpushpushkin.py index ea0cbc13..074a34da 100644 --- a/matrix_sygnal/webpushpushkin.py +++ b/sygnal/webpushpushkin.py @@ -31,10 +31,10 @@ from twisted.web.http_headers import Headers from twisted.web.iweb import IResponse -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 ( +from sygnal.exceptions import PushkinSetupException +from sygnal.helper.context_factory import ClientTLSOptionsFactory +from sygnal.helper.proxy.proxyagent_twisted import ProxyAgent +from sygnal.notifications import ( ConcurrencyLimitedPushkin, Device, Notification, @@ -42,7 +42,7 @@ ) if TYPE_CHECKING: - from matrix_sygnal.sygnal import Sygnal + from sygnal.sygnal import Sygnal QUEUE_TIME_HISTOGRAM = Histogram( "sygnal_webpush_queue_time", diff --git a/tests/test_apns.py b/tests/test_apns.py index 6ce84194..6a6653e3 100644 --- a/tests/test_apns.py +++ b/tests/test_apns.py @@ -17,8 +17,8 @@ from aioapns.common import NotificationResult, PushType -from matrix_sygnal import apnstruncate -from matrix_sygnal.apnspushkin import ApnsPushkin +from sygnal import apnstruncate +from sygnal.apnspushkin import ApnsPushkin from tests import testutils @@ -58,16 +58,14 @@ class ApnsTestCase(testutils.TestCase): def setUp(self) -> None: - self.apns_mock_class = patch("matrix_sygnal.apnspushkin.APNs").start() + self.apns_mock_class = patch("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( - "matrix_sygnal.apnspushkin.ApnsPushkin._report_certificate_expiration" - ).start() + patch("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 0e66efa7..bc0c0ba8 100644 --- a/tests/test_apnstruncate.py +++ b/tests/test_apnstruncate.py @@ -21,7 +21,7 @@ import unittest from typing import Any, Dict -from matrix_sygnal.apnstruncate import json_encode, truncate +from 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 c53c9ee5..ee6aa958 100644 --- a/tests/test_concurrency_limit.py +++ b/tests/test_concurrency_limit.py @@ -14,13 +14,13 @@ from typing import Any, Dict, List -from matrix_sygnal.notifications import ( +from sygnal.notifications import ( ConcurrencyLimitedPushkin, Device, Notification, NotificationContext, ) -from matrix_sygnal.utils import twisted_sleep +from sygnal.utils import twisted_sleep from tests.testutils import TestCase diff --git a/tests/test_gcm.py b/tests/test_gcm.py index 603e785c..aa35f015 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 matrix_sygnal.gcmpushkin import APIVersion, GcmPushkin +from sygnal.gcmpushkin import APIVersion, GcmPushkin from tests import testutils from tests.testutils import DummyResponse if TYPE_CHECKING: - from matrix_sygnal.sygnal import Sygnal + from 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 f463a5f8..c190a204 100644 --- a/tests/test_http.py +++ b/tests/test_http.py @@ -16,7 +16,7 @@ from aioapns.common import NotificationResult -from matrix_sygnal.apnspushkin import ApnsPushkin +from sygnal.apnspushkin import ApnsPushkin from tests import testutils @@ -50,16 +50,14 @@ class HttpTestCase(testutils.TestCase): def setUp(self) -> None: - self.apns_mock_class = patch("matrix_sygnal.apnspushkin.APNs").start() + self.apns_mock_class = patch("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( - "matrix_sygnal.apnspushkin.ApnsPushkin._report_certificate_expiration" - ).start() + patch("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 7ff8bcd0..c8b02d62 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 matrix_sygnal.exceptions import ProxyConnectError -from matrix_sygnal.helper.proxy.proxy_asyncio import HttpConnectProtocol +from sygnal.exceptions import ProxyConnectError +from 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 7f95d077..2a1dc047 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 matrix_sygnal.helper.proxy.proxyagent_twisted import ProxyAgent +from 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 8635a578..03e90b71 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 matrix_sygnal.helper.proxy import HttpProxyUrl, decompose_http_proxy_url +from 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 0fdb8edd..ab4ee7cf 100644 --- a/tests/test_pushgateway_api_v1.py +++ b/tests/test_pushgateway_api_v1.py @@ -17,16 +17,11 @@ from twisted.internet.address import IPv6Address from twisted.internet.testing import StringTransport -from matrix_sygnal.exceptions import ( +from sygnal.exceptions import ( NotificationDispatchException, TemporaryNotificationDispatchException, ) -from matrix_sygnal.notifications import ( - Device, - Notification, - NotificationContext, - Pushkin, -) +from sygnal.notifications import Device, Notification, NotificationContext, Pushkin from tests import testutils diff --git a/tests/testutils.py b/tests/testutils.py index ce08b46b..cbeca643 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 matrix_sygnal.sygnal import CONFIG_DEFAULTS, Sygnal, merge_left_with_defaults +from 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 9ac1f4b7..e8d2ace9 100644 --- a/tox.ini +++ b/tox.ini @@ -18,7 +18,7 @@ extras = allowlist_externals = poetry commands = - poetry run coverage run --source=matrix_sygnal -m twisted.trial tests + poetry run coverage run --source=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 matrix_sygnal/ tests/ stubs - poetry run black --check --diff matrix_sygnal/ tests/ stubs - poetry run isort --check-only --diff matrix_sygnal/ tests/ stubs + poetry run ruff sygnal/ tests/ stubs + poetry run black --check --diff sygnal/ tests/ stubs + poetry run isort --check-only --diff sygnal/ tests/ stubs [testenv:check_types] allowlist_externals = poetry commands = - poetry run mypy matrix_sygnal/ tests/ stubs + poetry run mypy sygnal/ tests/ stubs