From f3be92744076c249c5c2163c17e76271a63a0f60 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 29 Mar 2021 13:29:26 +0200 Subject: [PATCH] Removed service abc --- src/cpl/dependency_injection/__init__.py | 1 - src/cpl/dependency_injection/service_abc.py | 11 ----------- src/cpl/dependency_injection/service_provider_abc.py | 6 ++---- src/cpl/logging/logger_abc.py | 8 +++----- src/cpl/mailing/email_client_abc.py | 7 +++---- src/cpl_cli/command_abc.py | 8 +++----- src/cpl_cli/command_handler_service.py | 6 +++--- src/cpl_cli/live_server/live_server_service.py | 6 +++--- src/cpl_cli/publish/publisher_abc.py | 8 +++----- src/tests/custom/general/test_service.py | 8 +++++--- 10 files changed, 25 insertions(+), 44 deletions(-) delete mode 100644 src/cpl/dependency_injection/service_abc.py diff --git a/src/cpl/dependency_injection/__init__.py b/src/cpl/dependency_injection/__init__.py index 73436d6e..c94105ba 100644 --- a/src/cpl/dependency_injection/__init__.py +++ b/src/cpl/dependency_injection/__init__.py @@ -20,7 +20,6 @@ __version__ = '2021.4.2.dev1' from collections import namedtuple # imports: -from .service_abc import ServiceABC from .service_collection import ServiceCollection from .service_collection_abc import ServiceCollectionABC from .service_descriptor import ServiceDescriptor diff --git a/src/cpl/dependency_injection/service_abc.py b/src/cpl/dependency_injection/service_abc.py deleted file mode 100644 index a0da1277..00000000 --- a/src/cpl/dependency_injection/service_abc.py +++ /dev/null @@ -1,11 +0,0 @@ -from abc import ABC, abstractmethod - - -class ServiceABC(ABC): - - @abstractmethod - def __init__(self): - """ - ABC to represent a service - """ - pass diff --git a/src/cpl/dependency_injection/service_provider_abc.py b/src/cpl/dependency_injection/service_provider_abc.py index 3e86a0e1..042b0355 100644 --- a/src/cpl/dependency_injection/service_provider_abc.py +++ b/src/cpl/dependency_injection/service_provider_abc.py @@ -1,8 +1,6 @@ from abc import abstractmethod, ABC from collections import Callable -from typing import Type - -from cpl.dependency_injection.service_abc import ServiceABC +from typing import Type, Optional class ServiceProviderABC(ABC): @@ -24,7 +22,7 @@ class ServiceProviderABC(ABC): pass @abstractmethod - def get_service(self, instance_type: Type) -> Callable[ServiceABC]: + def get_service(self, instance_type: Type) -> Optional[Callable[object]]: """ Returns instance of given type :param instance_type: diff --git a/src/cpl/logging/logger_abc.py b/src/cpl/logging/logger_abc.py index 77d28522..98ef4eb9 100644 --- a/src/cpl/logging/logger_abc.py +++ b/src/cpl/logging/logger_abc.py @@ -1,16 +1,14 @@ -from abc import abstractmethod - -from cpl.dependency_injection.service_abc import ServiceABC +from abc import abstractmethod, ABC -class LoggerABC(ServiceABC): +class LoggerABC(ABC): @abstractmethod def __init__(self): """ ABC for logging """ - ServiceABC.__init__(self) + ABC.__init__(self) @abstractmethod def header(self, string: str): diff --git a/src/cpl/mailing/email_client_abc.py b/src/cpl/mailing/email_client_abc.py index 59041782..29690394 100644 --- a/src/cpl/mailing/email_client_abc.py +++ b/src/cpl/mailing/email_client_abc.py @@ -1,17 +1,16 @@ -from abc import abstractmethod +from abc import abstractmethod, ABC -from cpl.dependency_injection.service_abc import ServiceABC from cpl.mailing.email import EMail -class EMailClientABC(ServiceABC): +class EMailClientABC(ABC): @abstractmethod def __init__(self): """ ABC to send emails """ - ServiceABC.__init__(self) + ABC.__init__(self) @abstractmethod def connect(self): diff --git a/src/cpl_cli/command_abc.py b/src/cpl_cli/command_abc.py index 99a7e571..6ac6376f 100644 --- a/src/cpl_cli/command_abc.py +++ b/src/cpl_cli/command_abc.py @@ -1,13 +1,11 @@ -from abc import abstractmethod - -from cpl.dependency_injection.service_abc import ServiceABC +from abc import abstractmethod, ABC -class CommandABC(ServiceABC): +class CommandABC(ABC): @abstractmethod def __init__(self): - ServiceABC.__init__(self) + ABC.__init__(self) @abstractmethod def run(self, args: list[str]): pass diff --git a/src/cpl_cli/command_handler_service.py b/src/cpl_cli/command_handler_service.py index 7b8b4f2d..75bcdced 100644 --- a/src/cpl_cli/command_handler_service.py +++ b/src/cpl_cli/command_handler_service.py @@ -1,14 +1,14 @@ import os +from abc import ABC from cpl.configuration.configuration_abc import ConfigurationABC from cpl.console.console import Console -from cpl.dependency_injection.service_abc import ServiceABC from cpl.dependency_injection.service_provider_abc import ServiceProviderABC from cpl_cli.error import Error from cpl_cli.command_model import CommandModel -class CommandHandler(ServiceABC): +class CommandHandler(ABC): def __init__(self, config: ConfigurationABC, services: ServiceProviderABC): """ @@ -16,7 +16,7 @@ class CommandHandler(ServiceABC): :param config: :param services: """ - ServiceABC.__init__(self) + ABC.__init__(self) self._config = config self._env = self._config.environment diff --git a/src/cpl_cli/live_server/live_server_service.py b/src/cpl_cli/live_server/live_server_service.py index c556f20b..defd24b8 100644 --- a/src/cpl_cli/live_server/live_server_service.py +++ b/src/cpl_cli/live_server/live_server_service.py @@ -1,5 +1,6 @@ import os import time +from abc import ABC from contextlib import suppress import psutil as psutil @@ -7,13 +8,12 @@ from watchdog.events import FileSystemEventHandler from watchdog.observers import Observer from cpl.console.console import Console -from cpl.dependency_injection.service_abc import ServiceABC from cpl.environment.application_environment_abc import ApplicationEnvironmentABC from cpl_cli.configuration.build_settings import BuildSettings from cpl_cli.live_server.live_server_thread import LiveServerThread -class LiveServerService(ServiceABC, FileSystemEventHandler): +class LiveServerService(ABC, FileSystemEventHandler): def __init__(self, env: ApplicationEnvironmentABC, build_settings: BuildSettings): """ @@ -21,7 +21,7 @@ class LiveServerService(ServiceABC, FileSystemEventHandler): :param env: :param build_settings: """ - ServiceABC.__init__(self) + ABC.__init__(self) FileSystemEventHandler.__init__(self) self._env = env diff --git a/src/cpl_cli/publish/publisher_abc.py b/src/cpl_cli/publish/publisher_abc.py index 48aaaaa1..c33ed644 100644 --- a/src/cpl_cli/publish/publisher_abc.py +++ b/src/cpl_cli/publish/publisher_abc.py @@ -1,13 +1,11 @@ -from abc import abstractmethod - -from cpl.dependency_injection.service_abc import ServiceABC +from abc import abstractmethod, ABC -class PublisherABC(ServiceABC): +class PublisherABC(ABC): @abstractmethod def __init__(self): - ServiceABC.__init__(self) + ABC.__init__(self) @property @abstractmethod diff --git a/src/tests/custom/general/test_service.py b/src/tests/custom/general/test_service.py index c96dfb74..376707c1 100644 --- a/src/tests/custom/general/test_service.py +++ b/src/tests/custom/general/test_service.py @@ -1,11 +1,13 @@ +from abc import ABC + from cpl.console.console import Console -from cpl.dependency_injection import ServiceABC, ServiceProviderABC +from cpl.dependency_injection import ServiceProviderABC -class TestService(ServiceABC): +class TestService(ABC): def __init__(self, provider: ServiceProviderABC): - ServiceABC.__init__(self) + ABC.__init__(self) self._provider = provider