2021.10.2 #48

Merged
edraft merged 7 commits from 2021.10.2 into master 2021-11-14 12:56:42 +01:00
162 changed files with 1045 additions and 320 deletions

View File

@ -1,16 +1,16 @@
#!/bin/bash #!/bin/bash
if [ $1 == "-prod" ]; then if [ $1 == "-prod" ]; then
twine upload -r pip.sh-edraft.de ../dist/sh_cpl-cli/publish/setup/* twine upload -r pip.sh-edraft.de dist/sh_cpl-cli/publish/setup/*
twine upload -r pip.sh-edraft.de ../dist/sh_cpl-core/publish/setup/* twine upload -r pip.sh-edraft.de dist/sh_cpl-core/publish/setup/*
twine upload -r pip.sh-edraft.de ../dist/sh_cpl-query/publish/setup/* twine upload -r pip.sh-edraft.de dist/sh_cpl-query/publish/setup/*
elif [ $1 == "-prod" ]; then elif [ $1 == "-prod" ]; then
twine upload -r pip-exp.sh-edraft.de ../dist/sh_cpl-cli/publish/setup/* twine upload -r pip-exp.sh-edraft.de dist/sh_cpl-cli/publish/setup/*
twine upload -r pip-exp.sh-edraft.de ../dist/sh_cpl-core/publish/setup/* twine upload -r pip-exp.sh-edraft.de dist/sh_cpl-core/publish/setup/*
twine upload -r pip-.sh-edraft.de ../dist/sh_cpl-query/publish/setup/* twine upload -r pip-.sh-edraft.de dist/sh_cpl-query/publish/setup/*
else else
twine upload -r pip-dev.sh-edraft.de ../dist/sh_cpl-cli/publish/setup/* twine upload -r pip-dev.sh-edraft.de dist/sh_cpl-cli/publish/setup/*
twine upload -r pip-dev.sh-edraft.de ../dist/sh_cpl-core/publish/setup/* twine upload -r pip-dev.sh-edraft.de dist/sh_cpl-core/publish/setup/*
twine upload -r pip-dev.sh-edraft.de ../dist/sh_cpl-query/publish/setup/* twine upload -r pip-dev.sh-edraft.de dist/sh_cpl-query/publish/setup/*
fi fi

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_cli'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post2' __version__ = '2021.10.3'
from collections import namedtuple from collections import namedtuple
@ -29,4 +29,4 @@ from .main import main
from .startup import Startup from .startup import Startup
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post2') version_info = VersionInfo(major='2021', minor='10', micro='3')

View File

@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post2' __version__ = '2021.10.3'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post2') version_info = VersionInfo(major='2021', minor='10', micro='3')

View File

@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.build'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post2' __version__ = '2021.10.3'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post2') version_info = VersionInfo(major='2021', minor='10', micro='3')

View File

@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.generate'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post2' __version__ = '2021.10.3'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post2') version_info = VersionInfo(major='2021', minor='10', micro='3')

View File

@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post2' __version__ = '2021.10.3'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post2') version_info = VersionInfo(major='2021', minor='10', micro='3')

View File

@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.console'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post2' __version__ = '2021.10.3'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post2') version_info = VersionInfo(major='2021', minor='10', micro='3')

View File

@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.console.source'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post2' __version__ = '2021.10.3'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post2') version_info = VersionInfo(major='2021', minor='10', micro='3')

View File

@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.console.source.name'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post2' __version__ = '2021.10.3'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post2') version_info = VersionInfo(major='2021', minor='10', micro='3')

View File

@ -5,29 +5,51 @@ from cpl_cli._templates.template_file_abc import TemplateFileABC
class ApplicationTemplate(TemplateFileABC): class ApplicationTemplate(TemplateFileABC):
def __init__(self, name: str, path: str): def __init__(self, name: str, path: str, use_async: bool):
TemplateFileABC.__init__(self) TemplateFileABC.__init__(self)
self._name = 'application.py' self._name = 'application.py'
self._path = path self._path = path
self._value = textwrap.dedent("""\ self._use_async = use_async
from cpl_core.application import ApplicationABC
from cpl_core.configuration import ConfigurationABC if self._use_async:
from cpl_core.console import Console self._value = textwrap.dedent("""\
from cpl_core.dependency_injection import ServiceProviderABC 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 Application(ApplicationABC): class Application(ApplicationABC):
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC): def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
ApplicationABC.__init__(self, config, services) ApplicationABC.__init__(self, config, services)
def configure(self): async def configure(self):
pass pass
def main(self): async def main(self):
Console.write_line('Hello World') Console.write_line('Hello World')
""") """)
else:
self._value = textwrap.dedent("""\
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 Application(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')
""")
@property @property
def name(self) -> str: def name(self) -> str:

View File

@ -6,7 +6,7 @@ from cpl_cli._templates.template_file_abc import TemplateFileABC
class MainWithApplicationHostAndStartupTemplate(TemplateFileABC): class MainWithApplicationHostAndStartupTemplate(TemplateFileABC):
def __init__(self, name: str, path: str): def __init__(self, name: str, path: str, use_async: bool):
TemplateFileABC.__init__(self) TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name) name = String.convert_to_snake_case(name)
@ -15,22 +15,44 @@ class MainWithApplicationHostAndStartupTemplate(TemplateFileABC):
import_pkg = f'{name}.' import_pkg = f'{name}.'
self._value = textwrap.dedent(f"""\ if use_async:
from cpl_core.application import ApplicationBuilder self._value = textwrap.dedent(f"""\
import asyncio
from {import_pkg}application import Application from cpl_core.application import ApplicationBuilder
from {import_pkg}startup import Startup
from {import_pkg}application import Application
from {import_pkg}startup import Startup
def main(): async def main():
app_builder = ApplicationBuilder(Application) app_builder = ApplicationBuilder(Application)
app_builder.use_startup(Startup) app_builder.use_startup(Startup)
app_builder.build().run() app: Application = await app_builder.build_async()
await app.run_async()
if __name__ == '__main__': if __name__ == '__main__':
main() ml = asyncio.get_event_loop()
""") ml.run_until_complete(main())
""")
else:
self._value = textwrap.dedent(f"""\
from cpl_core.application import ApplicationBuilder
from {import_pkg}application import Application
from {import_pkg}startup import Startup
def main():
app_builder = ApplicationBuilder(Application)
app_builder.use_startup(Startup)
app_builder.build().run()
if __name__ == '__main__':
main()
""")
@property @property
def name(self) -> str: def name(self) -> str:
@ -47,7 +69,7 @@ class MainWithApplicationHostAndStartupTemplate(TemplateFileABC):
class MainWithApplicationBaseTemplate(TemplateFileABC): class MainWithApplicationBaseTemplate(TemplateFileABC):
def __init__(self, name: str, path: str): def __init__(self, name: str, path: str, use_async: bool):
TemplateFileABC.__init__(self) TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name) name = String.convert_to_snake_case(name)
@ -56,20 +78,40 @@ class MainWithApplicationBaseTemplate(TemplateFileABC):
import_pkg = f'{name}.' import_pkg = f'{name}.'
self._value = textwrap.dedent(f"""\ if use_async:
from cpl_core.application import ApplicationBuilder self._value = textwrap.dedent(f"""\
import asyncio
from {import_pkg}application import Application from cpl_core.application import ApplicationBuilder
from {import_pkg}application import Application
def main(): async def main():
app_builder = ApplicationBuilder(Application) app_builder = ApplicationBuilder(Application)
app_builder.build().run() app: Application = await app_builder.build_async()
await app.run_async()
if __name__ == '__main__': if __name__ == '__main__':
main() ml = asyncio.get_event_loop()
""") ml.run_until_complete(main())
""")
else:
self._value = textwrap.dedent(f"""\
from cpl_core.application import ApplicationBuilder
from {import_pkg}application import Application
def main():
app_builder = ApplicationBuilder(Application)
app_builder.build().run()
if __name__ == '__main__':
main()
""")
@property @property
def name(self) -> str: def name(self) -> str:
@ -86,7 +128,7 @@ class MainWithApplicationBaseTemplate(TemplateFileABC):
class MainWithoutApplicationBaseTemplate(TemplateFileABC): class MainWithoutApplicationBaseTemplate(TemplateFileABC):
def __init__(self, name: str, path: str): def __init__(self, name: str, path: str, use_async: bool):
TemplateFileABC.__init__(self) TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name) name = String.convert_to_snake_case(name)
@ -95,17 +137,33 @@ class MainWithoutApplicationBaseTemplate(TemplateFileABC):
import_pkg = f'{name}.' import_pkg = f'{name}.'
self._value = textwrap.dedent("""\ if use_async:
from cpl_core.console import Console self._value = textwrap.dedent("""\
import asyncio
from cpl_core.console import Console
def main(): async def main():
Console.write_line('Hello World') Console.write_line('Hello World')
if __name__ == '__main__': if __name__ == '__main__':
main() ml = asyncio.get_event_loop()
""") ml.run_until_complete(main())
""")
else:
self._value = textwrap.dedent("""\
from cpl_core.console import Console
def main():
Console.write_line('Hello World')
if __name__ == '__main__':
main()
""")
@property @property
def name(self) -> str: def name(self) -> str:
@ -122,7 +180,7 @@ class MainWithoutApplicationBaseTemplate(TemplateFileABC):
class MainWithDependencyInjection(TemplateFileABC): class MainWithDependencyInjection(TemplateFileABC):
def __init__(self, name: str, path: str): def __init__(self, name: str, path: str, use_async: bool):
TemplateFileABC.__init__(self) TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name) name = String.convert_to_snake_case(name)
@ -131,31 +189,61 @@ class MainWithDependencyInjection(TemplateFileABC):
import_pkg = f'{name}.' import_pkg = f'{name}.'
self._value = textwrap.dedent("""\ if use_async:
from cpl_core.configuration import Configuration, ConfigurationABC self._value = textwrap.dedent("""\
from cpl_core.console import Console import asyncio
from cpl_core.dependency_injection import ServiceCollection, ServiceProviderABC
from cpl_core.configuration import Configuration, ConfigurationABC
from cpl_core.console import Console
from cpl_core.dependency_injection import ServiceCollection, ServiceProviderABC
def configure_configuration() -> ConfigurationABC: async def configure_configuration() -> ConfigurationABC:
config = Configuration() config = Configuration()
return config return config
def configure_services(config: ConfigurationABC) -> ServiceProviderABC: async def configure_services(config: ConfigurationABC) -> ServiceProviderABC:
services = ServiceCollection(config) services = ServiceCollection(config)
return services.build_service_provider() return services.build_service_provider()
def main(): async def main():
config = configure_configuration() config = await configure_configuration()
provider = configure_services(config) provider = await configure_services(config)
Console.write_line('Hello World') Console.write_line('Hello World')
if __name__ == '__main__': if __name__ == '__main__':
main() ml = asyncio.get_event_loop()
""") ml.run_until_complete(main())
""")
else:
self._value = textwrap.dedent("""\
from cpl_core.configuration import Configuration, ConfigurationABC
from cpl_core.console import Console
from cpl_core.dependency_injection import ServiceCollection, ServiceProviderABC
def configure_configuration() -> ConfigurationABC:
config = Configuration()
return config
def configure_services(config: ConfigurationABC) -> ServiceProviderABC:
services = ServiceCollection(config)
return services.build_service_provider()
def main():
config = configure_configuration()
provider = configure_services(config)
Console.write_line('Hello World')
if __name__ == '__main__':
main()
""")
@property @property
def name(self) -> str: def name(self) -> str:

View File

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

View File

@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.console.source.tests'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post2' __version__ = '2021.10.3'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post2') version_info = VersionInfo(major='2021', minor='10', micro='3')

View File

@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.library'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post2' __version__ = '2021.10.3'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post2') version_info = VersionInfo(major='2021', minor='10', micro='3')

View File

@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.library.source'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post2' __version__ = '2021.10.3'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post2') version_info = VersionInfo(major='2021', minor='10', micro='3')

View File

@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.library.source.name'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post2' __version__ = '2021.10.3'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post2') version_info = VersionInfo(major='2021', minor='10', micro='3')

View File

@ -5,29 +5,50 @@ from cpl_cli._templates.template_file_abc import TemplateFileABC
class ApplicationTemplate(TemplateFileABC): class ApplicationTemplate(TemplateFileABC):
def __init__(self, name: str, path: str): def __init__(self, name: str, path: str, use_async: bool):
TemplateFileABC.__init__(self) TemplateFileABC.__init__(self)
self._name = 'application.py' self._name = 'application.py'
self._path = path self._path = path
self._value = textwrap.dedent("""\
from cpl_core.application import ApplicationABC if use_async:
from cpl_core.configuration import ConfigurationABC self._value = textwrap.dedent("""\
from cpl_core.console import Console from cpl_core.application import ApplicationABC
from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.configuration import ConfigurationABC
from cpl_core.console import Console
from cpl_core.dependency_injection import ServiceProviderABC
class Application(ApplicationABC): class Application(ApplicationABC):
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC): def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
ApplicationABC.__init__(self, config, services) ApplicationABC.__init__(self, config, services)
def configure(self): async def configure(self):
pass pass
def main(self): async def main(self):
Console.write_line('Hello World') Console.write_line('Hello World')
""") """)
else:
self._value = textwrap.dedent("""\
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 Application(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')
""")
@property @property
def name(self) -> str: def name(self) -> str:

View File

@ -5,7 +5,7 @@ from cpl_cli._templates.template_file_abc import TemplateFileABC
class MainWithApplicationHostAndStartupTemplate(TemplateFileABC): class MainWithApplicationHostAndStartupTemplate(TemplateFileABC):
def __init__(self, name: str, path: str): def __init__(self, name: str, path: str, use_async: bool):
TemplateFileABC.__init__(self) TemplateFileABC.__init__(self)
self._name = 'main.py' self._name = 'main.py'
@ -15,22 +15,44 @@ class MainWithApplicationHostAndStartupTemplate(TemplateFileABC):
if name == '': if name == '':
import_pkg = '' import_pkg = ''
self._value = textwrap.dedent(f"""\ if use_async:
from cpl_core.application import ApplicationBuilder self._value = textwrap.dedent(f"""\
import asyncio
from {import_pkg}application import Application from cpl_core.application import ApplicationBuilder
from {import_pkg}startup import Startup
from {import_pkg}application import Application
from {import_pkg}startup import Startup
def main(): async def main():
app_builder = ApplicationBuilder(Application) app_builder = ApplicationBuilder(Application)
app_builder.use_startup(Startup) app_builder.use_startup(Startup)
app_builder.build().run() app: Application = await app_builder.build_async()
await app.run_async()
if __name__ == '__main__': if __name__ == '__main__':
main() ml = asyncio.get_event_loop()
""") ml.run_until_complete(main())
""")
else:
self._value = textwrap.dedent(f"""\
from cpl_core.application import ApplicationBuilder
from {import_pkg}application import Application
from {import_pkg}startup import Startup
def main():
app_builder = ApplicationBuilder(Application)
app_builder.use_startup(Startup)
app_builder.build().run()
if __name__ == '__main__':
main()
""")
@property @property
def name(self) -> str: def name(self) -> str:
@ -47,7 +69,7 @@ class MainWithApplicationHostAndStartupTemplate(TemplateFileABC):
class MainWithApplicationBaseTemplate(TemplateFileABC): class MainWithApplicationBaseTemplate(TemplateFileABC):
def __init__(self, name: str, path: str): def __init__(self, name: str, path: str, use_async: bool):
TemplateFileABC.__init__(self) TemplateFileABC.__init__(self)
self._name = 'main.py' self._name = 'main.py'
@ -57,20 +79,40 @@ class MainWithApplicationBaseTemplate(TemplateFileABC):
if name == '': if name == '':
import_pkg = '' import_pkg = ''
self._value = textwrap.dedent(f"""\ if use_async:
from cpl_core.application import ApplicationBuilder self._value = textwrap.dedent(f"""\
import asyncio
from {import_pkg}application import Application from cpl_core.application import ApplicationBuilder
from {import_pkg}application import Application
def main(): async def main():
app_builder = ApplicationBuilder(Application) app_builder = ApplicationBuilder(Application)
app_builder.build().run() app: Application = await app_builder.build_async()
await app.run_async()
if __name__ == '__main__': if __name__ == '__main__':
main() ml = asyncio.get_event_loop()
""") ml.run_until_complete(main())
""")
else:
self._value = textwrap.dedent(f"""\
from cpl_core.application import ApplicationBuilder
from {import_pkg}application import Application
def main():
app_builder = ApplicationBuilder(Application)
app_builder.build().run()
if __name__ == '__main__':
main()
""")
@property @property
def name(self) -> str: def name(self) -> str:
@ -87,23 +129,39 @@ class MainWithApplicationBaseTemplate(TemplateFileABC):
class MainWithoutApplicationBaseTemplate(TemplateFileABC): class MainWithoutApplicationBaseTemplate(TemplateFileABC):
def __init__(self, name: str, path: str): def __init__(self, name: str, path: str, use_async: bool):
TemplateFileABC.__init__(self) TemplateFileABC.__init__(self)
self._name = 'main.py' self._name = 'main.py'
self._path = path self._path = path
self._value = textwrap.dedent("""\ if use_async:
from cpl_core.console import Console self._value = textwrap.dedent("""\
import asyncio
from cpl_core.console import Console
def main(): async def main():
Console.write_line('Hello World') Console.write_line('Hello World')
if __name__ == '__main__': if __name__ == '__main__':
main() ml = asyncio.get_event_loop()
""") ml.run_until_complete(main())
""")
else:
self._value = textwrap.dedent("""\
from cpl_core.console import Console
def main():
Console.write_line('Hello World')
if __name__ == '__main__':
main()
""")
@property @property
def name(self) -> str: def name(self) -> str:
@ -120,37 +178,67 @@ class MainWithoutApplicationBaseTemplate(TemplateFileABC):
class MainWithDependencyInjection(TemplateFileABC): class MainWithDependencyInjection(TemplateFileABC):
def __init__(self, name: str, path: str): def __init__(self, name: str, path: str, use_async: bool):
TemplateFileABC.__init__(self) TemplateFileABC.__init__(self)
self._name = 'main.py' self._name = 'main.py'
self._path = path self._path = path
self._value = textwrap.dedent("""\ if use_async:
from cpl_core.configuration import Configuration, ConfigurationABC self._value = textwrap.dedent("""\
from cpl_core.console import Console import asyncio
from cpl_core.dependency_injection import ServiceCollection, ServiceProviderABC
from cpl_core.configuration import Configuration, ConfigurationABC
from cpl_core.console import Console
from cpl_core.dependency_injection import ServiceCollection, ServiceProviderABC
def configure_configuration() -> ConfigurationABC: async def configure_configuration() -> ConfigurationABC:
config = Configuration() config = Configuration()
return config return config
def configure_services(config: ConfigurationABC) -> ServiceProviderABC: async def configure_services(config: ConfigurationABC) -> ServiceProviderABC:
services = ServiceCollection(config) services = ServiceCollection(config)
return services.build_service_provider() return services.build_service_provider()
def main(): async def main():
config = configure_configuration() config = await configure_configuration()
provider = configure_services(config) provider = await configure_services(config)
Console.write_line('Hello World') Console.write_line('Hello World')
if __name__ == '__main__': if __name__ == '__main__':
main() ml = asyncio.get_event_loop()
""") ml.run_until_complete(main())
""")
else:
self._value = textwrap.dedent("""\
from cpl_core.configuration import Configuration, ConfigurationABC
from cpl_core.console import Console
from cpl_core.dependency_injection import ServiceCollection, ServiceProviderABC
def configure_configuration() -> ConfigurationABC:
config = Configuration()
return config
def configure_services(config: ConfigurationABC) -> ServiceProviderABC:
services = ServiceCollection(config)
return services.build_service_provider()
def main():
config = configure_configuration()
provider = configure_services(config)
Console.write_line('Hello World')
if __name__ == '__main__':
main()
""")
@property @property
def name(self) -> str: def name(self) -> str:

View File

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

View File

@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.library.source.tests'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post2' __version__ = '2021.10.3'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post2') version_info = VersionInfo(major='2021', minor='10', micro='3')

View File

@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.publish'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post2' __version__ = '2021.10.3'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post2') version_info = VersionInfo(major='2021', minor='10', micro='3')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_cli.command'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post2' __version__ = '2021.10.3'
from collections import namedtuple from collections import namedtuple
@ -28,4 +28,4 @@ from .publish_service import PublishService
from .version_service import VersionService from .version_service import VersionService
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post2') version_info = VersionInfo(major='2021', minor='10', micro='3')

View File

@ -46,6 +46,7 @@ class NewService(CommandABC):
self._use_application_api: bool = False self._use_application_api: bool = False
self._use_startup: bool = False self._use_startup: bool = False
self._use_service_providing: bool = False self._use_service_providing: bool = False
self._use_async: bool = False
@property @property
def help_message(self) -> str: def help_message(self) -> str:
@ -178,6 +179,10 @@ class NewService(CommandABC):
if result.lower() == 'y': if result.lower() == 'y':
self._use_service_providing = True self._use_service_providing = True
result = Console.read('Do you want to use async? (y/n) ')
if result.lower() == 'y':
self._use_async = True
Console.set_foreground_color(ForegroundColorEnum.default) Console.set_foreground_color(ForegroundColorEnum.default)
def _console(self, args: list[str]): def _console(self, args: list[str]):
@ -202,6 +207,7 @@ class NewService(CommandABC):
self._use_application_api, self._use_application_api,
self._use_startup, self._use_startup,
self._use_service_providing, self._use_service_providing,
self._use_async,
self._project.name, self._project.name,
self._project_json, self._project_json,
self._workspace self._workspace
@ -231,6 +237,7 @@ class NewService(CommandABC):
self._use_application_api, self._use_application_api,
self._use_startup, self._use_startup,
self._use_service_providing, self._use_service_providing,
self._use_async,
self._project.name, self._project.name,
self._project_json, self._project_json,
self._workspace self._workspace

View File

@ -52,7 +52,11 @@ class VersionService(CommandABC):
] ]
packages = [] packages = []
for modname in cpl_packages: for modname in cpl_packages:
module = pkgutil.find_loader(modname).load_module(modname) module = pkgutil.find_loader(modname)
if module is None:
break
module = module.load_module(modname)
if '__version__' in dir(module): if '__version__' in dir(module):
packages.append([f'{modname}', module.__version__]) packages.append([f'{modname}', module.__version__])

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_cli.configuration'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post2' __version__ = '2021.10.3'
from collections import namedtuple from collections import namedtuple
@ -30,4 +30,4 @@ from .workspace_settings import WorkspaceSettings
from .workspace_settings_name_enum import WorkspaceSettingsNameEnum from .workspace_settings_name_enum import WorkspaceSettingsNameEnum
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post2') version_info = VersionInfo(major='2021', minor='10', micro='3')

View File

@ -4,7 +4,7 @@
"Version": { "Version": {
"Major": "2021", "Major": "2021",
"Minor": "10", "Minor": "10",
"Micro": "0.post2" "Micro": "3"
}, },
"Author": "Sven Heidemann", "Author": "Sven Heidemann",
"AuthorEmail": "sven.heidemann@sh-edraft.de", "AuthorEmail": "sven.heidemann@sh-edraft.de",
@ -16,7 +16,7 @@
"LicenseName": "MIT", "LicenseName": "MIT",
"LicenseDescription": "MIT, see LICENSE for more details.", "LicenseDescription": "MIT, see LICENSE for more details.",
"Dependencies": [ "Dependencies": [
"sh_cpl-core>=2021.10.0.post1" "sh_cpl-core>=2021.10.2"
], ],
"PythonVersion": ">=3.8", "PythonVersion": ">=3.8",
"PythonPath": {}, "PythonPath": {},

View File

@ -15,11 +15,11 @@ __title__ = 'cpl_cli.live_server'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post2' __version__ = '2021.10.3'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post2') version_info = VersionInfo(major='2021', minor='10', micro='3')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_cli.publish'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post2' __version__ = '2021.10.3'
from collections import namedtuple from collections import namedtuple
@ -24,4 +24,4 @@ from .publisher_abc import PublisherABC
from .publisher_service import PublisherService from .publisher_service import PublisherService
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post2') version_info = VersionInfo(major='2021', minor='10', micro='3')

View File

@ -15,11 +15,11 @@ __title__ = 'cpl_cli.source_creator'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post2' __version__ = '2021.10.3'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post2') version_info = VersionInfo(major='2021', minor='10', micro='3')

View File

@ -59,13 +59,14 @@ class ConsoleBuilder:
@classmethod @classmethod
def build(cls, project_path: str, use_application_api: bool, use_startup: bool, use_service_providing: bool, def build(cls, project_path: str, use_application_api: bool, use_startup: bool, use_service_providing: bool,
project_name: str, project_settings: dict, workspace: Optional[WorkspaceSettings]): use_async: bool, project_name: str, project_settings: dict, workspace: Optional[WorkspaceSettings]):
""" """
Builds the console project files Builds the console project files
:param project_path: :param project_path:
:param use_application_api: :param use_application_api:
:param use_startup: :param use_startup:
:param use_service_providing: :param use_service_providing:
:param use_async:
:param project_name: :param project_name:
:param project_settings: :param project_settings:
:param workspace: :param workspace:
@ -79,7 +80,8 @@ class ConsoleBuilder:
ReadmeTemplate(), ReadmeTemplate(),
TestsInitTemplate(), TestsInitTemplate(),
AppsettingsTemplate(), AppsettingsTemplate(),
MainInitTemplate(project_name, os.path.join('src/', project_name_snake)) MainInitTemplate(project_name, os.path.join(
'src/', project_name_snake))
] ]
else: else:
project_path = os.path.join( project_path = os.path.join(
@ -103,18 +105,22 @@ class ConsoleBuilder:
src_rel_path = os.path.join('src/', src_name) src_rel_path = os.path.join('src/', src_name)
if use_application_api: if use_application_api:
templates.append(ApplicationTemplate(src_name, src_rel_path)) templates.append(ApplicationTemplate(src_name, src_rel_path, use_async))
if use_startup: if use_startup:
templates.append(StartupTemplate(src_name, src_rel_path)) templates.append(StartupTemplate(src_name, src_rel_path, use_async))
templates.append(MainWithApplicationHostAndStartupTemplate(src_name, src_rel_path)) templates.append(MainWithApplicationHostAndStartupTemplate(
src_name, src_rel_path, use_async))
else: else:
templates.append(MainWithApplicationBaseTemplate(src_name, src_rel_path)) templates.append(MainWithApplicationBaseTemplate(
src_name, src_rel_path, use_async))
else: else:
if use_service_providing: if use_service_providing:
templates.append(MainWithDependencyInjection(src_name, src_rel_path)) templates.append(MainWithDependencyInjection(
src_name, src_rel_path, use_async))
else: else:
templates.append(MainWithoutApplicationBaseTemplate(src_name, src_rel_path)) templates.append(MainWithoutApplicationBaseTemplate(
src_name, src_rel_path, use_async))
proj_name = project_name proj_name = project_name
if workspace is not None: if workspace is not None:
@ -132,7 +138,8 @@ class ConsoleBuilder:
else: else:
workspace.projects[project_name] = f'src/{project_file_path}' workspace.projects[project_name] = f'src/{project_file_path}'
cls._create_workspace('cpl-workspace.json', workspace.default_project, workspace.projects) cls._create_workspace('cpl-workspace.json',
workspace.default_project, workspace.projects)
Console.spinner( Console.spinner(
f'Creating {project_file_path}', f'Creating {project_file_path}',

View File

@ -59,7 +59,7 @@ class LibraryBuilder:
@classmethod @classmethod
def build(cls, project_path: str, use_application_api: bool, use_startup: bool, def build(cls, project_path: str, use_application_api: bool, use_startup: bool,
use_service_providing: bool, project_name: str, project_settings: dict, use_async: bool, use_service_providing: bool, project_name: str, project_settings: dict,
workspace: Optional[WorkspaceSettings]): workspace: Optional[WorkspaceSettings]):
""" """
Builds the library project files Builds the library project files
@ -67,6 +67,7 @@ class LibraryBuilder:
:param use_application_api: :param use_application_api:
:param use_startup: :param use_startup:
:param use_service_providing: :param use_service_providing:
:param use_async:
:param project_name: :param project_name:
:param project_settings: :param project_settings:
:param workspace: :param workspace:
@ -79,7 +80,8 @@ class LibraryBuilder:
LicenseTemplate(), LicenseTemplate(),
ReadmeTemplate(), ReadmeTemplate(),
TestsInitTemplate(), TestsInitTemplate(),
NameInitTemplate(project_name, os.path.join('src/', project_name_snake)), NameInitTemplate(project_name, os.path.join(
'src/', project_name_snake)),
AppsettingsTemplate() AppsettingsTemplate()
] ]
else: else:
@ -108,14 +110,18 @@ class LibraryBuilder:
if use_startup: if use_startup:
templates.append(StartupTemplate(src_name, src_rel_path)) templates.append(StartupTemplate(src_name, src_rel_path))
templates.append(MainWithApplicationHostAndStartupTemplate(src_name, src_rel_path)) templates.append(MainWithApplicationHostAndStartupTemplate(
src_name, src_rel_path))
else: else:
templates.append(MainWithApplicationBaseTemplate(src_name, src_rel_path)) templates.append(MainWithApplicationBaseTemplate(
src_name, src_rel_path))
else: else:
if use_service_providing: if use_service_providing:
templates.append(MainWithDependencyInjection(src_name, src_rel_path)) templates.append(MainWithDependencyInjection(
src_name, src_rel_path))
else: else:
templates.append(MainWithoutApplicationBaseTemplate(src_name, src_rel_path)) templates.append(MainWithoutApplicationBaseTemplate(
src_name, src_rel_path))
proj_name = project_name proj_name = project_name
if workspace is not None: if workspace is not None:
@ -133,7 +139,8 @@ class LibraryBuilder:
else: else:
workspace.projects[project_name] = f'src/{project_file_path}' workspace.projects[project_name] = f'src/{project_file_path}'
cls._create_workspace('cpl-workspace.json', workspace.default_project, workspace.projects) cls._create_workspace('cpl-workspace.json',
workspace.default_project, workspace.projects)
Console.spinner( Console.spinner(
f'Creating {project_file_path}', f'Creating {project_file_path}',

View File

@ -15,11 +15,11 @@ __title__ = 'cpl_core'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post1' __version__ = '2021.10.2'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post1') version_info = VersionInfo(major='2021', minor='10', micro='2')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.application'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post1' __version__ = '2021.10.2'
from collections import namedtuple from collections import namedtuple
@ -26,4 +26,4 @@ from .application_builder_abc import ApplicationBuilderABC
from .startup_abc import StartupABC from .startup_abc import StartupABC
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post1') version_info = VersionInfo(major='2021', minor='10', micro='2')

View File

@ -35,6 +35,17 @@ class ApplicationABC(ABC):
except KeyboardInterrupt: except KeyboardInterrupt:
Console.close() Console.close()
async def run_async(self):
r"""Entry point
Called by custom Application.main
"""
try:
await self.configure()
await self.main()
except KeyboardInterrupt:
Console.close()
@abstractmethod @abstractmethod
def configure(self): def configure(self):
r"""Configure the application r"""Configure the application

View File

@ -1,4 +1,3 @@
import types
from typing import Type, Optional, Callable from typing import Type, Optional, Callable
from cpl_core.application.application_abc import ApplicationABC from cpl_core.application.application_abc import ApplicationABC
@ -6,7 +5,6 @@ from cpl_core.application.application_builder_abc import ApplicationBuilderABC
from cpl_core.application.application_extension_abc import ApplicationExtensionABC from cpl_core.application.application_extension_abc import ApplicationExtensionABC
from cpl_core.application.startup_abc import StartupABC from cpl_core.application.startup_abc import StartupABC
from cpl_core.configuration.configuration import Configuration from cpl_core.configuration.configuration import Configuration
from cpl_core.console import Console
from cpl_core.dependency_injection.service_collection import ServiceCollection from cpl_core.dependency_injection.service_collection import ServiceCollection
@ -50,3 +48,17 @@ class ApplicationBuilder(ApplicationBuilderABC):
extension.run(config, services) extension.run(config, services)
return self._app(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)
config = self._configuration
services = self._services.build_service_provider()
for ex in self._extensions:
extension = ex()
await extension.run(config, services)
return self._app(config, services)

View File

@ -23,6 +23,17 @@ class ApplicationBuilderABC(ABC):
""" """
pass pass
@abstractmethod
async def use_startup(self, startup: Type[StartupABC]):
r"""Sets the custom startup class to use async
Parameter
---------
startup: Type[:class:`cpl_core.application.startup_abc.StartupABC`]
Startup class to use
"""
pass
@abstractmethod @abstractmethod
def build(self) -> ApplicationABC: def build(self) -> ApplicationABC:
r"""Creates custom application object r"""Creates custom application object
@ -32,3 +43,13 @@ class ApplicationBuilderABC(ABC):
Object of :class:`cpl_core.application.application_abc.ApplicationABC` Object of :class:`cpl_core.application.application_abc.ApplicationABC`
""" """
pass pass
@abstractmethod
async def build_async(self) -> ApplicationABC:
r"""Creates custom application object async
Returns
-------
Object of :class:`cpl_core.application.application_abc.ApplicationABC`
"""
pass

View File

@ -11,3 +11,6 @@ class ApplicationExtensionABC(ABC):
@abstractmethod @abstractmethod
def run(self, config: ConfigurationABC, services: ServiceProviderABC): pass def run(self, config: ConfigurationABC, services: ServiceProviderABC): pass
@abstractmethod
async def run(self, config: ConfigurationABC, services: ServiceProviderABC): pass

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.configuration'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post1' __version__ = '2021.10.2'
from collections import namedtuple from collections import namedtuple
@ -27,4 +27,4 @@ from .configuration_variable_name_enum import ConfigurationVariableNameEnum
from .console_argument import ConsoleArgument from .console_argument import ConsoleArgument
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post1') version_info = VersionInfo(major='2021', minor='10', micro='2')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.console'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post1' __version__ = '2021.10.2'
from collections import namedtuple from collections import namedtuple
@ -27,4 +27,4 @@ from .foreground_color_enum import ForegroundColorEnum
from .spinner_thread import SpinnerThread from .spinner_thread import SpinnerThread
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post1') version_info = VersionInfo(major='2021', minor='10', micro='2')

View File

@ -4,7 +4,7 @@
"Version": { "Version": {
"Major": "2021", "Major": "2021",
"Minor": "10", "Minor": "10",
"Micro": "0.post1" "Micro": "2"
}, },
"Author": "Sven Heidemann", "Author": "Sven Heidemann",
"AuthorEmail": "sven.heidemann@sh-edraft.de", "AuthorEmail": "sven.heidemann@sh-edraft.de",

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.database'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post1' __version__ = '2021.10.2'
from collections import namedtuple from collections import namedtuple
@ -25,4 +25,4 @@ from .database_settings import DatabaseSettings
from .database_settings_name_enum import DatabaseSettingsNameEnum from .database_settings_name_enum import DatabaseSettingsNameEnum
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post1') version_info = VersionInfo(major='2021', minor='10', micro='2')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.database.connection'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post1' __version__ = '2021.10.2'
from collections import namedtuple from collections import namedtuple
@ -24,4 +24,4 @@ from .database_connection import DatabaseConnection
from .database_connection_abc import DatabaseConnectionABC from .database_connection_abc import DatabaseConnectionABC
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post1') version_info = VersionInfo(major='2021', minor='10', micro='2')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.database.context'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post1' __version__ = '2021.10.2'
from collections import namedtuple from collections import namedtuple
@ -24,4 +24,4 @@ from .database_context import DatabaseContext
from .database_context_abc import DatabaseContextABC from .database_context_abc import DatabaseContextABC
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post1') version_info = VersionInfo(major='2021', minor='10', micro='2')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.dependency_injection'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post1' __version__ = '2021.10.2'
from collections import namedtuple from collections import namedtuple
@ -28,4 +28,4 @@ from .service_provider import ServiceProvider
from .service_provider_abc import ServiceProviderABC from .service_provider_abc import ServiceProviderABC
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post1') version_info = VersionInfo(major='2021', minor='10', micro='2')

View File

@ -0,0 +1,18 @@
from cpl_core.console.console import Console
from cpl_core.dependency_injection.scope_abc import ScopeABC
from cpl_core.dependency_injection.service_provider_abc import ServiceProviderABC
class Scope(ScopeABC):
def __init__(self, service_provider: ServiceProviderABC):
self._service_provider = service_provider
self._service_provider.set_scope(self)
@property
def service_provider(self) -> ServiceProviderABC:
return self._service_provider
def dispose(self):
self._service_provider = None

View File

@ -0,0 +1,24 @@
from abc import ABC, abstractmethod
class ScopeABC(ABC):
r"""ABC for the class :class:`cpl_core.dependency_injection.scope.Scope`"""
def __init__(self):
pass
@property
@abstractmethod
def service_provider(self):
r"""Returns to service provider of scope
Returns
-------
Object of type :class:`cpl_core.dependency_injection.service_provider_abc.ServiceProviderABC`
"""
pass
@abstractmethod
def dispose():
r"""Sets service_provider to None
"""
pass

View File

@ -0,0 +1,19 @@
from cpl_core.dependency_injection.scope import Scope
from cpl_core.dependency_injection.scope_abc import ScopeABC
from cpl_core.dependency_injection.service_provider_abc import ServiceProviderABC
class ScopeBuilder:
r"""Class to build :class:`cpl_core.dependency_injection.scope.Scope`"""
def __init__(self, service_provider: ServiceProviderABC) -> None:
self._service_provider = service_provider
def build(self) -> ScopeABC:
r"""Returns scope
Returns
-------
Object of type :class:`cpl_core.dependency_injection.scope.Scope`
"""
return Scope(self._service_provider)

View File

@ -59,9 +59,13 @@ class ServiceCollection(ServiceCollectionABC):
self._add_descriptor(impl, ServiceLifetimeEnum.singleton) self._add_descriptor(impl, ServiceLifetimeEnum.singleton)
def add_scoped(self, service_type: Type, service: Callable = None): def add_scoped(self, service_type: Type, service: Callable = None):
raise Exception('Not implemented') if service is not None:
self._add_descriptor(service, ServiceLifetimeEnum.scoped)
else:
self._add_descriptor(service_type, ServiceLifetimeEnum.scoped)
def add_transient(self, service_type: Union[type], service: Union[type] = None):
def add_transient(self, service_type: type, service: type = None):
if service is not None: if service is not None:
self._add_descriptor(service, ServiceLifetimeEnum.transient) self._add_descriptor(service, ServiceLifetimeEnum.transient)
else: else:

View File

@ -4,5 +4,5 @@ from enum import Enum
class ServiceLifetimeEnum(Enum): class ServiceLifetimeEnum(Enum):
singleton = 0 singleton = 0
scoped = 1 # not supported yet scoped = 1
transient = 2 transient = 2

View File

@ -1,10 +1,13 @@
from collections import Callable from collections import Callable
import copy
from inspect import signature, Parameter from inspect import signature, Parameter
from typing import Optional from typing import Optional
from cpl_core.configuration.configuration_abc import ConfigurationABC from cpl_core.configuration.configuration_abc import ConfigurationABC
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
from cpl_core.database.context.database_context_abc import DatabaseContextABC from cpl_core.database.context.database_context_abc import DatabaseContextABC
from cpl_core.dependency_injection.scope_abc import ScopeABC
from cpl_core.dependency_injection.scope_builder import ScopeBuilder
from cpl_core.dependency_injection.service_provider_abc import ServiceProviderABC from cpl_core.dependency_injection.service_provider_abc import ServiceProviderABC
from cpl_core.dependency_injection.service_descriptor import ServiceDescriptor from cpl_core.dependency_injection.service_descriptor import ServiceDescriptor
from cpl_core.dependency_injection.service_lifetime_enum import ServiceLifetimeEnum from cpl_core.dependency_injection.service_lifetime_enum import ServiceLifetimeEnum
@ -30,8 +33,9 @@ class ServiceProvider(ServiceProviderABC):
self._service_descriptors: list[ServiceDescriptor] = service_descriptors self._service_descriptors: list[ServiceDescriptor] = service_descriptors
self._configuration: ConfigurationABC = config self._configuration: ConfigurationABC = config
self._database_context = db_context self._database_context = db_context
self._scope: Optional[ScopeABC] = None
def _find_service(self, service_type: type) -> [ServiceDescriptor]: def _find_service(self, service_type: type) -> ServiceDescriptor:
for descriptor in self._service_descriptors: for descriptor in self._service_descriptors:
if descriptor.service_type == service_type or issubclass(descriptor.service_type, service_type): if descriptor.service_type == service_type or issubclass(descriptor.service_type, service_type):
return descriptor return descriptor
@ -85,6 +89,13 @@ class ServiceProvider(ServiceProviderABC):
return service_type(*params) return service_type(*params)
def set_scope(self, scope: ScopeABC):
self._scope = scope
def create_scope(self) -> ScopeABC:
sb = ScopeBuilder(ServiceProvider(copy.deepcopy(self._service_descriptors), self._configuration, self._database_context))
return sb.build()
def get_service(self, service_type: type) -> Optional[Callable[object]]: def get_service(self, service_type: type) -> Optional[Callable[object]]:
result = self._find_service(service_type) result = self._find_service(service_type)
@ -95,7 +106,7 @@ class ServiceProvider(ServiceProviderABC):
return result.implementation return result.implementation
implementation = self.build_service(service_type) implementation = self.build_service(service_type)
if result.lifetime == ServiceLifetimeEnum.singleton: if result.lifetime == ServiceLifetimeEnum.singleton or result.lifetime == ServiceLifetimeEnum.scoped and self._scope is not None:
result.implementation = implementation result.implementation = implementation
return implementation return implementation

View File

@ -2,6 +2,8 @@ from abc import abstractmethod, ABC
from collections import Callable from collections import Callable
from typing import Type, Optional from typing import Type, Optional
from cpl_core.dependency_injection.scope_abc import ScopeABC
class ServiceProviderABC(ABC): class ServiceProviderABC(ABC):
r"""ABC for the class :class:`cpl_core.dependency_injection.service_provider.ServiceProvider`""" r"""ABC for the class :class:`cpl_core.dependency_injection.service_provider.ServiceProvider`"""
@ -25,6 +27,27 @@ class ServiceProviderABC(ABC):
""" """
pass pass
@abstractmethod
def set_scope(self, scope: ScopeABC):
r"""Sets the scope of service provider
Parameter
---------
scope :class:`cpl_core.dependency_injection.scope.Scope`
Service scope
"""
pass
@abstractmethod
def create_scope(self) -> ScopeABC:
r"""Creates a service scope
Returns
-------
Object of type :class:`cpl_core.dependency_injection.scope.Scope`
"""
pass
@abstractmethod @abstractmethod
def get_service(self, instance_type: Type) -> Optional[Callable[object]]: def get_service(self, instance_type: Type) -> Optional[Callable[object]]:
r"""Returns instance of given type r"""Returns instance of given type

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.environment'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post1' __version__ = '2021.10.2'
from collections import namedtuple from collections import namedtuple
@ -25,4 +25,4 @@ from .environment_name_enum import EnvironmentNameEnum
from .application_environment import ApplicationEnvironment from .application_environment import ApplicationEnvironment
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post1') version_info = VersionInfo(major='2021', minor='10', micro='2')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.logging'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post1' __version__ = '2021.10.2'
from collections import namedtuple from collections import namedtuple
@ -27,4 +27,4 @@ from .logging_settings import LoggingSettings
from .logging_settings_name_enum import LoggingSettingsNameEnum from .logging_settings_name_enum import LoggingSettingsNameEnum
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post1') version_info = VersionInfo(major='2021', minor='10', micro='2')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.mailing'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post1' __version__ = '2021.10.2'
from collections import namedtuple from collections import namedtuple
@ -27,4 +27,4 @@ from .email_client_settings import EMailClientSettings
from .email_client_settings_name_enum import EMailClientSettingsNameEnum from .email_client_settings_name_enum import EMailClientSettingsNameEnum
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post1') version_info = VersionInfo(major='2021', minor='10', micro='2')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.time'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post1' __version__ = '2021.10.2'
from collections import namedtuple from collections import namedtuple
@ -24,4 +24,4 @@ from .time_format_settings import TimeFormatSettings
from .time_format_settings_names_enum import TimeFormatSettingsNamesEnum from .time_format_settings_names_enum import TimeFormatSettingsNamesEnum
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post1') version_info = VersionInfo(major='2021', minor='10', micro='2')

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_core.utils'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post1' __version__ = '2021.10.2'
from collections import namedtuple from collections import namedtuple
@ -25,4 +25,4 @@ from .string import String
from .pip import Pip from .pip import Pip
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post1') version_info = VersionInfo(major='2021', minor='10', micro='2')

View File

@ -15,11 +15,11 @@ __title__ = 'cpl_query'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post2' __version__ = '2021.10.2'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post2') version_info = VersionInfo(major='2021', minor='10', micro='2')

View File

@ -15,11 +15,11 @@ __title__ = 'cpl_query._query'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post2' __version__ = '2021.10.2'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post2') version_info = VersionInfo(major='2021', minor='10', micro='2')

View File

@ -4,7 +4,7 @@
"Version": { "Version": {
"Major": "2021", "Major": "2021",
"Minor": "10", "Minor": "10",
"Micro": "0.post2" "Micro": "2"
}, },
"Author": "Sven Heidemann", "Author": "Sven Heidemann",
"AuthorEmail": "sven.heidemann@sh-edraft.de", "AuthorEmail": "sven.heidemann@sh-edraft.de",

View File

@ -15,7 +15,7 @@ __title__ = 'cpl_query.extension'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
__version__ = '2021.10.0.post2' __version__ = '2021.10.2'
from collections import namedtuple from collections import namedtuple
@ -27,4 +27,4 @@ from .ordered_iterable_abc import OrderedIterableABC
from .ordered_iterable import OrderedIterable from .ordered_iterable import OrderedIterable
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major='2021', minor='10', micro='0.post2') version_info = VersionInfo(major='2021', minor='10', micro='2')

View File

@ -0,0 +1,9 @@
{
"WorkspaceSettings": {
"DefaultProject": "async",
"Projects": {
"async": "src/async/async.json"
},
"Scripts": {}
}
}

View File

@ -0,0 +1,16 @@
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 Application(ApplicationABC):
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
ApplicationABC.__init__(self, config, services)
async def configure(self):
pass
async def main(self):
Console.write_line('Hello World')

View File

@ -0,0 +1,43 @@
{
"ProjectSettings": {
"Name": "async",
"Version": {
"Major": "0",
"Minor": "0",
"Micro": "0"
},
"Author": "",
"AuthorEmail": "",
"Description": "",
"LongDescription": "",
"URL": "",
"CopyrightDate": "",
"CopyrightName": "",
"LicenseName": "",
"LicenseDescription": "",
"Dependencies": [
"sh_cpl>=2021.10.0.post1"
],
"PythonVersion": ">=3.9.2",
"PythonPath": {
"linux": ""
},
"Classifiers": []
},
"BuildSettings": {
"ProjectType": "console",
"SourcePath": "",
"OutputPath": "../../dist",
"Main": "async.main",
"EntryPoint": "async",
"IncludePackageData": false,
"Included": [],
"Excluded": [
"*/__pycache__",
"*/logs",
"*/tests"
],
"PackageData": {},
"ProjectReferences": []
}
}

