2022.12 #133

Merged
edraft merged 85 commits from 2022.12 into master 2022-12-25 11:58:35 +01:00
13 changed files with 299 additions and 14 deletions
Showing only changes of commit 95d8df5bea - Show all commits

View File

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
"""
cpl-cli sh-edraft Common Python library CLI
~~~~~~~~~~~~~~~~~~~
sh-edraft Common Python library Command Line Interface
:copyright: (c) 2020 - 2022 sh-edraft.de
:license: MIT, see LICENSE for more details.
"""
__title__ = 'cpl_cli'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.12.0'
from collections import namedtuple
# imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='12', micro='0')

View File

@ -0,0 +1,39 @@
import textwrap
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
class Application(GenerateSchematicABC):
def __init__(self, *args: str):
GenerateSchematicABC.__init__(self, *args)
def get_code(self) -> str:
code = """\
from cpl_core.application import ApplicationABC
from cpl_core.configuration import ConfigurationABC
from cpl_core.console import Console
from cpl_core.dependency_injection import ServiceProviderABC
class $Name(ApplicationABC):
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
ApplicationABC.__init__(self, config, services)
def configure(self):
pass
def main(self):
Console.write_line('Hello World')
"""
x = self.build_code_str(code, Name=self._class_name)
return x
@classmethod
def register(cls):
GenerateSchematicABC.register(
cls,
'application',
['app', 'APP']
)

View File

@ -0,0 +1,35 @@
import textwrap
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
class ApplicationExtension(GenerateSchematicABC):
def __init__(self, *args: str):
GenerateSchematicABC.__init__(self, *args)
def get_code(self) -> str:
code = """\
from cpl_core.application import ApplicationExtensionABC
from cpl_core.configuration import ConfigurationABC
from cpl_core.dependency_injection import ServiceProviderABC
class $Name(ApplicationExtensionABC):
def __init__(self):
ApplicationExtensionABC.__init__(self)
def run(self, config: ConfigurationABC, services: ServiceProviderABC):
pass
"""
x = self.build_code_str(code, Name=self._class_name)
return x
@classmethod
def register(cls):
GenerateSchematicABC.register(
cls,
'application-extension',
['appex', 'APPEX']
)

View File

@ -0,0 +1,51 @@
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
from cpl_core.utils import String
class Schematic(GenerateSchematicABC):
def __init__(self, name: str, path: str, schematic: str):
GenerateSchematicABC.__init__(self, name, path, schematic)
self._name = f'schematic_{String.convert_to_snake_case(name)}.py'
self._path = '.cpl/'
self._class_name = String.convert_to_camel_case(name)
def get_code(self) -> str:
code = """\
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
class $Name(GenerateSchematicABC):
def __init__(self, *args: str):
GenerateSchematicABC.__init__(self, *args)
def get_code(self) -> str:
import textwrap
code = textwrap.dedent(\"\"\"\\
from enum import Enum
class $Name(Enum):
atr = 0
\"\"\")
return self.build_code_str(code, Name=self._class_name)
@classmethod
def register(cls):
GenerateSchematicABC.register(
cls,
'$NameLower',
[]
)
"""
return self.build_code_str(code, Name=self._class_name)
@classmethod
def register(cls):
GenerateSchematicABC.register(
cls,
'schematic',
['scheme', 'SCHEME']
)

View File

@ -0,0 +1,39 @@
import textwrap
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
class Startup(GenerateSchematicABC):
def __init__(self, *args: str):
GenerateSchematicABC.__init__(self, *args)
def get_code(self) -> str:
code = """\
from cpl_core.application import StartupABC
from cpl_core.configuration import ConfigurationABC
from cpl_core.dependency_injection import ServiceProviderABC, ServiceCollectionABC
from cpl_core.environment import ApplicationEnvironment
class $Name(StartupABC):
def __init__(self):
StartupABC.__init__(self)
def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
return configuration
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
return services.build_service_provider()
"""
x = self.build_code_str(code, Name=self._class_name)
return x
@classmethod
def register(cls):
GenerateSchematicABC.register(
cls,
'startup',
['stup', 'STUP']
)

View File

@ -0,0 +1,39 @@
import textwrap
from cpl_cli.abc.generate_schematic_abc import GenerateSchematicABC
class StartupExtension(GenerateSchematicABC):
def __init__(self, *args: str):
GenerateSchematicABC.__init__(self, *args)
def get_code(self) -> str:
code = """\
from cpl_core.application.startup_extension_abc import StartupExtensionABC
from cpl_core.configuration.configuration_abc import ConfigurationABC
from cpl_core.dependency_injection.service_collection_abc import ServiceCollectionABC
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
class $Name(StartupExtensionABC):
def __init__(self):
pass
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
pass
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
pass
"""
x = self.build_code_str(code, Name=self._class_name)
return x
@classmethod
def register(cls):
GenerateSchematicABC.register(
cls,
'startup-extension',
['stupex', 'STUPEX']
)

View File

@ -1 +1,26 @@
# -*- coding: utf-8 -*-
"""
cpl-cli sh-edraft Common Python library CLI
~~~~~~~~~~~~~~~~~~~
sh-edraft Common Python library Command Line Interface
:copyright: (c) 2020 - 2022 sh-edraft.de
:license: MIT, see LICENSE for more details.
"""
__title__ = 'cpl_cli.abc'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.12.0'
from collections import namedtuple
# imports # imports
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='12', micro='0')

View File

@ -35,11 +35,14 @@ class GenerateService(CommandABC):
self._env = self._config.environment self._env = self._config.environment
self._schematics = {} self._schematics = {}
for package_name in Dependencies.get_cpl_packages(): for package_name, version in Dependencies.get_cpl_packages():
package = importlib.import_module(String.convert_to_snake_case(package_name[0])) if package_name == 'cpl-cli':
continue
package = importlib.import_module(String.convert_to_snake_case(package_name))
self._read_custom_schematics_from_path(os.path.dirname(package.__file__)) self._read_custom_schematics_from_path(os.path.dirname(package.__file__))
self._read_custom_schematics_from_path(self._env.working_directory) self._read_custom_schematics_from_path(self._env.working_directory)
self._read_custom_schematics_from_path(self._env.runtime_directory)
if len(GenerateSchematicABC.__subclasses__()) == 0: if len(GenerateSchematicABC.__subclasses__()) == 0:
Console.error(f'No schematics found in template directory: .cpl') Console.error(f'No schematics found in template directory: .cpl')

View File

@ -2,18 +2,18 @@ import os
import sys import sys
import textwrap import textwrap
from cpl_cli import Error from cpl_cli.error import Error
from cpl_cli.command_abc import CommandABC from cpl_cli.command_abc import CommandABC
from cpl_cli.configuration import WorkspaceSettings from cpl_cli.configuration.workspace_settings import WorkspaceSettings
from cpl_cli.configuration.build_settings import BuildSettings from cpl_cli.configuration.build_settings import BuildSettings
from cpl_cli.configuration.project_settings import ProjectSettings from cpl_cli.configuration.project_settings import ProjectSettings
from cpl_cli.live_server.start_executable import StartExecutable from cpl_cli.live_server.start_executable import StartExecutable
from cpl_cli.publish import PublisherService from cpl_cli.publish.publisher_service import PublisherService
from cpl_core.configuration import ConfigurationABC from cpl_core.configuration.configuration_abc import ConfigurationABC
from cpl_core.console.console import Console from cpl_core.console.console import Console
from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.dependency_injection.service_provider_abc import ServiceProviderABC
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
from cpl_core.utils import String from cpl_core.utils.string import String
class RunService(CommandABC): class RunService(CommandABC):
@ -91,6 +91,7 @@ class RunService(CommandABC):
self._env.set_working_directory(self._src_dir) self._env.set_working_directory(self._src_dir)
self._publisher.build() self._publisher.build()
self._env.set_working_directory(self._src_dir)
self._src_dir = os.path.abspath(os.path.join( self._src_dir = os.path.abspath(os.path.join(
self._src_dir, self._src_dir,
self._build_settings.output_path, self._build_settings.output_path,

View File

@ -123,7 +123,7 @@ class ProjectSettings(ConfigurationModelABC):
self._python_path = settings[ProjectSettingsNameEnum.python_path.value] self._python_path = settings[ProjectSettingsNameEnum.python_path.value]
if ProjectSettingsNameEnum.python_path.value in settings and sys.platform in settings[ProjectSettingsNameEnum.python_path.value]: if ProjectSettingsNameEnum.python_path.value in settings and sys.platform in settings[ProjectSettingsNameEnum.python_path.value]:
path = settings[ProjectSettingsNameEnum.python_path.value][sys.platform] path = f'{settings[ProjectSettingsNameEnum.python_path.value][sys.platform]}/bin/python'
if path == '' or path is None: if path == '' or path is None:
Error.warn(f'{ProjectSettingsNameEnum.python_path.value} not set') Error.warn(f'{ProjectSettingsNameEnum.python_path.value} not set')
path = sys.executable path = sys.executable

View File

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
"""
cpl-cli sh-edraft Common Python library CLI
~~~~~~~~~~~~~~~~~~~
sh-edraft Common Python library Command Line Interface
:copyright: (c) 2020 - 2022 sh-edraft.de
:license: MIT, see LICENSE for more details.
"""
__title__ = 'cpl_cli.helper'
__author__ = 'Sven Heidemann'
__license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
__version__ = '2022.12.0'
from collections import namedtuple
# imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='12', micro='0')

View File

@ -103,9 +103,8 @@ class LiveServerService(FileSystemEventHandler):
return return
self._env.set_working_directory(self._src_dir) self._env.set_working_directory(self._src_dir)
Console.disable()
self._publisher.build() self._publisher.build()
Console.enable() self._env.set_working_directory(self._src_dir)
self._wd = os.path.abspath(os.path.join( self._wd = os.path.abspath(os.path.join(
self._src_dir, self._src_dir,
self._build_settings.output_path, self._build_settings.output_path,

View File

@ -1,13 +1,12 @@
import os import os
import subprocess import subprocess
import sys import sys
import threading
from datetime import datetime from datetime import datetime
from cpl_core.console.console import Console from cpl_core.console.console import Console
from cpl_core.console.foreground_color_enum import ForegroundColorEnum from cpl_core.console.foreground_color_enum import ForegroundColorEnum
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
from cpl_cli.configuration import BuildSettings from cpl_cli.configuration.build_settings import BuildSettings
class StartExecutable: class StartExecutable:
@ -43,7 +42,10 @@ class StartExecutable:
self._env_vars['VIRTUAL_ENV'] = path self._env_vars['VIRTUAL_ENV'] = path
def run(self, args: list[str], executable: str, path: str, output=True): def run(self, args: list[str], executable: str, path: str, output=True):
self._executable = os.path.abspath(executable) self._executable = os.path.abspath(os.path.join(self._env.working_directory, executable))
if not os.path.exists(self._executable):
Console.error(f'Executable not found')
return
main = self._build_settings.main main = self._build_settings.main
if '.' in self._build_settings.main: if '.' in self._build_settings.main: