From c1fe8c611ce0e5080a5bdecc598439f32552c145 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Sun, 14 Mar 2021 16:57:20 +0100 Subject: [PATCH] Added comments to application --- src/cpl/application/application_abc.py | 30 +++++++++++++++++-- src/cpl/application/application_host.py | 9 ++---- src/cpl/application/application_host_abc.py | 18 +++++++---- src/cpl/application/application_runtime.py | 4 +++ .../application/application_runtime_abc.py | 14 +++++++-- src/cpl/application/startup_abc.py | 27 ++++++++++++++--- 6 files changed, 82 insertions(+), 20 deletions(-) diff --git a/src/cpl/application/application_abc.py b/src/cpl/application/application_abc.py index 1ad5425f..d5f83021 100644 --- a/src/cpl/application/application_abc.py +++ b/src/cpl/application/application_abc.py @@ -12,6 +12,9 @@ class ApplicationABC(ABC): @abstractmethod def __init__(self): + """ + ABC of application + """ self._startup: Optional[StartupABC] = None self._app_host: Optional[ApplicationHostABC] = None self._configuration: Optional[ConfigurationABC] = None @@ -19,9 +22,18 @@ class ApplicationABC(ABC): self._services: Optional[ServiceProviderABC] = None def use_startup(self, startup: Type[StartupABC]): + """ + Sets the used startup class + :param startup: + :return: + """ self._startup = startup() def build(self): + """ + Creates application host and runtime + :return: + """ if self._startup is not None: self._app_host = self._startup.create_application_host() self._runtime = self._app_host.application_runtime @@ -29,11 +41,25 @@ class ApplicationABC(ABC): self._services = self._startup.create_services() def run(self): + """ + Entry point + :return: + """ self.configure() self.main() @abstractmethod - def configure(self): pass + def configure(self): + """ + Prepare the application + :return: + """ + pass @abstractmethod - def main(self): pass + def main(self): + """ + Custom entry point + :return: + """ + pass diff --git a/src/cpl/application/application_host.py b/src/cpl/application/application_host.py index 35bb3e1e..de82f893 100644 --- a/src/cpl/application/application_host.py +++ b/src/cpl/application/application_host.py @@ -1,4 +1,3 @@ -import atexit from collections import Callable from cpl.application.application_host_abc import ApplicationHostABC @@ -6,7 +5,6 @@ from cpl.application.application_runtime import ApplicationRuntime from cpl.application.application_runtime_abc import ApplicationRuntimeABC from cpl.configuration.configuration import Configuration from cpl.configuration.configuration_abc import ConfigurationABC -from cpl.console.console import Console from cpl.dependency_injection.service_provider import ServiceProvider from cpl.dependency_injection.service_provider_abc import ServiceProviderABC @@ -14,6 +12,9 @@ from cpl.dependency_injection.service_provider_abc import ServiceProviderABC class ApplicationHost(ApplicationHostABC): def __init__(self): + """ + Representation of application host + """ ApplicationHostABC.__init__(self) # Init @@ -33,9 +34,5 @@ class ApplicationHost(ApplicationHostABC): def services(self) -> ServiceProviderABC: return self._services - @staticmethod - def output_at_exit(): - atexit.register(Console.close) - def console_argument_error_function(self, function: Callable): self._config.argument_error_function = function diff --git a/src/cpl/application/application_host_abc.py b/src/cpl/application/application_host_abc.py index c7ef097b..6f3b73b4 100644 --- a/src/cpl/application/application_host_abc.py +++ b/src/cpl/application/application_host_abc.py @@ -9,7 +9,11 @@ from cpl.dependency_injection.service_provider_abc import ServiceProviderABC class ApplicationHostABC(ABC): @abstractmethod - def __init__(self): pass + def __init__(self): + """ + ABC for application host + """ + pass @property @abstractmethod @@ -23,9 +27,11 @@ class ApplicationHostABC(ABC): @abstractmethod def services(self) -> ServiceProviderABC: pass - @staticmethod @abstractmethod - def output_at_exit(): pass - - @abstractmethod - def console_argument_error_function(self, function: Callable): pass + def console_argument_error_function(self, function: Callable): + """ + Defines function to call when a argument error is detected + :param function: + :return: + """ + pass diff --git a/src/cpl/application/application_runtime.py b/src/cpl/application/application_runtime.py index 4325b4ec..84a805d8 100644 --- a/src/cpl/application/application_runtime.py +++ b/src/cpl/application/application_runtime.py @@ -8,6 +8,10 @@ from cpl.configuration.configuration_abc import ConfigurationABC class ApplicationRuntime(ApplicationRuntimeABC): def __init__(self, config: ConfigurationABC): + """ + Representation of the application runtime + :param config: + """ ApplicationRuntimeABC.__init__(self) self._app_configuration = config diff --git a/src/cpl/application/application_runtime_abc.py b/src/cpl/application/application_runtime_abc.py index 8581fb51..1064881b 100644 --- a/src/cpl/application/application_runtime_abc.py +++ b/src/cpl/application/application_runtime_abc.py @@ -7,7 +7,11 @@ from cpl.configuration.configuration_abc import ConfigurationABC class ApplicationRuntimeABC(ABC): @abstractmethod - def __init__(self): pass + def __init__(self): + """ + ABC for application runtime + """ + pass @property @abstractmethod @@ -42,4 +46,10 @@ class ApplicationRuntimeABC(ABC): def runtime_directory(self) -> str: pass @abstractmethod - def set_runtime_directory(self, runtime_directory: str): pass + def set_runtime_directory(self, runtime_directory: str): + """ + Sets the current runtime directory + :param runtime_directory: + :return: + """ + pass diff --git a/src/cpl/application/startup_abc.py b/src/cpl/application/startup_abc.py index 923d680a..3768edb8 100644 --- a/src/cpl/application/startup_abc.py +++ b/src/cpl/application/startup_abc.py @@ -8,13 +8,32 @@ from cpl.dependency_injection.service_provider_abc import ServiceProviderABC class StartupABC(ABC): @abstractmethod - def __init__(self): pass + def __init__(self): + """ + ABC for a startup class + """ + pass @abstractmethod - def create_application_host(self) -> ApplicationHostABC: pass + def create_application_host(self) -> ApplicationHostABC: + """ + Creates application host with specific attributes + :return: application host + """ + pass @abstractmethod - def create_configuration(self) -> ConfigurationABC: pass + def create_configuration(self) -> ConfigurationABC: + """ + Creates configuration of application + :return: configuration + """ + pass @abstractmethod - def create_services(self) -> ServiceProviderABC: pass + def create_services(self) -> ServiceProviderABC: + """ + Creates service provider + :return: service provider + """ + pass