diff --git a/cpl.json b/cpl.json index f583d98e..47f341ef 100644 --- a/cpl.json +++ b/cpl.json @@ -4,7 +4,7 @@ "Version": { "Major": "2021", "Minor": "04", - "Micro": "01-13" + "Micro": "01-14" }, "Author": "Sven Heidemann", "AuthorEmail": "sven.heidemann@sh-edraft.de", diff --git a/src/cpl/__init__.py b/src/cpl/__init__.py index 83842fe9..c75a9ae7 100644 --- a/src/cpl/__init__.py +++ b/src/cpl/__init__.py @@ -15,11 +15,11 @@ __title__ = 'sh_cpl.cpl' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl/application/__init__.py b/src/cpl/application/__init__.py index dbe60779..cbfc2460 100644 --- a/src/cpl/application/__init__.py +++ b/src/cpl/application/__init__.py @@ -15,17 +15,17 @@ __title__ = 'cpl.application' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple # imports: from .application_abc import ApplicationABC -from .application_host import ApplicationHost -from .application_host_abc import ApplicationHostABC +from .application_builder import ApplicationBuilder +from .application_builder_abc import ApplicationBuilderABC from .application_runtime import ApplicationRuntime from .application_runtime_abc import ApplicationRuntimeABC from .startup_abc import StartupABC VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl/application/application_abc.py b/src/cpl/application/application_abc.py index d5f83021..66be8c74 100644 --- a/src/cpl/application/application_abc.py +++ b/src/cpl/application/application_abc.py @@ -1,52 +1,33 @@ from abc import ABC, abstractmethod -from typing import Type, Optional +from typing import Optional -from cpl.application.application_host_abc import ApplicationHostABC from cpl.application.application_runtime_abc import ApplicationRuntimeABC -from cpl.application.startup_abc import StartupABC from cpl.configuration.configuration_abc import ConfigurationABC +from cpl.console.console import Console from cpl.dependency_injection.service_provider_abc import ServiceProviderABC class ApplicationABC(ABC): @abstractmethod - def __init__(self): + def __init__(self, config: ConfigurationABC, runtime: ApplicationRuntimeABC, services: ServiceProviderABC): """ ABC of application """ - self._startup: Optional[StartupABC] = None - self._app_host: Optional[ApplicationHostABC] = None - self._configuration: Optional[ConfigurationABC] = None - self._runtime: Optional[ApplicationRuntimeABC] = None - 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 - self._configuration = self._startup.create_configuration() - self._services = self._startup.create_services() + self._configuration: Optional[ConfigurationABC] = config + self._runtime: Optional[ApplicationRuntimeABC] = runtime + self._services: Optional[ServiceProviderABC] = services def run(self): """ Entry point :return: """ - self.configure() - self.main() + try: + self.configure() + self.main() + except KeyboardInterrupt: + Console.close() @abstractmethod def configure(self): diff --git a/src/cpl/application/application_builder.py b/src/cpl/application/application_builder.py new file mode 100644 index 00000000..7aebf781 --- /dev/null +++ b/src/cpl/application/application_builder.py @@ -0,0 +1,41 @@ +from typing import Type, Optional + +from cpl.application.application_abc import ApplicationABC +from cpl.application.application_builder_abc import ApplicationBuilderABC +from cpl.application.application_runtime import ApplicationRuntime +from cpl.application.startup_abc import StartupABC +from cpl.configuration import Configuration +from cpl.dependency_injection import ServiceProvider + + +class ApplicationBuilder(ApplicationBuilderABC): + + def __init__(self, app: Type[ApplicationABC]): + """ + Builder class for application + """ + ApplicationBuilderABC.__init__(self, app) + self._startup: Optional[StartupABC] = None + + self._configuration = Configuration() + self._runtime = ApplicationRuntime() + self._services = ServiceProvider(self._configuration, self._runtime) + + def use_startup(self, startup: Type[StartupABC]): + """ + Sets the used startup class + :param startup: + :return: + """ + self._startup = startup(self._configuration, self._runtime, self._services) + + def build(self) -> ApplicationABC: + """ + Creates application host and runtime + :return: + """ + if self._startup is not None: + self._startup.configure_configuration() + self._startup.configure_services() + + return self._app(self._configuration, self._runtime, self._services) diff --git a/src/cpl/application/application_builder_abc.py b/src/cpl/application/application_builder_abc.py new file mode 100644 index 00000000..bbaa4638 --- /dev/null +++ b/src/cpl/application/application_builder_abc.py @@ -0,0 +1,31 @@ +from abc import ABC, abstractmethod +from typing import Type + +from cpl.application.application_abc import ApplicationABC +from cpl.application.startup_abc import StartupABC + + +class ApplicationBuilderABC(ABC): + + def __init__(self, app: Type[ApplicationABC]): + """ + ABC of application builder + """ + self._app = app + + @abstractmethod + def use_startup(self, startup: Type[StartupABC]): + """ + Sets the used startup class + :param startup: + :return: + """ + pass + + @abstractmethod + def build(self) -> ApplicationABC: + """ + Creates application host and runtime + :return: + """ + pass diff --git a/src/cpl/application/application_host.py b/src/cpl/application/application_host.py deleted file mode 100644 index de82f893..00000000 --- a/src/cpl/application/application_host.py +++ /dev/null @@ -1,38 +0,0 @@ -from collections import Callable - -from cpl.application.application_host_abc import ApplicationHostABC -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.dependency_injection.service_provider import ServiceProvider -from cpl.dependency_injection.service_provider_abc import ServiceProviderABC - - -class ApplicationHost(ApplicationHostABC): - - def __init__(self): - """ - Representation of application host - """ - ApplicationHostABC.__init__(self) - - # Init - self._config = Configuration() - self._app_runtime = ApplicationRuntime(self._config) - self._services = ServiceProvider(self._app_runtime) - - @property - def configuration(self) -> ConfigurationABC: - return self._config - - @property - def application_runtime(self) -> ApplicationRuntimeABC: - return self._app_runtime - - @property - def services(self) -> ServiceProviderABC: - return self._services - - 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 deleted file mode 100644 index 6f3b73b4..00000000 --- a/src/cpl/application/application_host_abc.py +++ /dev/null @@ -1,37 +0,0 @@ -from abc import ABC, abstractmethod -from collections import Callable - -from cpl.application.application_runtime_abc import ApplicationRuntimeABC -from cpl.configuration.configuration_abc import ConfigurationABC -from cpl.dependency_injection.service_provider_abc import ServiceProviderABC - - -class ApplicationHostABC(ABC): - - @abstractmethod - def __init__(self): - """ - ABC for application host - """ - pass - - @property - @abstractmethod - def configuration(self) -> ConfigurationABC: pass - - @property - @abstractmethod - def application_runtime(self) -> ApplicationRuntimeABC: pass - - @property - @abstractmethod - def services(self) -> ServiceProviderABC: pass - - @abstractmethod - 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 84a805d8..3403574c 100644 --- a/src/cpl/application/application_runtime.py +++ b/src/cpl/application/application_runtime.py @@ -2,28 +2,21 @@ import pathlib from datetime import datetime from cpl.application.application_runtime_abc import ApplicationRuntimeABC -from cpl.configuration.configuration_abc import ConfigurationABC class ApplicationRuntime(ApplicationRuntimeABC): - def __init__(self, config: ConfigurationABC): + def __init__(self): """ Representation of the application runtime - :param config: """ ApplicationRuntimeABC.__init__(self) - self._app_configuration = config self._start_time: datetime = datetime.now() self._end_time: datetime = datetime.now() self._working_directory = pathlib.Path().absolute() self._runtime_directory = pathlib.Path(__file__).parent.absolute() - @property - def configuration(self) -> ConfigurationABC: - return self._app_configuration - @property def start_time(self) -> datetime: return self._start_time diff --git a/src/cpl/application/application_runtime_abc.py b/src/cpl/application/application_runtime_abc.py index 1064881b..55716954 100644 --- a/src/cpl/application/application_runtime_abc.py +++ b/src/cpl/application/application_runtime_abc.py @@ -1,8 +1,6 @@ from abc import ABC, abstractmethod from datetime import datetime -from cpl.configuration.configuration_abc import ConfigurationABC - class ApplicationRuntimeABC(ABC): @@ -13,10 +11,6 @@ class ApplicationRuntimeABC(ABC): """ pass - @property - @abstractmethod - def configuration(self) -> ConfigurationABC: pass - @property @abstractmethod def start_time(self) -> datetime: pass diff --git a/src/cpl/application/startup_abc.py b/src/cpl/application/startup_abc.py index 3768edb8..c8599f1c 100644 --- a/src/cpl/application/startup_abc.py +++ b/src/cpl/application/startup_abc.py @@ -1,6 +1,6 @@ from abc import ABC, abstractmethod -from cpl.application.application_host_abc import ApplicationHostABC +from cpl.application.application_runtime_abc import ApplicationRuntimeABC from cpl.configuration.configuration_abc import ConfigurationABC from cpl.dependency_injection.service_provider_abc import ServiceProviderABC @@ -8,22 +8,17 @@ from cpl.dependency_injection.service_provider_abc import ServiceProviderABC class StartupABC(ABC): @abstractmethod - def __init__(self): + def __init__(self, config: ConfigurationABC, runtime: ApplicationRuntimeABC, services: ServiceProviderABC): """ ABC for a startup class """ - pass + + self._configuration = config + self._application_runtime = runtime + self._services = services @abstractmethod - def create_application_host(self) -> ApplicationHostABC: - """ - Creates application host with specific attributes - :return: application host - """ - pass - - @abstractmethod - def create_configuration(self) -> ConfigurationABC: + def configure_configuration(self) -> ConfigurationABC: """ Creates configuration of application :return: configuration @@ -31,7 +26,7 @@ class StartupABC(ABC): pass @abstractmethod - def create_services(self) -> ServiceProviderABC: + def configure_services(self) -> ServiceProviderABC: """ Creates service provider :return: service provider diff --git a/src/cpl/configuration/__init__.py b/src/cpl/configuration/__init__.py index b25a4cec..0982f97c 100644 --- a/src/cpl/configuration/__init__.py +++ b/src/cpl/configuration/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl.configuration' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple @@ -27,4 +27,4 @@ from .configuration_variable_name_enum import ConfigurationVariableNameEnum from .console_argument import ConsoleArgument VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl/console/__init__.py b/src/cpl/console/__init__.py index 4348f868..cc231edf 100644 --- a/src/cpl/console/__init__.py +++ b/src/cpl/console/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl.console' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple @@ -27,4 +27,4 @@ from .foreground_color_enum import ForegroundColorEnum from .spinner_thread import SpinnerThread VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl/console/console.py b/src/cpl/console/console.py index 62764b53..b7945a92 100644 --- a/src/cpl/console/console.py +++ b/src/cpl/console/console.py @@ -432,7 +432,7 @@ class Console: return_value = call(*args, **kwargs) except KeyboardInterrupt: spinner.exit() - exit() + cls.close() spinner.stop_spinning() cls.set_hold_back(False) diff --git a/src/cpl/database/__init__.py b/src/cpl/database/__init__.py index 0f261562..2d932618 100644 --- a/src/cpl/database/__init__.py +++ b/src/cpl/database/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl.database' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple @@ -25,4 +25,4 @@ from .database_settings import DatabaseSettings from .database_settings_name_enum import DatabaseSettingsNameEnum VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl/database/connection/__init__.py b/src/cpl/database/connection/__init__.py index b2d15ec6..e902a32c 100644 --- a/src/cpl/database/connection/__init__.py +++ b/src/cpl/database/connection/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl.database.connection' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple @@ -24,4 +24,4 @@ from .database_connection import DatabaseConnection from .database_connection_abc import DatabaseConnectionABC VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl/database/context/__init__.py b/src/cpl/database/context/__init__.py index 19decd13..e3fc01fe 100644 --- a/src/cpl/database/context/__init__.py +++ b/src/cpl/database/context/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl.database.context' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple @@ -24,4 +24,4 @@ from .database_context import DatabaseContext from .database_context_abc import DatabaseContextABC VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl/dependency_injection/__init__.py b/src/cpl/dependency_injection/__init__.py index 794dfacc..6206ab22 100644 --- a/src/cpl/dependency_injection/__init__.py +++ b/src/cpl/dependency_injection/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl.dependency_injection' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple @@ -25,4 +25,4 @@ from .service_provider import ServiceProvider from .service_provider_abc import ServiceProviderABC VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl/dependency_injection/service_provider.py b/src/cpl/dependency_injection/service_provider.py index b9d1f2e2..0a657450 100644 --- a/src/cpl/dependency_injection/service_provider.py +++ b/src/cpl/dependency_injection/service_provider.py @@ -13,13 +13,14 @@ from cpl.environment.environment_abc import ApplicationEnvironmentABC class ServiceProvider(ServiceProviderABC): - def __init__(self, app_runtime: ApplicationRuntimeABC): + def __init__(self, config: ConfigurationABC, runtime: ApplicationRuntimeABC): """ Service for service providing - :param app_runtime: + :param runtime: """ ServiceProviderABC.__init__(self) - self._app_runtime: ApplicationRuntimeABC = app_runtime + self._configuration: ConfigurationABC = config + self._runtime: ApplicationRuntimeABC = runtime self._database_context: Optional[DatabaseContextABC] = None self._transient_services: dict[Type[ServiceABC], Callable[ServiceABC]] = {} @@ -38,19 +39,19 @@ class ServiceProvider(ServiceProviderABC): parameter = param[1] if parameter.name != 'self' and parameter.annotation != Parameter.empty: if issubclass(parameter.annotation, ApplicationRuntimeABC): - params.append(self._app_runtime) + params.append(self._runtime) elif issubclass(parameter.annotation, ApplicationEnvironmentABC): - params.append(self._app_runtime.configuration.environment) + params.append(self._configuration.environment) elif issubclass(parameter.annotation, DatabaseContextABC): params.append(self._database_context) elif issubclass(parameter.annotation, ConfigurationModelABC): - params.append(self._app_runtime.configuration.get_configuration(parameter.annotation)) + params.append(self._configuration.get_configuration(parameter.annotation)) elif issubclass(parameter.annotation, ConfigurationABC): - params.append(self._app_runtime.configuration) + params.append(self._configuration) elif issubclass(parameter.annotation, ServiceProviderABC): params.append(self) diff --git a/src/cpl/environment/__init__.py b/src/cpl/environment/__init__.py index 8cf4594c..0d33f2a8 100644 --- a/src/cpl/environment/__init__.py +++ b/src/cpl/environment/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl.environment' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple @@ -25,4 +25,4 @@ from .environment_name_enum import EnvironmentNameEnum from .application_environment import ApplicationEnvironment VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl/logging/__init__.py b/src/cpl/logging/__init__.py index 1aee0d28..7cb086c9 100644 --- a/src/cpl/logging/__init__.py +++ b/src/cpl/logging/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl.logging' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple @@ -27,4 +27,4 @@ from .logging_settings import LoggingSettings from .logging_settings_name_enum import LoggingSettingsNameEnum VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl/mailing/__init__.py b/src/cpl/mailing/__init__.py index 030cf13c..cc1397e3 100644 --- a/src/cpl/mailing/__init__.py +++ b/src/cpl/mailing/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl.mailing' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple @@ -27,4 +27,4 @@ from .email_client_settings import EMailClientSettings from .email_client_settings_name_enum import EMailClientSettingsNameEnum VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl/time/__init__.py b/src/cpl/time/__init__.py index 88740c08..a751a3e5 100644 --- a/src/cpl/time/__init__.py +++ b/src/cpl/time/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl.time' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple @@ -24,4 +24,4 @@ from .time_format_settings import TimeFormatSettings from .time_format_settings_names_enum import TimeFormatSettingsNamesEnum VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl/utils/__init__.py b/src/cpl/utils/__init__.py index dde1d36e..64bf29e6 100644 --- a/src/cpl/utils/__init__.py +++ b/src/cpl/utils/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl.utils' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple @@ -25,4 +25,4 @@ from .string import String from .pip import Pip VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl_cli/__init__.py b/src/cpl_cli/__init__.py index 1f068d33..a55c41da 100644 --- a/src/cpl_cli/__init__.py +++ b/src/cpl_cli/__init__.py @@ -15,7 +15,7 @@ __title__ = 'sh_cpl.cpl_cli' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple @@ -29,4 +29,4 @@ from .main import main from .startup import Startup VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl_cli/cli.py b/src/cpl_cli/cli.py index e1ed07f7..14f5a230 100644 --- a/src/cpl_cli/cli.py +++ b/src/cpl_cli/cli.py @@ -1,7 +1,10 @@ from typing import Optional from cpl.application.application_abc import ApplicationABC +from cpl.application.application_runtime_abc import ApplicationRuntimeABC +from cpl.configuration.configuration_abc import ConfigurationABC from cpl.console.console import Console +from cpl.dependency_injection import ServiceProviderABC from cpl_cli.command.build_service import BuildService from cpl_cli.command.generate_service import GenerateService from cpl_cli.command.install_service import InstallService @@ -19,11 +22,11 @@ from cpl_cli.command.version_service import VersionService class CLI(ApplicationABC): - def __init__(self): + def __init__(self, config: ConfigurationABC, runtime: ApplicationRuntimeABC, services: ServiceProviderABC): """ CPL CLI """ - ApplicationABC.__init__(self) + ApplicationABC.__init__(self, config, runtime, services) self._command_handler: Optional[CommandHandler] = None diff --git a/src/cpl_cli/command/__init__.py b/src/cpl_cli/command/__init__.py index d2bbdee7..abba08e8 100644 --- a/src/cpl_cli/command/__init__.py +++ b/src/cpl_cli/command/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_cli.command' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple @@ -28,4 +28,4 @@ from .publish_service import PublishService from .version_service import VersionService VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl_cli/configuration/__init__.py b/src/cpl_cli/configuration/__init__.py index bbb78b2c..09557508 100644 --- a/src/cpl_cli/configuration/__init__.py +++ b/src/cpl_cli/configuration/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_cli.configuration' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple @@ -28,4 +28,4 @@ from .version_settings import VersionSettings from .version_settings_name_enum import VersionSettingsNameEnum VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl_cli/live_server/__init__.py b/src/cpl_cli/live_server/__init__.py index 025c9bc3..40e6d497 100644 --- a/src/cpl_cli/live_server/__init__.py +++ b/src/cpl_cli/live_server/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli.live_server' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl_cli/main.py b/src/cpl_cli/main.py index 5be6a86d..71024452 100644 --- a/src/cpl_cli/main.py +++ b/src/cpl_cli/main.py @@ -1,12 +1,12 @@ +from cpl.application.application_builder import ApplicationBuilder from cpl_cli.cli import CLI from cpl_cli.startup import Startup def main(): - cli = CLI() - cli.use_startup(Startup) - cli.build() - cli.run() + app_builder = ApplicationBuilder(CLI) + app_builder.use_startup(Startup) + app_builder.build().run() if __name__ == '__main__': diff --git a/src/cpl_cli/publish/__init__.py b/src/cpl_cli/publish/__init__.py index cf4a3fb3..3e769af0 100644 --- a/src/cpl_cli/publish/__init__.py +++ b/src/cpl_cli/publish/__init__.py @@ -15,7 +15,7 @@ __title__ = 'cpl_cli.publish' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple @@ -24,4 +24,4 @@ from .publisher_abc import PublisherABC from .publisher_service import PublisherService VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl_cli/startup.py b/src/cpl_cli/startup.py index 627b24b3..1f7c41a9 100644 --- a/src/cpl_cli/startup.py +++ b/src/cpl_cli/startup.py @@ -1,7 +1,4 @@ -from typing import Optional - -from cpl.application.application_host import ApplicationHost -from cpl.application.application_host_abc import ApplicationHostABC +from cpl.application.application_runtime_abc import ApplicationRuntimeABC from cpl.application.startup_abc import StartupABC from cpl.configuration.console_argument import ConsoleArgument from cpl.configuration.configuration_abc import ConfigurationABC @@ -25,28 +22,17 @@ from cpl_cli.publish.publisher_abc import PublisherABC class Startup(StartupABC): - def __init__(self): - StartupABC.__init__(self) + def __init__(self, config: ConfigurationABC, runtime: ApplicationRuntimeABC, services: ServiceProviderABC): + StartupABC.__init__(self, config, runtime, services) - self._app_host: Optional[ApplicationHostABC] = None - self._configuration: Optional[ConfigurationABC] = None - self._services: Optional[ServiceProviderABC] = None + self._application_runtime.set_runtime_directory(__file__) - def create_application_host(self) -> ApplicationHostABC: - self._app_host = ApplicationHost() + def configure_configuration(self) -> ConfigurationABC: + self._configuration.argument_error_function = Error.error - self._app_host.application_runtime.set_runtime_directory(__file__) - self._app_host.console_argument_error_function(Error.error) - - self._configuration = self._app_host.configuration - self._services = self._app_host.services - - return self._app_host - - def create_configuration(self) -> ConfigurationABC: self._configuration.add_environment_variables('PYTHON_') self._configuration.add_environment_variables('CPL_') - self._configuration.add_json_file('appsettings.json', path=self._app_host.application_runtime.runtime_directory, + self._configuration.add_json_file('appsettings.json', path=self._application_runtime.runtime_directory, optional=False, output=False) self._configuration.add_console_argument(ConsoleArgument('', 'build', ['b', 'B'], '')) self._configuration.add_console_argument(ConsoleArgument('', 'generate', ['g', 'G'], '', console_arguments=[ @@ -73,7 +59,7 @@ class Startup(StartupABC): return self._configuration - def create_services(self) -> ServiceProviderABC: + def configure_services(self) -> ServiceProviderABC: self._services.add_singleton(CommandHandler) self._services.add_transient(PublisherABC, PublisherService) diff --git a/src/cpl_cli/templates/__init__.py b/src/cpl_cli/templates/__init__.py index 673fa0e1..f002695c 100644 --- a/src/cpl_cli/templates/__init__.py +++ b/src/cpl_cli/templates/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli.templates' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl_cli/templates/build/__init__.py b/src/cpl_cli/templates/build/__init__.py index 3a255a98..fb6c1dff 100644 --- a/src/cpl_cli/templates/build/__init__.py +++ b/src/cpl_cli/templates/build/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli.templates.build' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl_cli/templates/generate/__init__.py b/src/cpl_cli/templates/generate/__init__.py index 32471b64..6794365b 100644 --- a/src/cpl_cli/templates/generate/__init__.py +++ b/src/cpl_cli/templates/generate/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli.templates.generate' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl_cli/templates/new/__init__.py b/src/cpl_cli/templates/new/__init__.py index 4a0971e3..2617ec87 100644 --- a/src/cpl_cli/templates/new/__init__.py +++ b/src/cpl_cli/templates/new/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli.templates.new' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl_cli/templates/new/console/__init__.py b/src/cpl_cli/templates/new/console/__init__.py index 04df2f73..0ca97acf 100644 --- a/src/cpl_cli/templates/new/console/__init__.py +++ b/src/cpl_cli/templates/new/console/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli.templates.new.console' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl_cli/templates/new/console/src/__init__.py b/src/cpl_cli/templates/new/console/src/__init__.py index 23610c47..e7b4d344 100644 --- a/src/cpl_cli/templates/new/console/src/__init__.py +++ b/src/cpl_cli/templates/new/console/src/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli.templates.new.console.src' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl_cli/templates/new/console/src/application.py b/src/cpl_cli/templates/new/console/src/application.py index 5126403e..d86c1c59 100644 --- a/src/cpl_cli/templates/new/console/src/application.py +++ b/src/cpl_cli/templates/new/console/src/application.py @@ -12,13 +12,16 @@ class ApplicationTemplate(TemplateFileABC): self._path = 'src/' self._value = textwrap.dedent("""\ from cpl.application.application_abc import ApplicationABC + from cpl.application.application_runtime_abc import ApplicationRuntimeABC + from cpl.configuration.configuration_abc import ConfigurationABC from cpl.console.console import Console - - + from cpl.dependency_injection.service_provider_abc import ServiceProviderABC + + class Application(ApplicationABC): - def __init__(self): - ApplicationABC.__init__(self) + def __init__(self, config: ConfigurationABC, runtime: ApplicationRuntimeABC, services: ServiceProviderABC): + ApplicationABC.__init__(self, config, runtime, services) def configure(self): pass diff --git a/src/cpl_cli/templates/new/console/src/main.py b/src/cpl_cli/templates/new/console/src/main.py index 85a81d87..36902b91 100644 --- a/src/cpl_cli/templates/new/console/src/main.py +++ b/src/cpl_cli/templates/new/console/src/main.py @@ -11,15 +11,16 @@ class MainWithApplicationHostAndStartupTemplate(TemplateFileABC): self._name = 'main.py' self._path = 'src/' self._value = textwrap.dedent("""\ - from startup import Startup + from cpl.application.application_builder import ApplicationBuilder + from application import Application + from startup import Startup def main(): - app = Application() - app.use_startup(Startup) - app.build() - app.run() + app_builder = ApplicationBuilder(Application) + app_builder.use_startup(Startup) + app_builder.build().run() if __name__ == '__main__': @@ -47,13 +48,14 @@ class MainWithApplicationHostTemplate(TemplateFileABC): self._name = 'main.py' self._path = 'src/' self._value = textwrap.dedent("""\ + from cpl.application.application_builder import ApplicationBuilder + from application import Application def main(): - app = Application() - app.build() - app.run() + app_builder = ApplicationBuilder(Application) + app_builder.build().run() if __name__ == '__main__': diff --git a/src/cpl_cli/templates/new/console/src/startup.py b/src/cpl_cli/templates/new/console/src/startup.py index f7023854..ac8a282a 100644 --- a/src/cpl_cli/templates/new/console/src/startup.py +++ b/src/cpl_cli/templates/new/console/src/startup.py @@ -11,10 +11,7 @@ class StartupTemplate(TemplateFileABC): self._name = 'startup.py' self._path = 'src/' self._value = textwrap.dedent("""\ - from typing import Optional - - from cpl.application.application_host import ApplicationHost - from cpl.application.application_host_abc import ApplicationHostABC + from cpl.application.application_runtime_abc import ApplicationRuntimeABC from cpl.application.startup_abc import StartupABC from cpl.configuration.configuration_abc import ConfigurationABC from cpl.dependency_injection.service_provider_abc import ServiceProviderABC @@ -22,28 +19,15 @@ class StartupTemplate(TemplateFileABC): class Startup(StartupABC): - def __init__(self): - StartupABC.__init__(self) - - self._app_host: Optional[ApplicationHostABC] = None - self._configuration: Optional[ConfigurationABC] = None - self._services: Optional[ServiceProviderABC] = None - - def create_application_host(self) -> ApplicationHostABC: - self._app_host = ApplicationHost() - self._configuration = self._app_host.configuration - self._services = self._app_host.services - return self._app_host - - def create_configuration(self) -> ConfigurationABC: - pass + def __init__(self, config: ConfigurationABC, runtime: ApplicationRuntimeABC, services: ServiceProviderABC): + StartupABC.__init__(self, config, runtime, services) + def configure_configuration(self) -> ConfigurationABC: return self._configuration - def create_services(self) -> ServiceProviderABC: - pass - + def configure_services(self) -> ServiceProviderABC: return self._services + """) @property diff --git a/src/cpl_cli/templates/new/console/src/tests/__init__.py b/src/cpl_cli/templates/new/console/src/tests/__init__.py index 9825f4b8..77b287e6 100644 --- a/src/cpl_cli/templates/new/console/src/tests/__init__.py +++ b/src/cpl_cli/templates/new/console/src/tests/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli.templates.new.console.src.tests' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/cpl_cli/templates/publish/__init__.py b/src/cpl_cli/templates/publish/__init__.py index 54c5631a..e4bd3dc0 100644 --- a/src/cpl_cli/templates/publish/__init__.py +++ b/src/cpl_cli/templates/publish/__init__.py @@ -15,11 +15,11 @@ __title__ = 'cpl_cli.templates.publish' __author__ = 'Sven Heidemann' __license__ = 'MIT' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' -__version__ = '2021.4.1.post13' +__version__ = '2021.4.1.post14' from collections import namedtuple # imports: VersionInfo = namedtuple('VersionInfo', 'major minor micro') -version_info = VersionInfo(major='2021', minor='04', micro='01-13') +version_info = VersionInfo(major='2021', minor='04', micro='01-14') diff --git a/src/tests/custom/general/application.py b/src/tests/custom/general/application.py index 0620a1a2..d9d63caf 100644 --- a/src/tests/custom/general/application.py +++ b/src/tests/custom/general/application.py @@ -2,7 +2,10 @@ import time from typing import Optional from cpl.application.application_abc import ApplicationABC +from cpl.application.application_runtime_abc import ApplicationRuntimeABC +from cpl.configuration.configuration_abc import ConfigurationABC from cpl.console.console import Console +from cpl.dependency_injection.service_provider_abc import ServiceProviderABC from cpl.logging.logger_abc import LoggerABC from cpl.mailing.email import EMail from cpl.mailing.email_client_abc import EMailClientABC @@ -10,8 +13,8 @@ from cpl.mailing.email_client_abc import EMailClientABC class Application(ApplicationABC): - def __init__(self): - ApplicationABC.__init__(self) + def __init__(self, config: ConfigurationABC, runtime: ApplicationRuntimeABC, services: ServiceProviderABC): + ApplicationABC.__init__(self, config, runtime, services) self._logger: Optional[LoggerABC] = None self._mailer: Optional[EMailClientABC] = None diff --git a/src/tests/custom/general/main.py b/src/tests/custom/general/main.py index 142b759f..a9fd514f 100644 --- a/src/tests/custom/general/main.py +++ b/src/tests/custom/general/main.py @@ -1,12 +1,12 @@ +from cpl.application.application_builder import ApplicationBuilder from tests.custom.general.application import Application from tests.custom.general.startup import Startup def main(): - app = Application() - app.use_startup(Startup) - app.build() - app.run() + app_builder = ApplicationBuilder(Application) + app_builder.use_startup(Startup) + app_builder.build().run() if __name__ == '__main__': diff --git a/src/tests/custom/general/startup.py b/src/tests/custom/general/startup.py index f667cc4c..3c08c0a1 100644 --- a/src/tests/custom/general/startup.py +++ b/src/tests/custom/general/startup.py @@ -1,7 +1,4 @@ -from typing import Optional - -from cpl.application.application_host import ApplicationHost -from cpl.application.application_host_abc import ApplicationHostABC +from cpl.application.application_runtime_abc import ApplicationRuntimeABC from cpl.application.startup_abc import StartupABC from cpl.configuration.configuration_abc import ConfigurationABC from cpl.database.context.database_context import DatabaseContext @@ -16,20 +13,10 @@ from cpl.utils.credential_manager import CredentialManager class Startup(StartupABC): - def __init__(self): - StartupABC.__init__(self) + def __init__(self, config: ConfigurationABC, runtime: ApplicationRuntimeABC, services: ServiceProviderABC): + StartupABC.__init__(self, config, runtime, services) - self._app_host: Optional[ApplicationHostABC] = None - self._configuration: Optional[ConfigurationABC] = None - self._services: Optional[ServiceProviderABC] = None - - def create_application_host(self) -> ApplicationHostABC: - self._app_host = ApplicationHost() - self._configuration = self._app_host.configuration - self._services = self._app_host.services - return self._app_host - - def create_configuration(self) -> ConfigurationABC: + def configure_configuration(self) -> ConfigurationABC: self._configuration.add_environment_variables('PYTHON_') self._configuration.add_environment_variables('CPL_') self._configuration.add_console_arguments() @@ -39,7 +26,7 @@ class Startup(StartupABC): return self._configuration - def create_services(self) -> ServiceProviderABC: + def configure_services(self) -> ServiceProviderABC: # Create and connect to database db_settings: DatabaseSettings = self._configuration.get_configuration(DatabaseSettings) self._services.add_db_context(DatabaseContext)