From 7af7f866c150765f6045dec4d9779b270966e4c0 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Mon, 29 Mar 2021 08:56:18 +0200 Subject: [PATCH] Removed application runtime | Code refactoring p.2 --- src/cpl/application/__init__.py | 2 - src/cpl/application/application_abc.py | 6 +-- src/cpl/application/application_builder.py | 9 ++-- src/cpl/application/application_runtime.py | 52 ------------------- .../application/application_runtime_abc.py | 49 ----------------- .../service_collection.py | 6 +-- .../dependency_injection/service_provider.py | 8 +-- .../environment/application_environment.py | 41 +++++++++++++++ .../application_environment_abc.py | 38 ++++++++++++++ src/cpl/logging/logger_service.py | 10 ++-- src/cpl_cli/cli.py | 5 +- src/cpl_cli/command/install_service.py | 10 ++-- src/cpl_cli/command/new_service.py | 8 ++- src/cpl_cli/command/uninstall_service.py | 10 ++-- src/cpl_cli/command/update_service.py | 10 ++-- src/cpl_cli/command_handler_service.py | 9 ++-- .../live_server/live_server_service.py | 10 ++-- src/cpl_cli/publish/publisher_service.py | 12 ++--- src/cpl_cli/startup.py | 9 ++-- src/tests/custom/general/application.py | 5 +- src/tests/custom/general/startup.py | 4 +- 21 files changed, 136 insertions(+), 177 deletions(-) delete mode 100644 src/cpl/application/application_runtime.py delete mode 100644 src/cpl/application/application_runtime_abc.py diff --git a/src/cpl/application/__init__.py b/src/cpl/application/__init__.py index 028256d1..87eca6e5 100644 --- a/src/cpl/application/__init__.py +++ b/src/cpl/application/__init__.py @@ -23,8 +23,6 @@ from collections import namedtuple from .application_abc import ApplicationABC 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') diff --git a/src/cpl/application/application_abc.py b/src/cpl/application/application_abc.py index 66be8c74..4c0e07d8 100644 --- a/src/cpl/application/application_abc.py +++ b/src/cpl/application/application_abc.py @@ -1,21 +1,21 @@ from abc import ABC, abstractmethod from typing import Optional -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.environment import ApplicationEnvironmentABC class ApplicationABC(ABC): @abstractmethod - def __init__(self, config: ConfigurationABC, runtime: ApplicationRuntimeABC, services: ServiceProviderABC): + def __init__(self, config: ConfigurationABC, services: ServiceProviderABC): """ ABC of application """ self._configuration: Optional[ConfigurationABC] = config - self._runtime: Optional[ApplicationRuntimeABC] = runtime + self._environment: Optional[ApplicationEnvironmentABC] = self._configuration.environment self._services: Optional[ServiceProviderABC] = services def run(self): diff --git a/src/cpl/application/application_builder.py b/src/cpl/application/application_builder.py index b3e3f777..067bda82 100644 --- a/src/cpl/application/application_builder.py +++ b/src/cpl/application/application_builder.py @@ -2,7 +2,6 @@ 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.service_collection import ServiceCollection @@ -19,8 +18,8 @@ class ApplicationBuilder(ApplicationBuilderABC): self._startup: Optional[StartupABC] = None self._configuration = Configuration() - self._runtime = ApplicationRuntime() - self._services = ServiceCollection(self._configuration, self._runtime) + self._environment = self._configuration.environment + self._services = ServiceCollection(self._configuration) def use_startup(self, startup: Type[StartupABC]): """ @@ -28,7 +27,7 @@ class ApplicationBuilder(ApplicationBuilderABC): :param startup: :return: """ - self._startup = startup(self._configuration, self._runtime, self._services) + self._startup = startup(self._configuration, self._services) def build(self) -> ApplicationABC: """ @@ -39,4 +38,4 @@ class ApplicationBuilder(ApplicationBuilderABC): self._startup.configure_configuration() self._startup.configure_services() - return self._app(self._configuration, self._runtime, self._services.build_service_provider()) + return self._app(self._configuration, self._services.build_service_provider()) diff --git a/src/cpl/application/application_runtime.py b/src/cpl/application/application_runtime.py deleted file mode 100644 index 3403574c..00000000 --- a/src/cpl/application/application_runtime.py +++ /dev/null @@ -1,52 +0,0 @@ -import pathlib -from datetime import datetime - -from cpl.application.application_runtime_abc import ApplicationRuntimeABC - - -class ApplicationRuntime(ApplicationRuntimeABC): - - def __init__(self): - """ - Representation of the application runtime - """ - ApplicationRuntimeABC.__init__(self) - - 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 start_time(self) -> datetime: - return self._start_time - - @property - def end_time(self) -> datetime: - return self._end_time - - @end_time.setter - def end_time(self, end_time: datetime): - self._end_time = end_time - - @property - def date_time_now(self) -> datetime: - return datetime.now() - - @property - def working_directory(self) -> str: - return self._working_directory - - def set_working_directory(self, path: str = ''): - if path != '': - self._working_directory = path - return - - self._working_directory = pathlib.Path().absolute() - - @property - def runtime_directory(self) -> str: - return self._runtime_directory - - def set_runtime_directory(self, file: str): - self._runtime_directory = pathlib.Path(file).parent.absolute() diff --git a/src/cpl/application/application_runtime_abc.py b/src/cpl/application/application_runtime_abc.py deleted file mode 100644 index 55716954..00000000 --- a/src/cpl/application/application_runtime_abc.py +++ /dev/null @@ -1,49 +0,0 @@ -from abc import ABC, abstractmethod -from datetime import datetime - - -class ApplicationRuntimeABC(ABC): - - @abstractmethod - def __init__(self): - """ - ABC for application runtime - """ - pass - - @property - @abstractmethod - def start_time(self) -> datetime: pass - - @start_time.setter - @abstractmethod - def start_time(self, start_time: datetime): pass - - @property - @abstractmethod - def end_time(self): pass - - @end_time.setter - @abstractmethod - def end_time(self, end_time: datetime): pass - - @property - @abstractmethod - def date_time_now(self) -> datetime: pass - - @property - @abstractmethod - def working_directory(self) -> str: pass - - @property - @abstractmethod - def runtime_directory(self) -> str: pass - - @abstractmethod - def set_runtime_directory(self, runtime_directory: str): - """ - Sets the current runtime directory - :param runtime_directory: - :return: - """ - pass diff --git a/src/cpl/dependency_injection/service_collection.py b/src/cpl/dependency_injection/service_collection.py index 24fcd17b..d3bb4be1 100644 --- a/src/cpl/dependency_injection/service_collection.py +++ b/src/cpl/dependency_injection/service_collection.py @@ -1,6 +1,5 @@ from typing import Union, Type, Callable, Optional -from cpl.application.application_runtime_abc import ApplicationRuntimeABC from cpl.configuration.configuration_abc import ConfigurationABC from cpl.database.context import DatabaseContextABC from cpl.dependency_injection.service_provider_abc import ServiceProviderABC @@ -12,10 +11,9 @@ from cpl.dependency_injection.service_provider import ServiceProvider class ServiceCollection(ServiceCollectionABC): - def __init__(self, config: ConfigurationABC, runtime: ApplicationRuntimeABC): + def __init__(self, config: ConfigurationABC): ServiceCollectionABC.__init__(self) self._configuration: ConfigurationABC = config - self._runtime: ApplicationRuntimeABC = runtime self._database_context: Optional[DatabaseContextABC] = None self._service_descriptors: list[ServiceDescriptor] = [] @@ -63,4 +61,4 @@ class ServiceCollection(ServiceCollectionABC): self._add_descriptor(service_type, ServiceLifetimeEnum.transient) def build_service_provider(self) -> ServiceProviderABC: - return ServiceProvider(self._service_descriptors, self._configuration, self._runtime) + return ServiceProvider(self._service_descriptors, self._configuration) diff --git a/src/cpl/dependency_injection/service_provider.py b/src/cpl/dependency_injection/service_provider.py index 7f93477c..86d0b478 100644 --- a/src/cpl/dependency_injection/service_provider.py +++ b/src/cpl/dependency_injection/service_provider.py @@ -2,7 +2,6 @@ from collections import Callable from inspect import signature, Parameter from typing import Optional -from cpl.application.application_runtime_abc import ApplicationRuntimeABC from cpl.configuration.configuration_abc import ConfigurationABC from cpl.configuration.configuration_model_abc import ConfigurationModelABC from cpl.dependency_injection.service_provider_abc import ServiceProviderABC @@ -13,13 +12,11 @@ from cpl.environment.application_environment_abc import ApplicationEnvironmentAB class ServiceProvider(ServiceProviderABC): - def __init__(self, service_descriptors: list[ServiceDescriptor], config: ConfigurationABC, - runtime: ApplicationRuntimeABC): + def __init__(self, service_descriptors: list[ServiceDescriptor], config: ConfigurationABC): ServiceProviderABC.__init__(self) self._service_descriptors: list[ServiceDescriptor] = service_descriptors self._configuration: ConfigurationABC = config - self._runtime: ApplicationRuntimeABC = runtime def _find_service(self, service_type: type) -> [ServiceDescriptor]: for descriptor in self._service_descriptors: @@ -59,9 +56,6 @@ class ServiceProvider(ServiceProviderABC): if issubclass(parameter.annotation, ServiceProviderABC): params.append(self) - elif issubclass(parameter.annotation, ApplicationRuntimeABC): - params.append(self._runtime) - elif issubclass(parameter.annotation, ApplicationEnvironmentABC): params.append(self._configuration.environment) diff --git a/src/cpl/environment/application_environment.py b/src/cpl/environment/application_environment.py index 210f321b..7bb76f13 100644 --- a/src/cpl/environment/application_environment.py +++ b/src/cpl/environment/application_environment.py @@ -1,3 +1,5 @@ +import pathlib +from datetime import datetime from socket import gethostname from typing import Optional @@ -20,6 +22,11 @@ class ApplicationEnvironment(ApplicationEnvironmentABC): self._customer: Optional[str] = None self._content_root_path: Optional[str] = crp + 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 environment_name(self) -> str: return str(self._environment_name.value) @@ -55,3 +62,37 @@ class ApplicationEnvironment(ApplicationEnvironmentABC): @property def host_name(self): return gethostname() + + @property + def start_time(self) -> datetime: + return self._start_time + + @property + def end_time(self) -> datetime: + return self._end_time + + @end_time.setter + def end_time(self, end_time: datetime): + self._end_time = end_time + + @property + def date_time_now(self) -> datetime: + return datetime.now() + + @property + def working_directory(self) -> str: + return self._working_directory + + def set_working_directory(self, path: str = ''): + if path != '': + self._working_directory = path + return + + self._working_directory = pathlib.Path().absolute() + + @property + def runtime_directory(self) -> str: + return self._runtime_directory + + def set_runtime_directory(self, file: str): + self._runtime_directory = pathlib.Path(file).parent.absolute() diff --git a/src/cpl/environment/application_environment_abc.py b/src/cpl/environment/application_environment_abc.py index 861a4144..c306f53f 100644 --- a/src/cpl/environment/application_environment_abc.py +++ b/src/cpl/environment/application_environment_abc.py @@ -1,4 +1,5 @@ from abc import ABC, abstractmethod +from datetime import datetime class ApplicationEnvironmentABC(ABC): @@ -45,3 +46,40 @@ class ApplicationEnvironmentABC(ABC): @property @abstractmethod def host_name(self) -> str: pass + + @property + @abstractmethod + def start_time(self) -> datetime: pass + + @start_time.setter + @abstractmethod + def start_time(self, start_time: datetime): pass + + @property + @abstractmethod + def end_time(self): pass + + @end_time.setter + @abstractmethod + def end_time(self, end_time: datetime): pass + + @property + @abstractmethod + def date_time_now(self) -> datetime: pass + + @property + @abstractmethod + def working_directory(self) -> str: pass + + @property + @abstractmethod + def runtime_directory(self) -> str: pass + + @abstractmethod + def set_runtime_directory(self, runtime_directory: str): + """ + Sets the current runtime directory + :param runtime_directory: + :return: + """ + pass diff --git a/src/cpl/logging/logger_service.py b/src/cpl/logging/logger_service.py index 6390797c..4c04a5d2 100644 --- a/src/cpl/logging/logger_service.py +++ b/src/cpl/logging/logger_service.py @@ -3,9 +3,9 @@ import os import traceback from string import Template -from cpl.application.application_runtime_abc import ApplicationRuntimeABC from cpl.console.console import Console from cpl.console.foreground_color_enum import ForegroundColorEnum +from cpl.environment.application_environment_abc import ApplicationEnvironmentABC from cpl.logging.logger_abc import LoggerABC from cpl.logging.logging_level_enum import LoggingLevelEnum from cpl.logging.logging_settings import LoggingSettings @@ -14,7 +14,7 @@ from cpl.time.time_format_settings import TimeFormatSettings class Logger(LoggerABC): - def __init__(self, logging_settings: LoggingSettings, time_format: TimeFormatSettings, app_runtime: ApplicationRuntimeABC): + def __init__(self, logging_settings: LoggingSettings, time_format: TimeFormatSettings, env: ApplicationEnvironmentABC): """ Service for logging :param logging_settings: @@ -23,13 +23,13 @@ class Logger(LoggerABC): """ LoggerABC.__init__(self) - self._app_runtime = app_runtime + self._env = env self._log_settings: LoggingSettings = logging_settings self._time_format_settings: TimeFormatSettings = time_format self._log = Template(self._log_settings.filename).substitute( - date_time_now=self._app_runtime.date_time_now.strftime(self._time_format_settings.date_time_format), - start_time=self._app_runtime.start_time.strftime(self._time_format_settings.date_time_log_format) + date_time_now=self._env.date_time_now.strftime(self._time_format_settings.date_time_format), + start_time=self._env.start_time.strftime(self._time_format_settings.date_time_log_format) ) self._path = self._log_settings.path self._level = self._log_settings.level diff --git a/src/cpl_cli/cli.py b/src/cpl_cli/cli.py index 14f5a230..8547844e 100644 --- a/src/cpl_cli/cli.py +++ b/src/cpl_cli/cli.py @@ -1,7 +1,6 @@ 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 @@ -22,11 +21,11 @@ from cpl_cli.command.version_service import VersionService class CLI(ApplicationABC): - def __init__(self, config: ConfigurationABC, runtime: ApplicationRuntimeABC, services: ServiceProviderABC): + def __init__(self, config: ConfigurationABC, services: ServiceProviderABC): """ CPL CLI """ - ApplicationABC.__init__(self, config, runtime, services) + ApplicationABC.__init__(self, config, services) self._command_handler: Optional[CommandHandler] = None diff --git a/src/cpl_cli/command/install_service.py b/src/cpl_cli/command/install_service.py index bc392077..494bb823 100644 --- a/src/cpl_cli/command/install_service.py +++ b/src/cpl_cli/command/install_service.py @@ -4,9 +4,9 @@ import subprocess from packaging import version -from cpl.application.application_runtime_abc import ApplicationRuntimeABC from cpl.console.console import Console from cpl.console.foreground_color_enum import ForegroundColorEnum +from cpl.environment.application_environment_abc import ApplicationEnvironmentABC from cpl.utils.pip import Pip from cpl_cli.cli_settings import CLISettings from cpl_cli.command_abc import CommandABC @@ -18,18 +18,18 @@ from cpl_cli.error import Error class InstallService(CommandABC): - def __init__(self, runtime: ApplicationRuntimeABC, build_settings: BuildSettings, project_settings: ProjectSettings, + def __init__(self, env: ApplicationEnvironmentABC, build_settings: BuildSettings, project_settings: ProjectSettings, cli_settings: CLISettings): """ Service for the CLI command install - :param runtime: + :param env: :param build_settings: :param project_settings: :param cli_settings: """ CommandABC.__init__(self) - self._runtime = runtime + self._env = env self._build_settings = build_settings self._project_settings = project_settings self._cli_settings = cli_settings @@ -147,7 +147,7 @@ class InstallService(CommandABC): BuildSettings.__name__: SettingsHelper.get_build_settings_dict(self._build_settings) } - with open(os.path.join(self._runtime.working_directory, 'cpl.json'), 'w') as project_file: + with open(os.path.join(self._env.working_directory, 'cpl.json'), 'w') as project_file: project_file.write(json.dumps(config, indent=2)) project_file.close() diff --git a/src/cpl_cli/command/new_service.py b/src/cpl_cli/command/new_service.py index 2f46c390..565cc1c9 100644 --- a/src/cpl_cli/command/new_service.py +++ b/src/cpl_cli/command/new_service.py @@ -7,7 +7,6 @@ from packaging import version import cpl -from cpl.application.application_runtime_abc import ApplicationRuntimeABC from cpl.configuration.configuration_abc import ConfigurationABC from cpl.console.foreground_color_enum import ForegroundColorEnum from cpl.console.console import Console @@ -29,16 +28,15 @@ from cpl_cli.templates.template_file_abc import TemplateFileABC class NewService(CommandABC): - def __init__(self, configuration: ConfigurationABC, runtime: ApplicationRuntimeABC): + def __init__(self, configuration: ConfigurationABC): """ Service for the CLI command new :param configuration: - :param runtime: """ CommandABC.__init__(self) self._config = configuration - self._runtime = runtime + self._env = self._config.environment self._project: ProjectSettings = ProjectSettings() self._project_dict = {} @@ -128,7 +126,7 @@ class NewService(CommandABC): Gets project path :return: """ - project_path = os.path.join(self._runtime.working_directory, self._project.name) + project_path = os.path.join(self._env.working_directory, self._project.name) if os.path.isdir(project_path) and len(os.listdir(project_path)) > 0: Console.error('Project path is not empty\n') return None diff --git a/src/cpl_cli/command/uninstall_service.py b/src/cpl_cli/command/uninstall_service.py index cdd86de4..da7ea3ca 100644 --- a/src/cpl_cli/command/uninstall_service.py +++ b/src/cpl_cli/command/uninstall_service.py @@ -2,9 +2,9 @@ import json import os import subprocess -from cpl.application.application_runtime_abc import ApplicationRuntimeABC from cpl.console.console import Console from cpl.console.foreground_color_enum import ForegroundColorEnum +from cpl.environment.application_environment_abc import ApplicationEnvironmentABC from cpl.utils.pip import Pip from cpl_cli.command_abc import CommandABC from cpl_cli.configuration.build_settings import BuildSettings @@ -14,17 +14,17 @@ from cpl_cli.configuration.settings_helper import SettingsHelper class UninstallService(CommandABC): - def __init__(self, runtime: ApplicationRuntimeABC, build_settings: BuildSettings, + def __init__(self, env: ApplicationEnvironmentABC, build_settings: BuildSettings, project_settings: ProjectSettings): """ Service for the CLI command uninstall - :param runtime: + :param env: :param build_settings: :param project_settings: """ CommandABC.__init__(self) - self._runtime = runtime + self._env = env self._build_settings = build_settings self._project_settings = project_settings @@ -74,7 +74,7 @@ class UninstallService(CommandABC): ProjectSettings.__name__: SettingsHelper.get_project_settings_dict(self._project_settings), BuildSettings.__name__: SettingsHelper.get_build_settings_dict(self._build_settings) } - with open(os.path.join(self._runtime.working_directory, 'cpl.json'), 'w') as project_file: + with open(os.path.join(self._env.working_directory, 'cpl.json'), 'w') as project_file: project_file.write(json.dumps(config, indent=2)) project_file.close() diff --git a/src/cpl_cli/command/update_service.py b/src/cpl_cli/command/update_service.py index 0ff14d08..50951532 100644 --- a/src/cpl_cli/command/update_service.py +++ b/src/cpl_cli/command/update_service.py @@ -2,9 +2,9 @@ import json import os import subprocess -from cpl.application.application_runtime_abc import ApplicationRuntimeABC from cpl.console.console import Console from cpl.console.foreground_color_enum import ForegroundColorEnum +from cpl.environment.application_environment_abc import ApplicationEnvironmentABC from cpl.utils.pip import Pip from cpl_cli.cli_settings import CLISettings from cpl_cli.command_abc import CommandABC @@ -16,20 +16,20 @@ from cpl_cli.configuration.settings_helper import SettingsHelper class UpdateService(CommandABC): def __init__(self, - runtime: ApplicationRuntimeABC, + env: ApplicationEnvironmentABC, build_settings: BuildSettings, project_settings: ProjectSettings, cli_settings: CLISettings): """ Service for the CLI command update - :param runtime: + :param env: :param build_settings: :param project_settings: :param cli_settings: """ CommandABC.__init__(self) - self._runtime = runtime + self._env = env self._build_settings = build_settings self._project_settings = project_settings self._cli_settings = cli_settings @@ -117,7 +117,7 @@ class UpdateService(CommandABC): BuildSettings.__name__: SettingsHelper.get_build_settings_dict(self._build_settings) } - with open(os.path.join(self._runtime.working_directory, 'cpl.json'), 'w') as project: + with open(os.path.join(self._env.working_directory, 'cpl.json'), 'w') as project: project.write(json.dumps(config, indent=2)) project.close() diff --git a/src/cpl_cli/command_handler_service.py b/src/cpl_cli/command_handler_service.py index 63278ca7..7b8b4f2d 100644 --- a/src/cpl_cli/command_handler_service.py +++ b/src/cpl_cli/command_handler_service.py @@ -1,6 +1,5 @@ import os -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_abc import ServiceABC @@ -11,16 +10,16 @@ from cpl_cli.command_model import CommandModel class CommandHandler(ServiceABC): - def __init__(self, runtime: ApplicationRuntimeABC, config: ConfigurationABC, services: ServiceProviderABC): + def __init__(self, config: ConfigurationABC, services: ServiceProviderABC): """ Service to handle incoming commands and args - :param runtime: + :param config: :param services: """ ServiceABC.__init__(self) - self._runtime = runtime self._config = config + self._env = self._config.environment self._services = services self._commands: list[CommandModel] = [] @@ -44,7 +43,7 @@ class CommandHandler(ServiceABC): """ for command in self._commands: if cmd == command.name or cmd in command.aliases: - if command.is_project_needed and not os.path.isfile(os.path.join(self._runtime.working_directory, 'cpl.json')): + if command.is_project_needed and not os.path.isfile(os.path.join(self._env.working_directory, 'cpl.json')): Error.error('The command requires to be run in an CPL project, but a project could not be found.') return diff --git a/src/cpl_cli/live_server/live_server_service.py b/src/cpl_cli/live_server/live_server_service.py index 9e052805..c556f20b 100644 --- a/src/cpl_cli/live_server/live_server_service.py +++ b/src/cpl_cli/live_server/live_server_service.py @@ -6,28 +6,28 @@ import psutil as psutil from watchdog.events import FileSystemEventHandler from watchdog.observers import Observer -from cpl.application.application_runtime_abc import ApplicationRuntimeABC 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): - def __init__(self, runtime: ApplicationRuntimeABC, build_settings: BuildSettings): + def __init__(self, env: ApplicationEnvironmentABC, build_settings: BuildSettings): """ Service for the live development server - :param runtime: + :param env: :param build_settings: """ ServiceABC.__init__(self) FileSystemEventHandler.__init__(self) - self._runtime = runtime + self._env = env self._build_settings = build_settings - self._src_dir = os.path.join(self._runtime.working_directory, self._build_settings.source_path) + self._src_dir = os.path.join(self._env.working_directory, self._build_settings.source_path) self._ls_thread = None self._observer = None diff --git a/src/cpl_cli/publish/publisher_service.py b/src/cpl_cli/publish/publisher_service.py index 255cb054..964ab092 100644 --- a/src/cpl_cli/publish/publisher_service.py +++ b/src/cpl_cli/publish/publisher_service.py @@ -7,9 +7,9 @@ import setuptools from packaging import version from setuptools import sandbox -from cpl.application.application_runtime_abc import ApplicationRuntimeABC from cpl.console.foreground_color_enum import ForegroundColorEnum from cpl.console.console import Console +from cpl.environment.application_environment_abc import ApplicationEnvironmentABC from cpl_cli.configuration.build_settings import BuildSettings from cpl_cli.configuration.project_settings import ProjectSettings from cpl_cli.publish.publisher_abc import PublisherABC @@ -19,21 +19,21 @@ from cpl_cli.templates.publish.setup_template import SetupTemplate class PublisherService(PublisherABC): - def __init__(self, runtime: ApplicationRuntimeABC, project: ProjectSettings, build: BuildSettings): + def __init__(self, env: ApplicationEnvironmentABC, project: ProjectSettings, build: BuildSettings): """ Service to build or publish files for distribution - :param runtime: + :param env: :param project: :param build: """ PublisherABC.__init__(self) - self._runtime = runtime + self._env = env self._project_settings = project self._build_settings = build - self._source_path = os.path.join(self._runtime.working_directory, self._build_settings.source_path) - self._output_path = os.path.join(self._runtime.working_directory, self._build_settings.output_path) + self._source_path = os.path.join(self._env.working_directory, self._build_settings.source_path) + self._output_path = os.path.join(self._env.working_directory, self._build_settings.output_path) self._included_files: list[str] = [] self._included_dirs: list[str] = [] diff --git a/src/cpl_cli/startup.py b/src/cpl_cli/startup.py index 5d250cf3..1d54bc32 100644 --- a/src/cpl_cli/startup.py +++ b/src/cpl_cli/startup.py @@ -1,4 +1,3 @@ -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 @@ -23,21 +22,21 @@ from cpl_cli.publish.publisher_abc import PublisherABC class Startup(StartupABC): - def __init__(self, config: ConfigurationABC, runtime: ApplicationRuntimeABC, services: ServiceCollectionABC): + def __init__(self, config: ConfigurationABC, services: ServiceCollectionABC): StartupABC.__init__(self) self._configuration = config - self._application_runtime = runtime + self._env = self._configuration.environment self._services = services - self._application_runtime.set_runtime_directory(__file__) + self._env.set_runtime_directory(__file__) def configure_configuration(self) -> ConfigurationABC: self._configuration.argument_error_function = Error.error self._configuration.add_environment_variables('PYTHON_') self._configuration.add_environment_variables('CPL_') - self._configuration.add_json_file('appsettings.json', path=self._application_runtime.runtime_directory, + self._configuration.add_json_file('appsettings.json', path=self._env.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=[ diff --git a/src/tests/custom/general/application.py b/src/tests/custom/general/application.py index b59a9771..ff1140ca 100644 --- a/src/tests/custom/general/application.py +++ b/src/tests/custom/general/application.py @@ -2,7 +2,6 @@ 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 @@ -14,8 +13,8 @@ from tests.custom.general.test_service import TestService class Application(ApplicationABC): - def __init__(self, config: ConfigurationABC, runtime: ApplicationRuntimeABC, services: ServiceProviderABC): - ApplicationABC.__init__(self, config, runtime, services) + def __init__(self, config: ConfigurationABC, services: ServiceProviderABC): + ApplicationABC.__init__(self, config, services) self._logger: Optional[LoggerABC] = None self._mailer: Optional[EMailClientABC] = None diff --git a/src/tests/custom/general/startup.py b/src/tests/custom/general/startup.py index 2e3688b7..3630004e 100644 --- a/src/tests/custom/general/startup.py +++ b/src/tests/custom/general/startup.py @@ -1,4 +1,3 @@ -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 @@ -15,11 +14,10 @@ from tests.custom.general.test_service import TestService class Startup(StartupABC): - def __init__(self, config: ConfigurationABC, runtime: ApplicationRuntimeABC, services: ServiceCollectionABC): + def __init__(self, config: ConfigurationABC, services: ServiceCollectionABC): StartupABC.__init__(self) self._configuration = config - self._application_runtime = runtime self._services = services def configure_configuration(self) -> ConfigurationABC: