2022.6.4 #58

Merged
edraft merged 2 commits from 2022.6.4 into 2022.6 2022-04-30 18:33:55 +02:00
10 changed files with 89 additions and 22 deletions
Showing only changes of commit 97e52b39c0 - Show all commits

View File

@ -16,7 +16,7 @@
"LicenseName": "MIT",
"LicenseDescription": "MIT, see LICENSE for more details.",
"Dependencies": [
"cpl-core>=2022.6.1"
"cpl-core>=2022.6.2"
],
"PythonVersion": ">=3.10",
"PythonPath": {},

View File

@ -24,6 +24,7 @@ from .application_abc import ApplicationABC
from .application_builder import ApplicationBuilder
from .application_builder_abc import ApplicationBuilderABC
from .startup_abc import StartupABC
from .startup_extension_abc import StartupExtensionABC
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2022', minor='6', micro='1')

View File

@ -1,9 +1,10 @@
from typing import Type, Optional, Callable
from typing import Type, Optional, Callable, Union
from cpl_core.application.application_abc import ApplicationABC
from cpl_core.application.application_builder_abc import ApplicationBuilderABC
from cpl_core.application.application_extension_abc import ApplicationExtensionABC
from cpl_core.application.startup_abc import StartupABC
from cpl_core.application.startup_extension_abc import StartupExtensionABC
from cpl_core.configuration.configuration import Configuration
from cpl_core.dependency_injection.service_collection import ServiceCollection
@ -26,38 +27,47 @@ class ApplicationBuilder(ApplicationBuilderABC):
self._environment = self._configuration.environment
self._services = ServiceCollection(self._configuration)
self._extensions: list[Callable] = []
self._app_extensions: list[Callable] = []
self._startup_extensions: list[Callable] = []
def use_startup(self, startup: Type[StartupABC]):
self._startup = startup()
def use_extension(self, extension: Type[ApplicationExtensionABC]):
if extension not in self._extensions:
self._extensions.append(extension)
def use_extension(self, extension: Type[Union[ApplicationExtensionABC, StartupExtensionABC]]):
if issubclass(extension, ApplicationExtensionABC) and extension not in self._app_extensions:
self._app_extensions.append(extension)
elif issubclass(extension, StartupExtensionABC) and extension not in self._startup_extensions:
self._startup_extensions.append(extension)
def _build_startup(self):
for ex in self._startup_extensions:
extension = ex()
extension.configure_configuration(self._configuration, self._environment)
extension.configure_services(self._services, self._environment)
def build(self) -> ApplicationABC:
if self._startup is not None:
self._startup.configure_configuration(self._configuration, self._environment)
self._startup.configure_services(self._services, self._environment)
def build(self) -> ApplicationABC:
self._build_startup()
config = self._configuration
services = self._services.build_service_provider()
for ex in self._extensions:
for ex in self._app_extensions:
extension = ex()
extension.run(config, services)
return self._app(config, services)
async def build_async(self) -> ApplicationABC:
if self._startup is not None:
await self._startup.configure_configuration(self._configuration, self._environment)
await self._startup.configure_services(self._services, self._environment)
self._build_startup()
config = self._configuration
services = self._services.build_service_provider()
for ex in self._extensions:
for ex in self._app_extensions:
extension = ex()
await extension.run(config, services)

View File

@ -10,8 +10,7 @@ class StartupABC(ABC):
r"""ABC for the startup class"""
@abstractmethod
def __init__(self, *args):
pass
def __init__(self): pass
@abstractmethod
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC) -> ConfigurationABC:

View File

@ -0,0 +1,34 @@
from abc import ABC, abstractmethod
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 StartupExtensionABC(ABC):
r"""ABC for startup extension classes"""
@abstractmethod
def __init__(self): pass
@abstractmethod
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
r"""Creates configuration of application
Parameter
---------
config: :class:`cpl_core.configuration.configuration_abc.ConfigurationABC`
env: :class:`cpl_core.environment.application_environment_abc`
"""
pass
@abstractmethod
def configure_services(self, service: ServiceCollectionABC, env: ApplicationEnvironmentABC):
r"""Creates service provider
Parameter
---------
services: :class:`cpl_core.dependency_injection.service_collection_abc`
env: :class:`cpl_core.environment.application_environment_abc`
"""
pass

View File

@ -4,7 +4,7 @@
"Version": {
"Major": "2022",
"Minor": "6",
"Micro": "1"
"Micro": "2"
},
"Author": "Sven Heidemann",
"AuthorEmail": "sven.heidemann@sh-edraft.de",

View File

@ -21,9 +21,13 @@
},
"DatabaseSettings": {
"AuthPlugin": "mysql_native_password",
"ConnectionString": "mysql+mysqlconnector://sh_cpl:$credentials@localhost/sh_cpl",
"Credentials": "MHZhc0Y2bjhKc1VUMWV0Qw==",
"Encoding": "utf8mb4"
"Host": "localhost",
"User": "sh_cpl",
"Password": "MHZhc0Y2bjhKc1VUMWV0Qw==",
"Database": "sh_cpl",
"Charset": "utf8mb4",
"UseUnicode": "true",
"Buffered": "true",
"AuthPlugin": "mysql_native_password"
}
}

View File

@ -16,9 +16,9 @@
"LicenseName": "MIT",
"LicenseDescription": "MIT, see LICENSE for more details.",
"Dependencies": [
"sh_cpl==2021.4.0.post2"
"cpl_core==2022.6.1"
],
"PythonVersion": ">=3.8",
"PythonVersion": ">=3.10",
"PythonPath": {
"linux": "../../../../../../cpl-env/bin/python3.9",
"win32": ""

View File

@ -1,12 +1,14 @@
from application import Application
from cpl_core.application import ApplicationBuilder
from general.test_extension import TestExtension
from test_extension import TestExtension
from startup import Startup
from test_startup_extension import TestStartupExtension
def main():
app_builder = ApplicationBuilder(Application)
app_builder.use_startup(Startup)
app_builder.use_extension(TestStartupExtension)
app_builder.use_extension(TestExtension)
app_builder.build().run()

View File

@ -0,0 +1,17 @@
from cpl_core.application import StartupExtensionABC
from cpl_core.configuration import ConfigurationABC
from cpl_core.console import Console
from cpl_core.dependency_injection import ServiceCollectionABC
from cpl_core.environment import ApplicationEnvironmentABC
class TestStartupExtension(StartupExtensionABC):
def __init__(self):
StartupExtensionABC.__init__(self)
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
Console.write_line('config')
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
Console.write_line('services')