Removed application runtime | Code refactoring p.2
This commit is contained in:
@@ -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
|
||||
|
||||
|
@@ -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()
|
||||
|
||||
|
@@ -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
|
||||
|
@@ -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()
|
||||
|
||||
|
@@ -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()
|
||||
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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
|
||||
|
||||
|
@@ -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] = []
|
||||
|
@@ -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=[
|
||||
|
Reference in New Issue
Block a user