Skip to content
This repository has been archived by the owner on Jan 29, 2023. It is now read-only.

Commit

Permalink
feat: shorten the imports
Browse files Browse the repository at this point in the history
  • Loading branch information
Rydra committed Jan 23, 2022
1 parent 34624ee commit e9276f7
Show file tree
Hide file tree
Showing 33 changed files with 123 additions and 84 deletions.
24 changes: 24 additions & 0 deletions melange/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
from __future__ import absolute_import

__title__ = "melange"
from melange.__version__ import __version__ # noqa

__author__ = "David Jiménez"
__license__ = "Apache License 2.0"
__copyright__ = "Copyright 2022 David Jiménez, David Arthur, and Contributors"

from melange.backends.factory import MessagingBackendFactory
from melange.consumers import Consumer, SingleDispatchConsumer, consumer
from melange.message_dispatcher import MessageDispatcher, SimpleMessageDispatcher
from melange.publishers import QueuePublisher, TopicPublisher

__all__ = [
"TopicPublisher",
"QueuePublisher",
"MessageDispatcher",
"SimpleMessageDispatcher",
"Consumer",
"SingleDispatchConsumer",
"consumer",
"MessagingBackendFactory",
]
18 changes: 18 additions & 0 deletions melange/backends/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from __future__ import absolute_import

from melange.backends.backend_manager import BackendManager
from melange.backends.interfaces import MessagingBackend
from melange.backends.kafka import KafkaBackend
from melange.backends.sqs.localsqs import LocalSQSBackend
from melange.backends.sqs.sqs_backend import AWSBackend
from melange.backends.testing import InMemoryMessagingBackend, link_synchronously

__all__ = [
"link_synchronously",
"InMemoryMessagingBackend",
"MessagingBackend",
"BackendManager",
"KafkaBackend",
"LocalSQSBackend",
"AWSBackend",
]
7 changes: 3 additions & 4 deletions melange/examples/doc_examples/backend_manager.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
from melange.backends.backend_manager import BackendManager
from melange.backends.sqs.localsqs import LocalSQSBackend
from melange import QueuePublisher
from melange.backends import BackendManager, LocalSQSBackend
from melange.examples.shared import serializer_registry
from melange.publishers import QueuePublisher
from melange.serializers.pickle import PickleSerializer
from melange.serializers import PickleSerializer


class MyTestMessage:
Expand Down
4 changes: 2 additions & 2 deletions melange/examples/doc_examples/factory_complete.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from melange.backends.factory import MessagingBackendFactory
from melange.backends.sqs.localsqs import LocalSQSBackend
from melange import MessagingBackendFactory
from melange.backends import LocalSQSBackend

backend = LocalSQSBackend()
factory = MessagingBackendFactory(backend)
Expand Down
4 changes: 2 additions & 2 deletions melange/examples/doc_examples/factory_queue.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from melange.backends.factory import MessagingBackendFactory
from melange.backends.sqs.localsqs import LocalSQSBackend
from melange import MessagingBackendFactory
from melange.backends import LocalSQSBackend

backend = LocalSQSBackend()
factory = MessagingBackendFactory(backend)
Expand Down
4 changes: 2 additions & 2 deletions melange/examples/doc_examples/factory_topic.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from melange.backends.factory import MessagingBackendFactory
from melange.backends.sqs.sqs_backend import AWSBackend
from melange import MessagingBackendFactory
from melange.backends import AWSBackend

backend = AWSBackend()
factory = MessagingBackendFactory(backend)
Expand Down
2 changes: 1 addition & 1 deletion melange/examples/doc_examples/serializer_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

from melange.exceptions import SerializationError
from melange.helpers.typing import T
from melange.serializers.interfaces import Serializer
from melange.serializers import Serializer


class MyOwnSerializer(Serializer):
Expand Down
6 changes: 3 additions & 3 deletions melange/examples/doc_examples/topic_publish.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from melange.backends.sqs.localsqs import LocalSQSBackend
from melange import TopicPublisher
from melange.backends import LocalSQSBackend
from melange.examples.shared import serializer_registry
from melange.publishers import TopicPublisher
from melange.serializers.pickle import PickleSerializer
from melange.serializers import PickleSerializer


class MyTestMessage:
Expand Down
8 changes: 3 additions & 5 deletions melange/examples/doc_examples/tutorial/consume.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from simple_cqrs.domain_event import DomainEvent

from melange.backends.sqs.localsqs import LocalSQSBackend
from melange.consumers import SingleDispatchConsumer, consumer
from melange import SimpleMessageDispatcher, SingleDispatchConsumer, consumer
from melange.backends import LocalSQSBackend
from melange.examples.doc_examples.tutorial.publish import MyTestMessage
from melange.message_dispatcher import SimpleMessageDispatcher
from melange.serializers.pickle import PickleSerializer
from melange.serializers.registry import SerializerRegistry
from melange.serializers import PickleSerializer, SerializerRegistry


class MyConsumer(SingleDispatchConsumer):
Expand Down
4 changes: 2 additions & 2 deletions melange/examples/doc_examples/tutorial/create_queue.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from melange.backends.factory import MessagingBackendFactory
from melange.backends.sqs.localsqs import LocalSQSBackend
from melange import MessagingBackendFactory
from melange.backends import LocalSQSBackend

backend = LocalSQSBackend(host="localhost", port=9324)
factory = MessagingBackendFactory(backend)
Expand Down
7 changes: 3 additions & 4 deletions melange/examples/doc_examples/tutorial/publish.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from simple_cqrs.domain_event import DomainEvent

from melange.backends.sqs.localsqs import LocalSQSBackend
from melange.publishers import QueuePublisher
from melange.serializers.pickle import PickleSerializer
from melange.serializers.registry import SerializerRegistry
from melange import QueuePublisher
from melange.backends import LocalSQSBackend
from melange.serializers import PickleSerializer, SerializerRegistry


class MyTestMessage:
Expand Down
4 changes: 2 additions & 2 deletions melange/examples/init_queues.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os

from melange.backends.factory import MessagingBackendFactory
from melange.backends.sqs.localsqs import LocalSQSBackend
from melange import MessagingBackendFactory
from melange.backends import LocalSQSBackend

if __name__ == "__main__":
backend = LocalSQSBackend(
Expand Down
7 changes: 3 additions & 4 deletions melange/examples/payment_service/app.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import os

from melange.backends.sqs.localsqs import LocalSQSBackend
from melange import MessageDispatcher, QueuePublisher
from melange.backends import LocalSQSBackend
from melange.examples.payment_service.consumer import PaymentConsumer
from melange.examples.payment_service.publisher import PaymentPublisher
from melange.examples.payment_service.repository import PaymentRepository
from melange.examples.payment_service.service import PaymentService
from melange.examples.shared import serializer_registry
from melange.message_dispatcher import MessageDispatcher
from melange.publishers import QueuePublisher
from melange.serializers.pickle import PickleSerializer
from melange.serializers import PickleSerializer

if __name__ == "__main__":
serializer = PickleSerializer()
Expand Down
7 changes: 3 additions & 4 deletions melange/examples/payment_service/app_simpleconsumer.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
import os

from melange.backends.sqs.localsqs import LocalSQSBackend
from melange import QueuePublisher, SimpleMessageDispatcher
from melange.backends import LocalSQSBackend
from melange.examples.payment_service.consumer import PaymentConsumer
from melange.examples.payment_service.publisher import PaymentPublisher
from melange.examples.payment_service.repository import PaymentRepository
from melange.examples.payment_service.service import PaymentService
from melange.examples.shared import serializer_registry
from melange.message_dispatcher import SimpleMessageDispatcher
from melange.publishers import QueuePublisher
from melange.serializers.pickle import PickleSerializer
from melange.serializers import PickleSerializer

if __name__ == "__main__":
serializer = PickleSerializer()
Expand Down
2 changes: 1 addition & 1 deletion melange/examples/payment_service/consumer.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from melange.consumers import SingleDispatchConsumer, consumer
from melange import SingleDispatchConsumer, consumer
from melange.examples.common.commands import DoPayment
from melange.examples.payment_service.events import OrderResponse
from melange.examples.payment_service.service import PaymentService
Expand Down
2 changes: 1 addition & 1 deletion melange/examples/payment_service/consumer_draft.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Any, Optional

from melange.consumers import Consumer
from melange import Consumer
from melange.examples.common.commands import DoPayment
from melange.examples.payment_service.events import OrderResponse
from melange.examples.payment_service.service import PaymentService
Expand Down
2 changes: 1 addition & 1 deletion melange/examples/payment_service/publisher.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from melange import QueuePublisher
from melange.examples.payment_service.events import OrderStatus
from melange.publishers import QueuePublisher


class PaymentPublisher:
Expand Down
6 changes: 2 additions & 4 deletions melange/examples/payment_service/triggerer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
import os
import uuid

from melange.backends.sqs.localsqs import LocalSQSBackend
from melange import QueuePublisher
from melange.backends import LocalSQSBackend
from melange.examples.payment_service.events import OrderResponse
from melange.examples.shared import serializer_registry
from melange.publishers import QueuePublisher
from melange.serializers.pickle import PickleSerializer

if __name__ == "__main__":
parser = argparse.ArgumentParser(
Expand All @@ -16,7 +15,6 @@
args = parser.parse_args()

order_reponse = OrderResponse(id=str(uuid.uuid4()), reference=args.reference)
serializer = PickleSerializer()
backend = LocalSQSBackend(
host=os.environ.get("SQSHOST"), port=os.environ.get("SQSPORT")
)
Expand Down
7 changes: 3 additions & 4 deletions melange/examples/saga_pattern/app.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import os

from melange.backends.sqs.localsqs import LocalSQSBackend
from melange import QueuePublisher, SimpleMessageDispatcher
from melange.backends import LocalSQSBackend
from melange.examples.saga_pattern.consumer import SagaConsumer
from melange.examples.saga_pattern.publisher import SagaPublisher
from melange.examples.saga_pattern.repository import SagaRepository
from melange.examples.shared import serializer_registry
from melange.message_dispatcher import SimpleMessageDispatcher
from melange.publishers import QueuePublisher
from melange.serializers.pickle import PickleSerializer
from melange.serializers import PickleSerializer

if __name__ == "__main__":
serializer = PickleSerializer()
Expand Down
2 changes: 1 addition & 1 deletion melange/examples/saga_pattern/consumer.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import uuid
from typing import Any

from melange.consumers import SingleDispatchConsumer, consumer
from melange import SingleDispatchConsumer, consumer
from melange.examples.common.commands import DoPayment
from melange.examples.payment_service.events import OrderResponse, OrderStatus
from melange.examples.saga_pattern.models import Saga
Expand Down
2 changes: 1 addition & 1 deletion melange/examples/saga_pattern/publisher.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from melange import QueuePublisher
from melange.examples.common.commands import DoPayment
from melange.publishers import QueuePublisher


class SagaPublisher:
Expand Down
6 changes: 3 additions & 3 deletions melange/examples/saga_pattern/saga_triggerer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
import os
import uuid

from melange.backends.sqs.localsqs import LocalSQSBackend
from melange import QueuePublisher
from melange.backends import LocalSQSBackend
from melange.examples.payment_service.events import OrderResponse
from melange.examples.shared import serializer_registry
from melange.publishers import QueuePublisher
from melange.serializers.pickle import PickleSerializer
from melange.serializers import PickleSerializer

if __name__ == "__main__":
parser = argparse.ArgumentParser(
Expand Down
3 changes: 1 addition & 2 deletions melange/examples/shared.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
from simple_cqrs.domain_event import DomainEvent

from melange.serializers.pickle import PickleSerializer
from melange.serializers.registry import SerializerRegistry
from melange.serializers import PickleSerializer, SerializerRegistry

serializer_settings = {
"serializers": {"pickle": PickleSerializer},
Expand Down
13 changes: 13 additions & 0 deletions melange/serializers/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from __future__ import absolute_import

__all__ = [
"Serializer",
"JsonSerializer",
"PickleSerializer",
"SerializerRegistry",
]

from melange.serializers.interfaces import Serializer
from melange.serializers.json import JsonSerializer
from melange.serializers.pickle import PickleSerializer
from melange.serializers.registry import SerializerRegistry
4 changes: 2 additions & 2 deletions tests/backends/test_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import pytest
from hamcrest import *

from melange.backends.factory import MessagingBackendFactory
from melange.backends.sqs.localsqs import LocalSQSBackend
from melange import MessagingBackendFactory
from melange.backends import LocalSQSBackend


class TestFactory:
Expand Down
2 changes: 1 addition & 1 deletion tests/backends/test_localsqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest
from hamcrest import *

from melange.backends.sqs.localsqs import LocalSQSBackend
from melange.backends import LocalSQSBackend
from melange.models import Message


Expand Down
15 changes: 8 additions & 7 deletions tests/doc_examples/test_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@
import polling
from hamcrest import *

from melange.backends.factory import MessagingBackendFactory
from melange.backends.sqs.localsqs import LocalSQSBackend
from melange.consumers import Consumer
from melange.message_dispatcher import SimpleMessageDispatcher
from melange.publishers import QueuePublisher
from melange.serializers.pickle import PickleSerializer
from melange.serializers.registry import SerializerRegistry
from melange import (
Consumer,
MessagingBackendFactory,
QueuePublisher,
SimpleMessageDispatcher,
)
from melange.backends import LocalSQSBackend
from melange.serializers import PickleSerializer, SerializerRegistry
from tests.probe import Probe


Expand Down
8 changes: 3 additions & 5 deletions tests/doc_examples/test_testing.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
from melange.backends.testing import InMemoryMessagingBackend, link_synchronously
from melange.consumers import Consumer
from melange.publishers import QueuePublisher
from melange.serializers.pickle import PickleSerializer
from melange.serializers.registry import SerializerRegistry
from melange import Consumer, QueuePublisher
from melange.backends import InMemoryMessagingBackend, link_synchronously
from melange.serializers import PickleSerializer, SerializerRegistry

serializer_settings = {
"serializers": {
Expand Down
4 changes: 2 additions & 2 deletions tests/fixtures.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import json
from typing import Any, Optional

from melange.consumers import SingleDispatchConsumer, consumer
from melange.serializers.interfaces import Serializer
from melange import SingleDispatchConsumer, consumer
from melange.serializers import Serializer


class BaseMessage:
Expand Down
5 changes: 2 additions & 3 deletions tests/serializers/test_registry.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

from hamcrest import *

from melange.serializers.json import JsonSerializer
from melange.serializers.pickle import PickleSerializer
from melange.serializers.registry import SerializerRegistry, sort
from melange.serializers import JsonSerializer, PickleSerializer, SerializerRegistry
from melange.serializers.registry import sort
from tests.fixtures import (
BananaHappened,
BaseMessage,
Expand Down
8 changes: 3 additions & 5 deletions tests/test_message_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@
from doublex import ANY_ARG, ProxySpy, Spy, called, never
from hamcrest import *

from melange.backends.interfaces import MessagingBackend
from melange.message_dispatcher import SimpleMessageDispatcher
from melange import SimpleMessageDispatcher
from melange.backends import MessagingBackend
from melange.models import Message
from melange.serializers.json import JsonSerializer
from melange.serializers.pickle import PickleSerializer
from melange.serializers.registry import SerializerRegistry
from melange.serializers import JsonSerializer, PickleSerializer, SerializerRegistry
from tests.fixtures import (
BananaConsumer,
BananaHappened,
Expand Down
2 changes: 1 addition & 1 deletion tests/test_pickleserializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from hamcrest import *

from melange.examples.payment_service.events import OrderResponse
from melange.serializers.pickle import PickleSerializer
from melange.serializers import PickleSerializer


def test_pickle_a_domain_event():
Expand Down
Loading

0 comments on commit e9276f7

Please sign in to comment.