From 443c189b7139639ff59b7b9561e04d1a6360e346 Mon Sep 17 00:00:00 2001 From: Andrew Whitehead Date: Tue, 10 Dec 2019 12:17:06 -0800 Subject: [PATCH 1/3] refactor modules into core and utils packages Signed-off-by: Andrew Whitehead --- aries_cloudagent/admin/error.py | 2 +- aries_cloudagent/admin/server.py | 5 +-- aries_cloudagent/cache/base.py | 2 +- aries_cloudagent/commands/start.py | 2 +- aries_cloudagent/config/base.py | 2 +- aries_cloudagent/config/default_context.py | 2 +- aries_cloudagent/config/provider.py | 5 ++- aries_cloudagent/{tests => core}/__init__.py | 0 aries_cloudagent/{ => core}/conductor.py | 35 ++++++++--------- aries_cloudagent/{ => core}/dispatcher.py | 28 +++++++------- aries_cloudagent/{ => core}/error.py | 0 aries_cloudagent/core/tests/__init__.py | 0 .../{ => core}/tests/test_conductor.py | 38 +++++++++---------- .../{ => core}/tests/test_dispatcher.py | 18 ++++----- aries_cloudagent/issuer/indy.py | 4 +- aries_cloudagent/ledger/error.py | 2 +- aries_cloudagent/ledger/provider.py | 2 +- aries_cloudagent/messaging/base_handler.py | 3 +- aries_cloudagent/messaging/decorators/base.py | 2 +- aries_cloudagent/messaging/error.py | 2 +- aries_cloudagent/messaging/models/base.py | 4 +- aries_cloudagent/messaging/plugin_registry.py | 2 +- .../messaging/protocol_registry.py | 2 +- aries_cloudagent/messaging/responder.py | 2 +- .../messaging/tests/test_plugin_registry.py | 2 +- .../protocols/connections/manager.py | 2 +- .../protocols/credentials/manager.py | 2 +- .../protocols/introduction/base_service.py | 2 +- .../issue_credential/v1_0/manager.py | 2 +- .../protocols/present_proof/v1_0/manager.py | 2 +- .../protocols/presentations/manager.py | 2 +- aries_cloudagent/protocols/routing/manager.py | 2 +- aries_cloudagent/storage/error.py | 2 +- aries_cloudagent/storage/provider.py | 2 +- aries_cloudagent/transport/error.py | 2 +- aries_cloudagent/transport/inbound/manager.py | 2 +- aries_cloudagent/transport/outbound/base.py | 2 +- .../transport/outbound/manager.py | 4 +- .../outbound/tests/test_http_transport.py | 2 +- aries_cloudagent/transport/stats.py | 2 +- aries_cloudagent/utils/__init__.py | 0 aries_cloudagent/{ => utils}/classloader.py | 2 +- aries_cloudagent/{ => utils}/stats.py | 0 aries_cloudagent/utils/tests/__init__.py | 0 .../{ => utils}/tests/test_classloader.py | 23 +++++------ .../{ => utils}/tests/test_stats.py | 0 aries_cloudagent/wallet/error.py | 2 +- aries_cloudagent/wallet/provider.py | 2 +- 48 files changed, 115 insertions(+), 112 deletions(-) rename aries_cloudagent/{tests => core}/__init__.py (100%) rename aries_cloudagent/{ => core}/conductor.py (93%) rename aries_cloudagent/{ => core}/dispatcher.py (92%) rename aries_cloudagent/{ => core}/error.py (100%) create mode 100644 aries_cloudagent/core/tests/__init__.py rename aries_cloudagent/{ => core}/tests/test_conductor.py (91%) rename aries_cloudagent/{ => core}/tests/test_dispatcher.py (83%) create mode 100644 aries_cloudagent/utils/__init__.py rename aries_cloudagent/{ => utils}/classloader.py (99%) rename aries_cloudagent/{ => utils}/stats.py (100%) create mode 100644 aries_cloudagent/utils/tests/__init__.py rename aries_cloudagent/{ => utils}/tests/test_classloader.py (83%) rename aries_cloudagent/{ => utils}/tests/test_stats.py (100%) diff --git a/aries_cloudagent/admin/error.py b/aries_cloudagent/admin/error.py index 8e348a121b..b5f8f58b07 100644 --- a/aries_cloudagent/admin/error.py +++ b/aries_cloudagent/admin/error.py @@ -1,6 +1,6 @@ """Admin error classes.""" -from ..error import BaseError +from ..core.error import BaseError class AdminError(BaseError): diff --git a/aries_cloudagent/admin/server.py b/aries_cloudagent/admin/server.py index 73e6356391..b7bb58d1c2 100644 --- a/aries_cloudagent/admin/server.py +++ b/aries_cloudagent/admin/server.py @@ -15,15 +15,14 @@ from ..messaging.plugin_registry import PluginRegistry from ..messaging.responder import BaseResponder from ..messaging.task_queue import TaskQueue -from ..stats import Collector from ..transport.queue.basic import BasicMessageQueue from ..transport.outbound.message import OutboundMessage +from ..utils.stats import Collector +from ..version import __version__ from .base_server import BaseAdminServer from .error import AdminSetupError -from ..version import __version__ - LOGGER = logging.getLogger(__name__) diff --git a/aries_cloudagent/cache/base.py b/aries_cloudagent/cache/base.py index f489450c04..0f3cc445db 100644 --- a/aries_cloudagent/cache/base.py +++ b/aries_cloudagent/cache/base.py @@ -4,7 +4,7 @@ from abc import ABC, abstractmethod from typing import Any, Sequence, Text, Union -from ..error import BaseError +from ..core.error import BaseError class CacheError(BaseError): diff --git a/aries_cloudagent/commands/start.py b/aries_cloudagent/commands/start.py index f98c813f5c..79873057b4 100644 --- a/aries_cloudagent/commands/start.py +++ b/aries_cloudagent/commands/start.py @@ -13,7 +13,7 @@ except ImportError: uvloop = None -from ..conductor import Conductor +from ..core.conductor import Conductor from ..config import argparse as arg from ..config.default_context import DefaultContextBuilder from ..config.util import common_config diff --git a/aries_cloudagent/config/base.py b/aries_cloudagent/config/base.py index c19d3b50a5..1f04378682 100644 --- a/aries_cloudagent/config/base.py +++ b/aries_cloudagent/config/base.py @@ -3,7 +3,7 @@ from abc import ABC, abstractmethod from typing import Mapping -from ..error import BaseError +from ..core.error import BaseError class ConfigError(BaseError): diff --git a/aries_cloudagent/config/default_context.py b/aries_cloudagent/config/default_context.py index 7ce066251b..a4b1f54757 100644 --- a/aries_cloudagent/config/default_context.py +++ b/aries_cloudagent/config/default_context.py @@ -17,10 +17,10 @@ from ..protocols.actionmenu.driver_service import DriverMenuService from ..protocols.introduction.base_service import BaseIntroductionService from ..protocols.introduction.demo_service import DemoIntroductionService -from ..stats import Collector from ..storage.base import BaseStorage from ..storage.provider import StorageProvider from ..transport.wire_format import BaseWireFormat +from ..utils.stats import Collector from ..wallet.base import BaseWallet from ..wallet.provider import WalletProvider diff --git a/aries_cloudagent/config/provider.py b/aries_cloudagent/config/provider.py index 3aba0f39a8..902230fac0 100644 --- a/aries_cloudagent/config/provider.py +++ b/aries_cloudagent/config/provider.py @@ -2,9 +2,10 @@ from typing import Sequence, Union +from ..utils.classloader import ClassLoader +from ..utils.stats import Collector + from .base import BaseProvider, BaseSettings, BaseInjector -from ..classloader import ClassLoader -from ..stats import Collector class InstanceProvider(BaseProvider): diff --git a/aries_cloudagent/tests/__init__.py b/aries_cloudagent/core/__init__.py similarity index 100% rename from aries_cloudagent/tests/__init__.py rename to aries_cloudagent/core/__init__.py diff --git a/aries_cloudagent/conductor.py b/aries_cloudagent/core/conductor.py similarity index 93% rename from aries_cloudagent/conductor.py rename to aries_cloudagent/core/conductor.py index 0a0fbbfe95..396d2b7047 100644 --- a/aries_cloudagent/conductor.py +++ b/aries_cloudagent/core/conductor.py @@ -11,24 +11,25 @@ import hashlib import logging -from .admin.base_server import BaseAdminServer -from .admin.server import AdminServer -from .config.default_context import ContextBuilder -from .config.injection_context import InjectionContext -from .config.ledger import ledger_config -from .config.logging import LoggingConfigurator -from .config.wallet import wallet_config +from ..admin.base_server import BaseAdminServer +from ..admin.server import AdminServer +from ..config.default_context import ContextBuilder +from ..config.injection_context import InjectionContext +from ..config.ledger import ledger_config +from ..config.logging import LoggingConfigurator +from ..config.wallet import wallet_config +from ..messaging.responder import BaseResponder +from ..messaging.task_queue import CompletedTask, TaskQueue +from ..protocols.connections.manager import ConnectionManager, ConnectionManagerError +from ..transport.inbound.manager import InboundTransportManager +from ..transport.inbound.message import InboundMessage +from ..transport.outbound.base import OutboundDeliveryError +from ..transport.outbound.manager import OutboundTransportManager +from ..transport.outbound.message import OutboundMessage +from ..transport.wire_format import BaseWireFormat +from ..utils.stats import Collector + from .dispatcher import Dispatcher -from .protocols.connections.manager import ConnectionManager, ConnectionManagerError -from .messaging.responder import BaseResponder -from .messaging.task_queue import CompletedTask, TaskQueue -from .stats import Collector -from .transport.inbound.manager import InboundTransportManager -from .transport.inbound.message import InboundMessage -from .transport.outbound.base import OutboundDeliveryError -from .transport.outbound.manager import OutboundTransportManager -from .transport.outbound.message import OutboundMessage -from .transport.wire_format import BaseWireFormat LOGGER = logging.getLogger(__name__) diff --git a/aries_cloudagent/dispatcher.py b/aries_cloudagent/core/dispatcher.py similarity index 92% rename from aries_cloudagent/dispatcher.py rename to aries_cloudagent/core/dispatcher.py index 10cd2c8443..15b519d9fd 100644 --- a/aries_cloudagent/dispatcher.py +++ b/aries_cloudagent/core/dispatcher.py @@ -12,20 +12,20 @@ from aiohttp.web import HTTPException -from .config.injection_context import InjectionContext -from .messaging.agent_message import AgentMessage -from .messaging.error import MessageParseError -from .messaging.models.base import BaseModelError -from .protocols.connections.manager import ConnectionManager -from .protocols.problem_report.message import ProblemReport -from .messaging.protocol_registry import ProtocolRegistry -from .messaging.request_context import RequestContext -from .messaging.responder import BaseResponder -from .messaging.task_queue import CompletedTask, PendingTask, TaskQueue -from .messaging.util import datetime_now -from .stats import Collector -from .transport.inbound.message import InboundMessage -from .transport.outbound.message import OutboundMessage +from ..config.injection_context import InjectionContext +from ..messaging.agent_message import AgentMessage +from ..messaging.error import MessageParseError +from ..messaging.models.base import BaseModelError +from ..messaging.protocol_registry import ProtocolRegistry +from ..messaging.request_context import RequestContext +from ..messaging.responder import BaseResponder +from ..messaging.task_queue import CompletedTask, PendingTask, TaskQueue +from ..messaging.util import datetime_now +from ..protocols.connections.manager import ConnectionManager +from ..protocols.problem_report.message import ProblemReport +from ..transport.inbound.message import InboundMessage +from ..transport.outbound.message import OutboundMessage +from ..utils.stats import Collector LOGGER = logging.getLogger(__name__) diff --git a/aries_cloudagent/error.py b/aries_cloudagent/core/error.py similarity index 100% rename from aries_cloudagent/error.py rename to aries_cloudagent/core/error.py diff --git a/aries_cloudagent/core/tests/__init__.py b/aries_cloudagent/core/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/aries_cloudagent/tests/test_conductor.py b/aries_cloudagent/core/tests/test_conductor.py similarity index 91% rename from aries_cloudagent/tests/test_conductor.py rename to aries_cloudagent/core/tests/test_conductor.py index 425e98a3e2..f1996bd083 100644 --- a/aries_cloudagent/tests/test_conductor.py +++ b/aries_cloudagent/core/tests/test_conductor.py @@ -4,30 +4,30 @@ from asynctest import mock as async_mock from .. import conductor as test_module -from ..admin.base_server import BaseAdminServer -from ..config.base_context import ContextBuilder -from ..config.injection_context import InjectionContext -from ..protocols.connections.manager import ConnectionManager -from ..connections.models.connection_record import ConnectionRecord -from ..connections.models.connection_target import ConnectionTarget -from ..connections.models.diddoc import ( +from ...admin.base_server import BaseAdminServer +from ...config.base_context import ContextBuilder +from ...config.injection_context import InjectionContext +from ...connections.models.connection_record import ConnectionRecord +from ...connections.models.connection_target import ConnectionTarget +from ...connections.models.diddoc import ( DIDDoc, PublicKey, PublicKeyType, Service, ) -from ..messaging.protocol_registry import ProtocolRegistry -from ..stats import Collector -from ..storage.base import BaseStorage -from ..storage.basic import BasicStorage -from ..transport.inbound.base import InboundTransportConfiguration -from ..transport.inbound.message import InboundMessage -from ..transport.inbound.receipt import MessageReceipt -from ..transport.outbound.base import OutboundDeliveryError -from ..transport.outbound.message import OutboundMessage -from ..transport.wire_format import BaseWireFormat -from ..wallet.base import BaseWallet -from ..wallet.basic import BasicWallet +from ...messaging.protocol_registry import ProtocolRegistry +from ...protocols.connections.manager import ConnectionManager +from ...storage.base import BaseStorage +from ...storage.basic import BasicStorage +from ...transport.inbound.base import InboundTransportConfiguration +from ...transport.inbound.message import InboundMessage +from ...transport.inbound.receipt import MessageReceipt +from ...transport.outbound.base import OutboundDeliveryError +from ...transport.outbound.message import OutboundMessage +from ...transport.wire_format import BaseWireFormat +from ...utils.stats import Collector +from ...wallet.base import BaseWallet +from ...wallet.basic import BasicWallet class Config: diff --git a/aries_cloudagent/tests/test_dispatcher.py b/aries_cloudagent/core/tests/test_dispatcher.py similarity index 83% rename from aries_cloudagent/tests/test_dispatcher.py rename to aries_cloudagent/core/tests/test_dispatcher.py index 66c1b5e7df..dc2be57b3d 100644 --- a/aries_cloudagent/tests/test_dispatcher.py +++ b/aries_cloudagent/core/tests/test_dispatcher.py @@ -4,15 +4,15 @@ from asynctest import TestCase as AsyncTestCase, mock as async_mock from .. import dispatcher as test_module -from ..config.injection_context import InjectionContext -from ..connections.models.connection_record import ConnectionRecord -from ..messaging.agent_message import AgentMessage, AgentMessageSchema -from ..messaging.error import MessageParseError -from ..messaging.protocol_registry import ProtocolRegistry -from ..protocols.problem_report.message import ProblemReport -from ..transport.inbound.message import InboundMessage -from ..transport.inbound.receipt import MessageReceipt -from ..transport.outbound.message import OutboundMessage +from ...config.injection_context import InjectionContext +from ...connections.models.connection_record import ConnectionRecord +from ...messaging.agent_message import AgentMessage, AgentMessageSchema +from ...messaging.error import MessageParseError +from ...messaging.protocol_registry import ProtocolRegistry +from ...protocols.problem_report.message import ProblemReport +from ...transport.inbound.message import InboundMessage +from ...transport.inbound.receipt import MessageReceipt +from ...transport.outbound.message import OutboundMessage def make_context() -> InjectionContext: diff --git a/aries_cloudagent/issuer/indy.py b/aries_cloudagent/issuer/indy.py index b81ca6c5c9..516ab91f91 100644 --- a/aries_cloudagent/issuer/indy.py +++ b/aries_cloudagent/issuer/indy.py @@ -3,10 +3,10 @@ import json import logging - import indy.anoncreds -from ..error import BaseError +from ..core.error import BaseError + from .base import BaseIssuer from .util import encode diff --git a/aries_cloudagent/ledger/error.py b/aries_cloudagent/ledger/error.py index a51c97d785..700ed89dc1 100644 --- a/aries_cloudagent/ledger/error.py +++ b/aries_cloudagent/ledger/error.py @@ -1,6 +1,6 @@ """Ledger related errors.""" -from ..error import BaseError +from ..core.error import BaseError class LedgerError(BaseError): diff --git a/aries_cloudagent/ledger/provider.py b/aries_cloudagent/ledger/provider.py index 29dac6ecd6..89dfa4dca4 100644 --- a/aries_cloudagent/ledger/provider.py +++ b/aries_cloudagent/ledger/provider.py @@ -3,8 +3,8 @@ import logging from ..cache.base import BaseCache -from ..classloader import ClassLoader from ..config.base import BaseProvider, BaseInjector, BaseSettings +from ..utils.classloader import ClassLoader from ..wallet.base import BaseWallet LOGGER = logging.getLogger(__name__) diff --git a/aries_cloudagent/messaging/base_handler.py b/aries_cloudagent/messaging/base_handler.py index 3d598023b6..3418a7b096 100644 --- a/aries_cloudagent/messaging/base_handler.py +++ b/aries_cloudagent/messaging/base_handler.py @@ -3,7 +3,8 @@ from abc import ABC, abstractmethod import logging -from ..error import BaseError +from ..core.error import BaseError + from .responder import BaseResponder from .request_context import RequestContext diff --git a/aries_cloudagent/messaging/decorators/base.py b/aries_cloudagent/messaging/decorators/base.py index 717f8ed3ec..4771f04651 100644 --- a/aries_cloudagent/messaging/decorators/base.py +++ b/aries_cloudagent/messaging/decorators/base.py @@ -6,7 +6,7 @@ from marshmallow import Schema from marshmallow.fields import Field -from ...error import BaseError +from ...core.error import BaseError from ..models.base import BaseModel diff --git a/aries_cloudagent/messaging/error.py b/aries_cloudagent/messaging/error.py index 43f2db8316..6c73219f9d 100644 --- a/aries_cloudagent/messaging/error.py +++ b/aries_cloudagent/messaging/error.py @@ -1,6 +1,6 @@ """Messaging-related error classes and codes.""" -from ..error import BaseError +from ..core.error import BaseError class MessageParseError(BaseError): diff --git a/aries_cloudagent/messaging/models/base.py b/aries_cloudagent/messaging/models/base.py index 06772fa294..05af84e107 100644 --- a/aries_cloudagent/messaging/models/base.py +++ b/aries_cloudagent/messaging/models/base.py @@ -6,8 +6,8 @@ from marshmallow import Schema, post_dump, pre_load, post_load, ValidationError -from ...classloader import ClassLoader -from ...error import BaseError +from ...core.error import BaseError +from ...utils.classloader import ClassLoader LOGGER = logging.getLogger(__name__) diff --git a/aries_cloudagent/messaging/plugin_registry.py b/aries_cloudagent/messaging/plugin_registry.py index 3191cd1bdc..f6ebefd1f5 100644 --- a/aries_cloudagent/messaging/plugin_registry.py +++ b/aries_cloudagent/messaging/plugin_registry.py @@ -5,9 +5,9 @@ from types import ModuleType from typing import Sequence -from ..classloader import ClassLoader, ModuleLoadError from ..config.injection_context import InjectionContext from ..messaging.protocol_registry import ProtocolRegistry +from ..utils.classloader import ClassLoader, ModuleLoadError LOGGER = logging.getLogger(__name__) diff --git a/aries_cloudagent/messaging/protocol_registry.py b/aries_cloudagent/messaging/protocol_registry.py index cf1708007c..63575832f1 100644 --- a/aries_cloudagent/messaging/protocol_registry.py +++ b/aries_cloudagent/messaging/protocol_registry.py @@ -2,8 +2,8 @@ from typing import Mapping, Sequence -from ..classloader import ClassLoader from ..config.injection_context import InjectionContext +from ..utils.classloader import ClassLoader class ProtocolRegistry: diff --git a/aries_cloudagent/messaging/responder.py b/aries_cloudagent/messaging/responder.py index 3718c59145..f36ed1cb18 100644 --- a/aries_cloudagent/messaging/responder.py +++ b/aries_cloudagent/messaging/responder.py @@ -8,7 +8,7 @@ from abc import ABC, abstractmethod from typing import Sequence, Union -from ..error import BaseError +from ..core.error import BaseError from ..connections.models.connection_target import ConnectionTarget from ..transport.outbound.message import OutboundMessage diff --git a/aries_cloudagent/messaging/tests/test_plugin_registry.py b/aries_cloudagent/messaging/tests/test_plugin_registry.py index 31948c3e65..92ec76a398 100644 --- a/aries_cloudagent/messaging/tests/test_plugin_registry.py +++ b/aries_cloudagent/messaging/tests/test_plugin_registry.py @@ -1,7 +1,7 @@ from asynctest import TestCase as AsyncTestCase, mock as async_mock -from ...classloader import ClassLoader from ...config.injection_context import InjectionContext +from ...utils.classloader import ClassLoader from ..plugin_registry import PluginRegistry diff --git a/aries_cloudagent/protocols/connections/manager.py b/aries_cloudagent/protocols/connections/manager.py index c475ba67ff..febb402c1e 100644 --- a/aries_cloudagent/protocols/connections/manager.py +++ b/aries_cloudagent/protocols/connections/manager.py @@ -10,7 +10,7 @@ from ...connections.models.diddoc import DIDDoc, PublicKey, PublicKeyType, Service from ...config.base import InjectorError from ...config.injection_context import InjectionContext -from ...error import BaseError +from ...core.error import BaseError from ...ledger.base import BaseLedger from ...messaging.responder import BaseResponder from ...storage.base import BaseStorage diff --git a/aries_cloudagent/protocols/credentials/manager.py b/aries_cloudagent/protocols/credentials/manager.py index 3173033059..4a39475337 100644 --- a/aries_cloudagent/protocols/credentials/manager.py +++ b/aries_cloudagent/protocols/credentials/manager.py @@ -5,7 +5,7 @@ from ...config.injection_context import InjectionContext from ...connections.models.connection_record import ConnectionRecord -from ...error import BaseError +from ...core.error import BaseError from ...holder.base import BaseHolder from ...issuer.base import BaseIssuer from ...ledger.base import BaseLedger diff --git a/aries_cloudagent/protocols/introduction/base_service.py b/aries_cloudagent/protocols/introduction/base_service.py index e04a603ade..c562ea05a8 100644 --- a/aries_cloudagent/protocols/introduction/base_service.py +++ b/aries_cloudagent/protocols/introduction/base_service.py @@ -2,7 +2,7 @@ from abc import ABC, abstractmethod -from ...error import BaseError +from ...core.error import BaseError from ...messaging.request_context import RequestContext from .messages.invitation import Invitation diff --git a/aries_cloudagent/protocols/issue_credential/v1_0/manager.py b/aries_cloudagent/protocols/issue_credential/v1_0/manager.py index aa56aa056f..cba7bfac12 100644 --- a/aries_cloudagent/protocols/issue_credential/v1_0/manager.py +++ b/aries_cloudagent/protocols/issue_credential/v1_0/manager.py @@ -5,7 +5,7 @@ from ....cache.base import BaseCache from ....config.injection_context import InjectionContext -from ....error import BaseError +from ....core.error import BaseError from ....holder.base import BaseHolder from ....issuer.base import BaseIssuer from ....ledger.base import BaseLedger diff --git a/aries_cloudagent/protocols/present_proof/v1_0/manager.py b/aries_cloudagent/protocols/present_proof/v1_0/manager.py index b4640a6c53..c44f0aa1a0 100644 --- a/aries_cloudagent/protocols/present_proof/v1_0/manager.py +++ b/aries_cloudagent/protocols/present_proof/v1_0/manager.py @@ -4,7 +4,7 @@ import logging from ....config.injection_context import InjectionContext -from ....error import BaseError +from ....core.error import BaseError from ....holder.base import BaseHolder from ....ledger.base import BaseLedger from ....messaging.decorators.attach_decorator import AttachDecorator diff --git a/aries_cloudagent/protocols/presentations/manager.py b/aries_cloudagent/protocols/presentations/manager.py index 8583678c9f..84fd75d332 100644 --- a/aries_cloudagent/protocols/presentations/manager.py +++ b/aries_cloudagent/protocols/presentations/manager.py @@ -5,7 +5,7 @@ from uuid import uuid4 from ...config.injection_context import InjectionContext -from ...error import BaseError +from ...core.error import BaseError from ...holder.base import BaseHolder from ...ledger.base import BaseLedger from ...verifier.base import BaseVerifier diff --git a/aries_cloudagent/protocols/routing/manager.py b/aries_cloudagent/protocols/routing/manager.py index 996ba83d86..81c45c0f20 100644 --- a/aries_cloudagent/protocols/routing/manager.py +++ b/aries_cloudagent/protocols/routing/manager.py @@ -4,7 +4,7 @@ from typing import Sequence from ...config.injection_context import InjectionContext -from ...error import BaseError +from ...core.error import BaseError from ...messaging.util import time_now from ...storage.base import BaseStorage, StorageRecord from ...storage.error import StorageError, StorageDuplicateError, StorageNotFoundError diff --git a/aries_cloudagent/storage/error.py b/aries_cloudagent/storage/error.py index 9cc3b85a98..3d6e062533 100644 --- a/aries_cloudagent/storage/error.py +++ b/aries_cloudagent/storage/error.py @@ -1,6 +1,6 @@ """Storage-related exceptions.""" -from ..error import BaseError +from ..core.error import BaseError class StorageError(BaseError): diff --git a/aries_cloudagent/storage/provider.py b/aries_cloudagent/storage/provider.py index 839f2a19b1..65746421f5 100644 --- a/aries_cloudagent/storage/provider.py +++ b/aries_cloudagent/storage/provider.py @@ -2,8 +2,8 @@ import logging -from ..classloader import ClassLoader from ..config.base import BaseProvider, BaseInjector, BaseSettings +from ..utils.classloader import ClassLoader from ..wallet.base import BaseWallet LOGGER = logging.getLogger(__name__) diff --git a/aries_cloudagent/transport/error.py b/aries_cloudagent/transport/error.py index 6615c1bf87..fa955149cb 100644 --- a/aries_cloudagent/transport/error.py +++ b/aries_cloudagent/transport/error.py @@ -1,6 +1,6 @@ """Transport-related error classes and codes.""" -from ..error import BaseError +from ..core.error import BaseError class TransportError(BaseError): diff --git a/aries_cloudagent/transport/inbound/manager.py b/aries_cloudagent/transport/inbound/manager.py index ce32bc8968..55ca3dd9ed 100644 --- a/aries_cloudagent/transport/inbound/manager.py +++ b/aries_cloudagent/transport/inbound/manager.py @@ -7,8 +7,8 @@ from typing import Callable, Coroutine from ...config.injection_context import InjectionContext -from ...classloader import ClassLoader, ModuleLoadError, ClassNotFoundError from ...messaging.task_queue import CompletedTask, TaskQueue +from ...utils.classloader import ClassLoader, ModuleLoadError, ClassNotFoundError from ..outbound.message import OutboundMessage from ..wire_format import BaseWireFormat diff --git a/aries_cloudagent/transport/outbound/base.py b/aries_cloudagent/transport/outbound/base.py index 30258d0cdb..48ec111389 100644 --- a/aries_cloudagent/transport/outbound/base.py +++ b/aries_cloudagent/transport/outbound/base.py @@ -4,7 +4,7 @@ from abc import ABC, abstractmethod from typing import Union -from ...stats import Collector +from ...utils.stats import Collector from ..error import TransportError from ..wire_format import BaseWireFormat diff --git a/aries_cloudagent/transport/outbound/manager.py b/aries_cloudagent/transport/outbound/manager.py index d92181add6..8f1a8b77e2 100644 --- a/aries_cloudagent/transport/outbound/manager.py +++ b/aries_cloudagent/transport/outbound/manager.py @@ -8,11 +8,11 @@ from typing import Callable, Type, Union from urllib.parse import urlparse -from ...classloader import ClassLoader, ModuleLoadError, ClassNotFoundError from ...connections.models.connection_target import ConnectionTarget from ...config.injection_context import InjectionContext from ...messaging.task_queue import CompletedTask, TaskQueue, task_exc_info -from ...stats import Collector +from ...utils.classloader import ClassLoader, ModuleLoadError, ClassNotFoundError +from ...utils.stats import Collector from ..wire_format import BaseWireFormat diff --git a/aries_cloudagent/transport/outbound/tests/test_http_transport.py b/aries_cloudagent/transport/outbound/tests/test_http_transport.py index 43d4bb44f9..20d72d60f1 100644 --- a/aries_cloudagent/transport/outbound/tests/test_http_transport.py +++ b/aries_cloudagent/transport/outbound/tests/test_http_transport.py @@ -3,7 +3,7 @@ from aiohttp.test_utils import AioHTTPTestCase, unittest_run_loop from aiohttp import web -from ....stats import Collector +from ....utils.stats import Collector from ...outbound.message import OutboundMessage diff --git a/aries_cloudagent/transport/stats.py b/aries_cloudagent/transport/stats.py index 06943e101e..836de49a09 100644 --- a/aries_cloudagent/transport/stats.py +++ b/aries_cloudagent/transport/stats.py @@ -2,7 +2,7 @@ import aiohttp -from ..stats import Collector +from ..utils.stats import Collector class StatsTracer(aiohttp.TraceConfig): diff --git a/aries_cloudagent/utils/__init__.py b/aries_cloudagent/utils/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/aries_cloudagent/classloader.py b/aries_cloudagent/utils/classloader.py similarity index 99% rename from aries_cloudagent/classloader.py rename to aries_cloudagent/utils/classloader.py index fcd02b0c0f..6dc0a8b8fe 100644 --- a/aries_cloudagent/classloader.py +++ b/aries_cloudagent/utils/classloader.py @@ -9,7 +9,7 @@ from types import ModuleType from typing import Sequence, Type -from .error import BaseError +from ..core.error import BaseError class ModuleLoadError(BaseError): diff --git a/aries_cloudagent/stats.py b/aries_cloudagent/utils/stats.py similarity index 100% rename from aries_cloudagent/stats.py rename to aries_cloudagent/utils/stats.py diff --git a/aries_cloudagent/utils/tests/__init__.py b/aries_cloudagent/utils/tests/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/aries_cloudagent/tests/test_classloader.py b/aries_cloudagent/utils/tests/test_classloader.py similarity index 83% rename from aries_cloudagent/tests/test_classloader.py rename to aries_cloudagent/utils/tests/test_classloader.py index 8d468f01d4..b83b0d6755 100644 --- a/aries_cloudagent/tests/test_classloader.py +++ b/aries_cloudagent/utils/tests/test_classloader.py @@ -1,8 +1,9 @@ from unittest import TestCase, mock -from .. import classloader +from ...core.error import BaseError + +from .. import classloader as test_module from ..classloader import ClassLoader, ClassNotFoundError, ModuleLoadError -from ..error import BaseError class TestClassLoader(TestCase): @@ -10,24 +11,24 @@ def test_import_loaded(self): assert ClassLoader.load_module("unittest") def test_import_local(self): - with mock.patch.object(classloader.sys, "modules", {}): + with mock.patch.object(test_module.sys, "modules", {}): assert ( ClassLoader.load_module("aries_cloudagent.transport").__name__ == "aries_cloudagent.transport" ) def test_import_relative(self): - with mock.patch.object(classloader.sys, "modules", {}): + with mock.patch.object(test_module.sys, "modules", {}): assert ( ClassLoader.load_module("transport", "aries_cloudagent").__name__ == "aries_cloudagent.transport" ) - with mock.patch.object(classloader.sys, "modules", {}): + with mock.patch.object(test_module.sys, "modules", {}): assert ( ClassLoader.load_module(".transport", "aries_cloudagent").__name__ == "aries_cloudagent.transport" ) - with mock.patch.object(classloader.sys, "modules", {}): + with mock.patch.object(test_module.sys, "modules", {}): assert ( ClassLoader.load_module( "..transport", "aries_cloudagent.config" @@ -36,17 +37,17 @@ def test_import_relative(self): ) def test_import_missing(self): - with mock.patch.object(classloader.sys, "modules", {}): + with mock.patch.object(test_module.sys, "modules", {}): assert ClassLoader.load_module("aries_cloudagent.not") is None - with mock.patch.object(classloader.sys, "modules", {}): + with mock.patch.object(test_module.sys, "modules", {}): assert ClassLoader.load_module("aries_cloudagent.not.a-module") is None - with mock.patch.object(classloader.sys, "modules", {}): + with mock.patch.object(test_module.sys, "modules", {}): assert ClassLoader.load_module("aries_cloudagent", "not.a-module") is None def test_import_error(self): with mock.patch.object( - classloader, "import_module", autospec=True - ) as import_module, mock.patch.object(classloader.sys, "modules", {}): + test_module, "import_module", autospec=True + ) as import_module, mock.patch.object(test_module.sys, "modules", {}): import_module.side_effect = ModuleNotFoundError with self.assertRaises(ModuleLoadError): ClassLoader.load_module("aries_cloudagent.config") diff --git a/aries_cloudagent/tests/test_stats.py b/aries_cloudagent/utils/tests/test_stats.py similarity index 100% rename from aries_cloudagent/tests/test_stats.py rename to aries_cloudagent/utils/tests/test_stats.py diff --git a/aries_cloudagent/wallet/error.py b/aries_cloudagent/wallet/error.py index fdd995ad05..4359c9ff81 100644 --- a/aries_cloudagent/wallet/error.py +++ b/aries_cloudagent/wallet/error.py @@ -1,6 +1,6 @@ """Wallet-related exceptions.""" -from ..error import BaseError +from ..core.error import BaseError class WalletError(BaseError): diff --git a/aries_cloudagent/wallet/provider.py b/aries_cloudagent/wallet/provider.py index 529e459426..65ce49ba88 100644 --- a/aries_cloudagent/wallet/provider.py +++ b/aries_cloudagent/wallet/provider.py @@ -2,8 +2,8 @@ import logging -from ..classloader import ClassLoader from ..config.base import BaseProvider, BaseInjector, BaseSettings +from ..utils.classloader import ClassLoader LOGGER = logging.getLogger(__name__) From 43aa9d521d4bd3444ee9b61fab90b8eff450169a Mon Sep 17 00:00:00 2001 From: Andrew Whitehead Date: Tue, 10 Dec 2019 12:30:52 -0800 Subject: [PATCH 2/3] move additional modules out of messaging package Signed-off-by: Andrew Whitehead --- aries_cloudagent/admin/server.py | 4 ++-- aries_cloudagent/admin/tests/test_admin_server.py | 4 ++-- aries_cloudagent/config/default_context.py | 4 ++-- aries_cloudagent/config/tests/test_default_context.py | 2 +- aries_cloudagent/core/conductor.py | 2 +- aries_cloudagent/core/dispatcher.py | 4 ++-- aries_cloudagent/{messaging => core}/plugin_registry.py | 3 ++- aries_cloudagent/{messaging => core}/protocol_registry.py | 0 aries_cloudagent/core/tests/test_conductor.py | 2 +- aries_cloudagent/core/tests/test_dispatcher.py | 5 +++-- .../{messaging => core}/tests/test_plugin_registry.py | 0 .../{messaging => core}/tests/test_protocol_registry.py | 2 +- .../protocols/discovery/handlers/query_handler.py | 2 +- .../protocols/discovery/handlers/tests/test_query_handler.py | 2 +- aries_cloudagent/protocols/discovery/routes.py | 2 +- aries_cloudagent/transport/inbound/manager.py | 2 +- aries_cloudagent/transport/outbound/manager.py | 2 +- aries_cloudagent/transport/pack_format.py | 2 +- aries_cloudagent/{messaging => utils}/task_queue.py | 0 .../{messaging => utils}/tests/test_task_queue.py | 0 20 files changed, 23 insertions(+), 21 deletions(-) rename aries_cloudagent/{messaging => core}/plugin_registry.py (98%) rename aries_cloudagent/{messaging => core}/protocol_registry.py (100%) rename aries_cloudagent/{messaging => core}/tests/test_plugin_registry.py (100%) rename aries_cloudagent/{messaging => core}/tests/test_protocol_registry.py (98%) rename aries_cloudagent/{messaging => utils}/task_queue.py (100%) rename aries_cloudagent/{messaging => utils}/tests/test_task_queue.py (100%) diff --git a/aries_cloudagent/admin/server.py b/aries_cloudagent/admin/server.py index b7bb58d1c2..3580eb37c5 100644 --- a/aries_cloudagent/admin/server.py +++ b/aries_cloudagent/admin/server.py @@ -12,12 +12,12 @@ from marshmallow import fields, Schema from ..config.injection_context import InjectionContext -from ..messaging.plugin_registry import PluginRegistry +from ..core.plugin_registry import PluginRegistry from ..messaging.responder import BaseResponder -from ..messaging.task_queue import TaskQueue from ..transport.queue.basic import BasicMessageQueue from ..transport.outbound.message import OutboundMessage from ..utils.stats import Collector +from ..utils.task_queue import TaskQueue from ..version import __version__ from .base_server import BaseAdminServer diff --git a/aries_cloudagent/admin/tests/test_admin_server.py b/aries_cloudagent/admin/tests/test_admin_server.py index 02eef8b950..981e6dfacd 100644 --- a/aries_cloudagent/admin/tests/test_admin_server.py +++ b/aries_cloudagent/admin/tests/test_admin_server.py @@ -8,8 +8,8 @@ from ...config.default_context import DefaultContextBuilder from ...config.injection_context import InjectionContext from ...config.provider import ClassProvider -from ...messaging.plugin_registry import PluginRegistry -from ...messaging.protocol_registry import ProtocolRegistry +from ...core.plugin_registry import PluginRegistry +from ...core.protocol_registry import ProtocolRegistry from ...transport.outbound.message import OutboundMessage from ..server import AdminServer diff --git a/aries_cloudagent/config/default_context.py b/aries_cloudagent/config/default_context.py index a4b1f54757..743a26a5c2 100644 --- a/aries_cloudagent/config/default_context.py +++ b/aries_cloudagent/config/default_context.py @@ -6,13 +6,13 @@ from ..cache.base import BaseCache from ..cache.basic import BasicCache +from ..core.plugin_registry import PluginRegistry +from ..core.protocol_registry import ProtocolRegistry from ..ledger.base import BaseLedger from ..ledger.provider import LedgerProvider from ..issuer.base import BaseIssuer from ..holder.base import BaseHolder from ..verifier.base import BaseVerifier -from ..messaging.plugin_registry import PluginRegistry -from ..messaging.protocol_registry import ProtocolRegistry from ..protocols.actionmenu.base_service import BaseMenuService from ..protocols.actionmenu.driver_service import DriverMenuService from ..protocols.introduction.base_service import BaseIntroductionService diff --git a/aries_cloudagent/config/tests/test_default_context.py b/aries_cloudagent/config/tests/test_default_context.py index 2f7932df7d..dae1867311 100644 --- a/aries_cloudagent/config/tests/test_default_context.py +++ b/aries_cloudagent/config/tests/test_default_context.py @@ -1,6 +1,6 @@ from asynctest import TestCase as AsyncTestCase -from ...messaging.protocol_registry import ProtocolRegistry +from ...core.protocol_registry import ProtocolRegistry from ...storage.base import BaseStorage from ...transport.wire_format import BaseWireFormat from ...wallet.base import BaseWallet diff --git a/aries_cloudagent/core/conductor.py b/aries_cloudagent/core/conductor.py index 396d2b7047..6e8bc6bc06 100644 --- a/aries_cloudagent/core/conductor.py +++ b/aries_cloudagent/core/conductor.py @@ -19,7 +19,6 @@ from ..config.logging import LoggingConfigurator from ..config.wallet import wallet_config from ..messaging.responder import BaseResponder -from ..messaging.task_queue import CompletedTask, TaskQueue from ..protocols.connections.manager import ConnectionManager, ConnectionManagerError from ..transport.inbound.manager import InboundTransportManager from ..transport.inbound.message import InboundMessage @@ -27,6 +26,7 @@ from ..transport.outbound.manager import OutboundTransportManager from ..transport.outbound.message import OutboundMessage from ..transport.wire_format import BaseWireFormat +from ..utils.task_queue import CompletedTask, TaskQueue from ..utils.stats import Collector from .dispatcher import Dispatcher diff --git a/aries_cloudagent/core/dispatcher.py b/aries_cloudagent/core/dispatcher.py index 15b519d9fd..be6cceb248 100644 --- a/aries_cloudagent/core/dispatcher.py +++ b/aries_cloudagent/core/dispatcher.py @@ -13,19 +13,19 @@ from aiohttp.web import HTTPException from ..config.injection_context import InjectionContext +from ..core.protocol_registry import ProtocolRegistry from ..messaging.agent_message import AgentMessage from ..messaging.error import MessageParseError from ..messaging.models.base import BaseModelError -from ..messaging.protocol_registry import ProtocolRegistry from ..messaging.request_context import RequestContext from ..messaging.responder import BaseResponder -from ..messaging.task_queue import CompletedTask, PendingTask, TaskQueue from ..messaging.util import datetime_now from ..protocols.connections.manager import ConnectionManager from ..protocols.problem_report.message import ProblemReport from ..transport.inbound.message import InboundMessage from ..transport.outbound.message import OutboundMessage from ..utils.stats import Collector +from ..utils.task_queue import CompletedTask, PendingTask, TaskQueue LOGGER = logging.getLogger(__name__) diff --git a/aries_cloudagent/messaging/plugin_registry.py b/aries_cloudagent/core/plugin_registry.py similarity index 98% rename from aries_cloudagent/messaging/plugin_registry.py rename to aries_cloudagent/core/plugin_registry.py index f6ebefd1f5..fe4f5b40f2 100644 --- a/aries_cloudagent/messaging/plugin_registry.py +++ b/aries_cloudagent/core/plugin_registry.py @@ -6,9 +6,10 @@ from typing import Sequence from ..config.injection_context import InjectionContext -from ..messaging.protocol_registry import ProtocolRegistry from ..utils.classloader import ClassLoader, ModuleLoadError +from .protocol_registry import ProtocolRegistry + LOGGER = logging.getLogger(__name__) diff --git a/aries_cloudagent/messaging/protocol_registry.py b/aries_cloudagent/core/protocol_registry.py similarity index 100% rename from aries_cloudagent/messaging/protocol_registry.py rename to aries_cloudagent/core/protocol_registry.py diff --git a/aries_cloudagent/core/tests/test_conductor.py b/aries_cloudagent/core/tests/test_conductor.py index f1996bd083..1c395c05fd 100644 --- a/aries_cloudagent/core/tests/test_conductor.py +++ b/aries_cloudagent/core/tests/test_conductor.py @@ -15,7 +15,7 @@ PublicKeyType, Service, ) -from ...messaging.protocol_registry import ProtocolRegistry +from ...core.protocol_registry import ProtocolRegistry from ...protocols.connections.manager import ConnectionManager from ...storage.base import BaseStorage from ...storage.basic import BasicStorage diff --git a/aries_cloudagent/core/tests/test_dispatcher.py b/aries_cloudagent/core/tests/test_dispatcher.py index dc2be57b3d..7bd492d25f 100644 --- a/aries_cloudagent/core/tests/test_dispatcher.py +++ b/aries_cloudagent/core/tests/test_dispatcher.py @@ -3,17 +3,18 @@ from asynctest import TestCase as AsyncTestCase, mock as async_mock -from .. import dispatcher as test_module from ...config.injection_context import InjectionContext from ...connections.models.connection_record import ConnectionRecord +from ...core.protocol_registry import ProtocolRegistry from ...messaging.agent_message import AgentMessage, AgentMessageSchema from ...messaging.error import MessageParseError -from ...messaging.protocol_registry import ProtocolRegistry from ...protocols.problem_report.message import ProblemReport from ...transport.inbound.message import InboundMessage from ...transport.inbound.receipt import MessageReceipt from ...transport.outbound.message import OutboundMessage +from .. import dispatcher as test_module + def make_context() -> InjectionContext: context = InjectionContext() diff --git a/aries_cloudagent/messaging/tests/test_plugin_registry.py b/aries_cloudagent/core/tests/test_plugin_registry.py similarity index 100% rename from aries_cloudagent/messaging/tests/test_plugin_registry.py rename to aries_cloudagent/core/tests/test_plugin_registry.py diff --git a/aries_cloudagent/messaging/tests/test_protocol_registry.py b/aries_cloudagent/core/tests/test_protocol_registry.py similarity index 98% rename from aries_cloudagent/messaging/tests/test_protocol_registry.py rename to aries_cloudagent/core/tests/test_protocol_registry.py index d7fe0c530a..119bf775b6 100644 --- a/aries_cloudagent/messaging/tests/test_protocol_registry.py +++ b/aries_cloudagent/core/tests/test_protocol_registry.py @@ -1,8 +1,8 @@ from asynctest import TestCase as AsyncTestCase, mock as async_mock from ...config.injection_context import InjectionContext +from ...messaging.error import MessageParseError -from ..error import MessageParseError from ..protocol_registry import ProtocolRegistry diff --git a/aries_cloudagent/protocols/discovery/handlers/query_handler.py b/aries_cloudagent/protocols/discovery/handlers/query_handler.py index 6372ccf800..5e48f79c09 100644 --- a/aries_cloudagent/protocols/discovery/handlers/query_handler.py +++ b/aries_cloudagent/protocols/discovery/handlers/query_handler.py @@ -1,7 +1,7 @@ """Handler for incoming query messages.""" +from ....core.protocol_registry import ProtocolRegistry from ....messaging.base_handler import BaseHandler, BaseResponder, RequestContext -from ....messaging.protocol_registry import ProtocolRegistry from ..messages.disclose import Disclose from ..messages.query import Query diff --git a/aries_cloudagent/protocols/discovery/handlers/tests/test_query_handler.py b/aries_cloudagent/protocols/discovery/handlers/tests/test_query_handler.py index 618eb08bea..6ee7fddb6c 100644 --- a/aries_cloudagent/protocols/discovery/handlers/tests/test_query_handler.py +++ b/aries_cloudagent/protocols/discovery/handlers/tests/test_query_handler.py @@ -1,7 +1,7 @@ import pytest +from .....core.protocol_registry import ProtocolRegistry from .....messaging.base_handler import HandlerException -from .....messaging.protocol_registry import ProtocolRegistry from .....messaging.request_context import RequestContext from .....messaging.responder import MockResponder diff --git a/aries_cloudagent/protocols/discovery/routes.py b/aries_cloudagent/protocols/discovery/routes.py index 4daabb0790..055d5343d6 100644 --- a/aries_cloudagent/protocols/discovery/routes.py +++ b/aries_cloudagent/protocols/discovery/routes.py @@ -5,7 +5,7 @@ from marshmallow import fields, Schema -from ...messaging.protocol_registry import ProtocolRegistry +from ...core.protocol_registry import ProtocolRegistry class QueryResultSchema(Schema): diff --git a/aries_cloudagent/transport/inbound/manager.py b/aries_cloudagent/transport/inbound/manager.py index 55ca3dd9ed..82e03d02e9 100644 --- a/aries_cloudagent/transport/inbound/manager.py +++ b/aries_cloudagent/transport/inbound/manager.py @@ -7,8 +7,8 @@ from typing import Callable, Coroutine from ...config.injection_context import InjectionContext -from ...messaging.task_queue import CompletedTask, TaskQueue from ...utils.classloader import ClassLoader, ModuleLoadError, ClassNotFoundError +from ...utils.task_queue import CompletedTask, TaskQueue from ..outbound.message import OutboundMessage from ..wire_format import BaseWireFormat diff --git a/aries_cloudagent/transport/outbound/manager.py b/aries_cloudagent/transport/outbound/manager.py index 8f1a8b77e2..df049a3173 100644 --- a/aries_cloudagent/transport/outbound/manager.py +++ b/aries_cloudagent/transport/outbound/manager.py @@ -10,9 +10,9 @@ from ...connections.models.connection_target import ConnectionTarget from ...config.injection_context import InjectionContext -from ...messaging.task_queue import CompletedTask, TaskQueue, task_exc_info from ...utils.classloader import ClassLoader, ModuleLoadError, ClassNotFoundError from ...utils.stats import Collector +from ...utils.task_queue import CompletedTask, TaskQueue, task_exc_info from ..wire_format import BaseWireFormat diff --git a/aries_cloudagent/transport/pack_format.py b/aries_cloudagent/transport/pack_format.py index 20e79bf16a..75ba6b04bd 100644 --- a/aries_cloudagent/transport/pack_format.py +++ b/aries_cloudagent/transport/pack_format.py @@ -7,8 +7,8 @@ from ..config.base import InjectorError from ..config.injection_context import InjectionContext from ..protocols.routing.messages.forward import Forward -from ..messaging.task_queue import TaskQueue from ..messaging.util import time_now +from ..utils.task_queue import TaskQueue from ..wallet.base import BaseWallet from ..wallet.error import WalletError diff --git a/aries_cloudagent/messaging/task_queue.py b/aries_cloudagent/utils/task_queue.py similarity index 100% rename from aries_cloudagent/messaging/task_queue.py rename to aries_cloudagent/utils/task_queue.py diff --git a/aries_cloudagent/messaging/tests/test_task_queue.py b/aries_cloudagent/utils/tests/test_task_queue.py similarity index 100% rename from aries_cloudagent/messaging/tests/test_task_queue.py rename to aries_cloudagent/utils/tests/test_task_queue.py From aee7525c034286b202e217f6d0c1d5c674d0def4 Mon Sep 17 00:00:00 2001 From: Andrew Whitehead Date: Tue, 10 Dec 2019 12:55:57 -0800 Subject: [PATCH 3/3] move additional modules into utils package Signed-off-by: Andrew Whitehead --- aries_cloudagent/config/ledger.py | 6 +++--- .../{transport/util.py => utils/http.py} | 12 ++++++------ aries_cloudagent/{messaging => utils}/repeat.py | 0 .../tests/test_util.py => utils/tests/test_http.py} | 12 ++++++------ .../{messaging => utils}/tests/test_repeat.py | 0 5 files changed, 15 insertions(+), 15 deletions(-) rename aries_cloudagent/{transport/util.py => utils/http.py} (87%) rename aries_cloudagent/{messaging => utils}/repeat.py (100%) rename aries_cloudagent/{transport/tests/test_util.py => utils/tests/test_http.py} (82%) rename aries_cloudagent/{messaging => utils}/tests/test_repeat.py (100%) diff --git a/aries_cloudagent/config/ledger.py b/aries_cloudagent/config/ledger.py index d747941378..021a8f51aa 100644 --- a/aries_cloudagent/config/ledger.py +++ b/aries_cloudagent/config/ledger.py @@ -11,7 +11,7 @@ from prompt_toolkit.formatted_text import HTML from ..ledger.base import BaseLedger -from ..transport.util import http_fetch, TransportFetchError +from ..utils.http import fetch, FetchError from .base import ConfigError from .injection_context import InjectionContext @@ -25,8 +25,8 @@ async def fetch_genesis_transactions(genesis_url: str) -> str: headers["Content-Type"] = "application/json" LOGGER.info("Fetching genesis transactions from: %s", genesis_url) try: - return await http_fetch(genesis_url, headers=headers) - except TransportFetchError as e: + return await fetch(genesis_url, headers=headers) + except FetchError as e: raise ConfigError("Error retrieving ledger genesis transactions") from e diff --git a/aries_cloudagent/transport/util.py b/aries_cloudagent/utils/http.py similarity index 87% rename from aries_cloudagent/transport/util.py rename to aries_cloudagent/utils/http.py index 1a89ba7d02..a32b17c17a 100644 --- a/aries_cloudagent/transport/util.py +++ b/aries_cloudagent/utils/http.py @@ -1,19 +1,19 @@ -"""Transport utility methods.""" +"""HTTP utility methods.""" import asyncio from aiohttp import BaseConnector, ClientError, ClientResponse, ClientSession -from ..messaging.repeat import RepeatSequence +from ..core.error import BaseError -from .error import TransportError +from .repeat import RepeatSequence -class TransportFetchError(TransportError): +class FetchError(BaseError): """Error raised when an HTTP fetch fails.""" -async def http_fetch( +async def fetch( url: str, *, headers: dict = None, @@ -56,4 +56,4 @@ async def http_fetch( return await (response.json() if json else response.text()) except (ClientError, asyncio.TimeoutError) as e: if attempt.final: - raise TransportFetchError("Exceeded maximum fetch attempts") from e + raise FetchError("Exceeded maximum fetch attempts") from e diff --git a/aries_cloudagent/messaging/repeat.py b/aries_cloudagent/utils/repeat.py similarity index 100% rename from aries_cloudagent/messaging/repeat.py rename to aries_cloudagent/utils/repeat.py diff --git a/aries_cloudagent/transport/tests/test_util.py b/aries_cloudagent/utils/tests/test_http.py similarity index 82% rename from aries_cloudagent/transport/tests/test_util.py rename to aries_cloudagent/utils/tests/test_http.py index 7d7557fdec..a9b486fb5d 100644 --- a/aries_cloudagent/transport/tests/test_util.py +++ b/aries_cloudagent/utils/tests/test_http.py @@ -1,7 +1,7 @@ from aiohttp import web from aiohttp.test_utils import AioHTTPTestCase, unittest_run_loop -from ..util import http_fetch, TransportFetchError +from ..http import fetch, FetchError class TestTransportUtils(AioHTTPTestCase): @@ -26,19 +26,19 @@ async def succeed_route(self, request): return ret @unittest_run_loop - async def test_http_fetch(self): + async def test_fetch(self): server_addr = f"http://localhost:{self.server.port}" - result = await http_fetch( + result = await fetch( f"{server_addr}/succeed", session=self.client.session, json=True ) assert result == [1] assert self.succeed_calls == 1 @unittest_run_loop - async def test_http_fetch_fail(self): + async def test_fetch_fail(self): server_addr = f"http://localhost:{self.server.port}" - with self.assertRaises(TransportFetchError): - result = await http_fetch( + with self.assertRaises(FetchError): + result = await fetch( f"{server_addr}/fail", max_attempts=2, interval=0, diff --git a/aries_cloudagent/messaging/tests/test_repeat.py b/aries_cloudagent/utils/tests/test_repeat.py similarity index 100% rename from aries_cloudagent/messaging/tests/test_repeat.py rename to aries_cloudagent/utils/tests/test_repeat.py