2022.10.4 - Removed async from startup functions (#94) #110

Merged
edraft merged 1 commits from 2022.10.4 into 2022.10 2022-09-17 11:59:39 +02:00
4 changed files with 40 additions and 82 deletions

View File

@ -5,33 +5,12 @@ from cpl_cli._templates.template_file_abc import TemplateFileABC
class StartupTemplate(TemplateFileABC):
def __init__(self, name: str, path: str, use_async: bool):
def __init__(self, name: str, path: str):
TemplateFileABC.__init__(self)
self._name = 'startup.py'
self._path = path
self._use_async = use_async
if self._use_async:
self._value = textwrap.dedent("""\
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 Startup(StartupABC):
def __init__(self):
StartupABC.__init__(self)
async def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
return configuration
async def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
return services.build_service_provider()
""")
else:
self._value = textwrap.dedent("""\
from cpl_core.application import StartupABC
from cpl_core.configuration import ConfigurationABC

View File

@ -5,32 +5,11 @@ from cpl_cli._templates.template_file_abc import TemplateFileABC
class StartupTemplate(TemplateFileABC):
def __init__(self, name: str, path: str, use_async: bool):
def __init__(self, name: str, path: str):
TemplateFileABC.__init__(self)
self._name = 'startup.py'
self._path = path
if use_async:
self._value = textwrap.dedent("""\
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 Startup(StartupABC):
def __init__(self):
StartupABC.__init__(self)
async def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
return configuration
async def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
return services.build_service_provider()
""")
else:
self._value = textwrap.dedent("""\
from cpl_core.application import StartupABC
from cpl_core.configuration import ConfigurationABC

View File

@ -109,7 +109,7 @@ class ConsoleBuilder:
templates.append(ApplicationTemplate(src_name, py_src_rel_path, use_async))
if use_startup:
templates.append(StartupTemplate(src_name, py_src_rel_path, use_async))
templates.append(StartupTemplate(src_name, py_src_rel_path))
templates.append(MainWithApplicationHostAndStartupTemplate(src_name, py_src_rel_path, use_async))
else:
templates.append(MainWithApplicationBaseTemplate(src_name, py_src_rel_path, use_async))

View File

@ -113,7 +113,7 @@ class LibraryBuilder:
templates.append(ApplicationTemplate(src_name, py_src_rel_path, use_async))
if use_startup:
templates.append(StartupTemplate(src_name, py_src_rel_path, use_async))
templates.append(StartupTemplate(src_name, py_src_rel_path))
templates.append(MainWithApplicationHostAndStartupTemplate(src_name, py_src_rel_path, use_async))
else:
templates.append(MainWithApplicationBaseTemplate(src_name, py_src_rel_path, use_async))