View File

@ -0,0 +1,17 @@
import asyncio
from cpl_core.application import ApplicationBuilder
from application import Application
from startup import Startup
async def main():
app_builder = ApplicationBuilder(Application)
app_builder.use_startup(Startup)
app = await app_builder.build_async()
await app.run_async()
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())

View File

@ -0,0 +1,16 @@
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()

View File

@ -0,0 +1,9 @@
{
"WorkspaceSettings": {
"DefaultProject": "di",
"Projects": {
"di": "src/di/di.json"
},
"Scripts": {}
}
}

View File

@ -0,0 +1,45 @@
from cpl_core.application import ApplicationABC
from cpl_core.configuration import ConfigurationABC
from cpl_core.console.console import Console
from cpl_core.dependency_injection import ServiceProviderABC
from cpl_core.dependency_injection.scope import Scope
from test_service_service import TestService
from di_tester_service import DITesterService
class Application(ApplicationABC):
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
ApplicationABC.__init__(self, config, services)
def _part_of_scoped(self):
ts: TestService = self._services.get_service(TestService)
ts.run()
def configure(self):
pass
def main(self):
Console.write_line('Scope1')
scope1: Scope = self._services.create_scope()
ts: TestService = scope1.service_provider.get_service(TestService)
ts.run()
dit: DITesterService = scope1.service_provider.get_service(DITesterService)
dit.run()
t = scope1
b = t.service_provider
scope1.dispose()
#Console.write_line('Disposed:')
#ts1: TestService = scope1.service_provider.get_service(TestService)
#ts1.run()
Console.write_line('Scope2')
scope2: Scope = self._services.create_scope()
ts: TestService = scope2.service_provider.get_service(TestService)
ts.run()
dit: DITesterService = scope2.service_provider.get_service(DITesterService)
dit.run()
Console.write_line('Global')
self._part_of_scoped()

View File

@ -0,0 +1,43 @@
{
"ProjectSettings": {
"Name": "di",
"Version": {
"Major": "0",
"Minor": "0",
"Micro": "0"
},
"Author": "",
"AuthorEmail": "",
"Description": "",
"LongDescription": "",
"URL": "",
"CopyrightDate": "",
"CopyrightName": "",
"LicenseName": "",
"LicenseDescription": "",
"Dependencies": [
"sh_cpl>=2021.10.0.post1"
],
"PythonVersion": ">=3.9.2",
"PythonPath": {
"linux": ""
},
"Classifiers": []
},
"BuildSettings": {
"ProjectType": "console",
"SourcePath": "",
"OutputPath": "../../dist",
"Main": "di.main",
"EntryPoint": "di",
"IncludePackageData": false,
"Included": [],
"Excluded": [
"*/__pycache__",
"*/logs",
"*/tests"
],
"PackageData": {},
"ProjectReferences": []
}
}

View File

@ -0,0 +1,12 @@
from cpl_core.console.console import Console
from test_service_service import TestService
class DITesterService:
def __init__(self, ts: TestService):
self._ts = ts
def run(self):
Console.write_line('DIT: ')
self._ts.run()

View File

@ -0,0 +1,14 @@
from cpl_core.application import ApplicationBuilder
from di.application import Application
from di.startup import Startup
def main():
app_builder = ApplicationBuilder(Application)
app_builder.use_startup(Startup)
app_builder.build().run()
if __name__ == '__main__':
main()

View File

@ -0,0 +1,21 @@
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
from test_service_service import TestService
from di_tester_service import DITesterService
class Startup(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:
services.add_scoped(TestService)
services.add_scoped(DITesterService)
return services.build_service_provider()

View File

@ -0,0 +1,13 @@
import string
from cpl_core.console.console import Console
from cpl_core.utils.string import String
class TestService:
def __init__(self):
self._name = String.random_string(string.ascii_lowercase, 8)
def run(self):
Console.write_line(f'Im {self._name}')

Some files were not shown because too many files have changed in this diff Show More