2021.4 #19

Merged
edraft merged 237 commits from 2021.4 into master 2021-04-01 10:13:33 +02:00
8 changed files with 104 additions and 44 deletions
Showing only changes of commit b6d508526a - Show all commits

View File

@ -13,6 +13,7 @@ from setuptools import sandbox
from cpl.console.foreground_color_enum import ForegroundColorEnum
from cpl.console.console import Console
from cpl.environment.application_environment_abc import ApplicationEnvironmentABC
from cpl.utils.string import String
from cpl_cli.configuration.build_settings import BuildSettings
from cpl_cli.configuration.project_settings import ProjectSettings
from cpl_cli.configuration.project_type_enum import ProjectTypeEnum
@ -292,11 +293,11 @@ class PublisherService(PublisherABC):
main = None
try:
main_name = ''
main_name = self._build_settings.main
if '.' in self._build_settings.main:
length = len(self._build_settings.main.split('.'))
main_name = self._build_settings.main.split('.')[length-1]
main_name = self._build_settings.main.split('.')[length - 1]
sys.path.insert(0, self._source_path)
main_mod = __import__(self._build_settings.main)
@ -406,25 +407,44 @@ class PublisherService(PublisherABC):
4. Remove all included source from dist_path/publish
:return:
"""
if self._build_settings.project_type != ProjectTypeEnum.library.value:
Console.error(f'Project must be a {ProjectTypeEnum.library.value} for publishing.')
return
self._output_path = os.path.join(self._output_path, 'publish')
Console.write_line('Build:')
Console.spinner('Reading source files:', self._read_sources, text_foreground_color=ForegroundColorEnum.green,
spinner_foreground_color=ForegroundColorEnum.blue)
Console.spinner('Creating internal packages:', self._create_packages,
Console.spinner(
'Reading source files:',
self._read_sources,
text_foreground_color=ForegroundColorEnum.green,
spinner_foreground_color=ForegroundColorEnum.blue)
Console.spinner('Building application:', self._dist_files, text_foreground_color=ForegroundColorEnum.green,
spinner_foreground_color=ForegroundColorEnum.blue)
spinner_foreground_color=ForegroundColorEnum.blue
)
Console.spinner(
'Creating internal packages:',
self._create_packages,
text_foreground_color=ForegroundColorEnum.green,
spinner_foreground_color=ForegroundColorEnum.blue
)
Console.spinner(
'Building application:',
self._dist_files,
text_foreground_color=ForegroundColorEnum.green,
spinner_foreground_color=ForegroundColorEnum.blue
)
Console.write_line('\nPublish:')
Console.spinner('Generating setup.py:', self._create_setup, text_foreground_color=ForegroundColorEnum.green,
spinner_foreground_color=ForegroundColorEnum.blue)
Console.spinner(
'Generating setup.py:',
self._create_setup,
text_foreground_color=ForegroundColorEnum.green,
spinner_foreground_color=ForegroundColorEnum.blue
)
Console.write_line('Running setup.py:\n')
self._run_setup()
Console.spinner('Cleaning dist path:', self._clean_dist_files, text_foreground_color=ForegroundColorEnum.green,
spinner_foreground_color=ForegroundColorEnum.blue)
Console.spinner(
'Cleaning dist path:',
self._clean_dist_files,
text_foreground_color=ForegroundColorEnum.green,
spinner_foreground_color=ForegroundColorEnum.blue
)

View File

@ -6,10 +6,11 @@ from cpl_cli.source_creator.template_builder import TemplateBuilder
from cpl_cli.templates.new.console.appsettings_json import AppsettingsTemplate
from cpl_cli.templates.new.console.license import LicenseTemplate
from cpl_cli.templates.new.console.readme_py import ReadmeTemplate
from cpl_cli.templates.new.console.src.application import ApplicationTemplate
from cpl_cli.templates.new.console.src.main import MainWithApplicationHostAndStartupTemplate, \
from cpl_cli.templates.new.console.src.name.application import ApplicationTemplate
from cpl_cli.templates.new.console.src.name.init import MainInitTemplate
from cpl_cli.templates.new.console.src.name.main import MainWithApplicationHostAndStartupTemplate, \
MainWithoutApplicationBaseTemplate, MainWithApplicationBaseTemplate, MainWithDependencyInjection
from cpl_cli.templates.new.console.src.startup import StartupTemplate
from cpl_cli.templates.new.console.src.name.startup import StartupTemplate
from cpl_cli.templates.new.console.src.tests.init import TestsInitTemplate
from cpl_cli.templates.template_file_abc import TemplateFileABC
@ -43,22 +44,23 @@ class ConsoleBuilder:
LicenseTemplate(),
ReadmeTemplate(),
TestsInitTemplate(),
AppsettingsTemplate()
AppsettingsTemplate(),
MainInitTemplate(project_name)
]
if use_application_api:
templates.append(ApplicationTemplate())
templates.append(ApplicationTemplate(project_name))
if use_startup:
templates.append(StartupTemplate())
templates.append(MainWithApplicationHostAndStartupTemplate())
templates.append(StartupTemplate(project_name))
templates.append(MainWithApplicationHostAndStartupTemplate(project_name))
else:
templates.append(MainWithApplicationBaseTemplate())
templates.append(MainWithApplicationBaseTemplate(project_name))
else:
if use_service_providing:
templates.append(MainWithDependencyInjection())
templates.append(MainWithDependencyInjection(project_name))
else:
templates.append(MainWithoutApplicationBaseTemplate())
templates.append(MainWithoutApplicationBaseTemplate(project_name))
for template in templates:
Console.spinner(

View File

@ -1,15 +1,17 @@
import textwrap
from cpl.utils.string import String
from cpl_cli.templates.template_file_abc import TemplateFileABC
class ApplicationTemplate(TemplateFileABC):
def __init__(self):
def __init__(self, name: str):
TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name)
self._name = 'application.py'
self._path = 'src/'
self._path = f'src/{name}/'
self._value = textwrap.dedent("""\
from cpl.application import ApplicationABC
from cpl.configuration import ConfigurationABC

View File

@ -0,0 +1,29 @@
import textwrap
from cpl.utils.string import String
from cpl_cli.templates.template_file_abc import TemplateFileABC
class MainInitTemplate(TemplateFileABC):
def __init__(self, name: str):
TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name)
self._name = '__init__.py'
self._path = f'src/{name}/'
self._value = textwrap.dedent("""\
# imports:
""")
@property
def name(self) -> str:
return self._name
@property
def path(self) -> str:
return self._path
@property
def value(self) -> str:
return self._value

View File

@ -1,20 +1,22 @@
import textwrap
from cpl.utils.string import String
from cpl_cli.templates.template_file_abc import TemplateFileABC
class MainWithApplicationHostAndStartupTemplate(TemplateFileABC):
def __init__(self):
def __init__(self, name: str):
TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name)
self._name = 'main.py'
self._path = 'src/'
self._value = textwrap.dedent("""\
self._path = f'src/{name}/'
self._value = textwrap.dedent(f"""\
from cpl.application import ApplicationBuilder
from application import Application
from startup import Startup
from {name}.application import Application
from {name}.startup import Startup
def main():
@ -42,15 +44,16 @@ class MainWithApplicationHostAndStartupTemplate(TemplateFileABC):
class MainWithApplicationBaseTemplate(TemplateFileABC):
def __init__(self):
def __init__(self, name: str):
TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name)
self._name = 'main.py'
self._path = 'src/'
self._value = textwrap.dedent("""\
self._path = f'src/{name}'
self._value = textwrap.dedent(f"""\
from cpl.application import ApplicationBuilder
from application import Application
from {name}.application import Application
def main():
@ -77,11 +80,12 @@ class MainWithApplicationBaseTemplate(TemplateFileABC):
class MainWithoutApplicationBaseTemplate(TemplateFileABC):
def __init__(self):
def __init__(self, name: str):
TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name)
self._name = 'main.py'
self._path = 'src/'
self._path = f'src/{name}'
self._value = textwrap.dedent("""\
from cpl.console import Console
@ -109,11 +113,12 @@ class MainWithoutApplicationBaseTemplate(TemplateFileABC):
class MainWithDependencyInjection(TemplateFileABC):
def __init__(self):
def __init__(self, name: str):
TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name)
self._name = 'main.py'
self._path = 'src/'
self._path = f'src/{name}'
self._value = textwrap.dedent("""\
from cpl.configuration import Configuration, ConfigurationABC
from cpl.console import Console

View File

@ -1,15 +1,17 @@
import textwrap
from cpl.utils.string import String
from cpl_cli.templates.template_file_abc import TemplateFileABC
class StartupTemplate(TemplateFileABC):
def __init__(self):
def __init__(self, name: str):
TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name)
self._name = 'startup.py'
self._path = 'src/'
self._path = f'src/{name}/'
self._value = textwrap.dedent("""\
from cpl.application import StartupABC
from cpl.configuration import ConfigurationABC

View File

@ -47,7 +47,7 @@ class MainWithApplicationBaseTemplate(TemplateFileABC):
self._name = 'main.py'
self._path = 'src/'
self._value = textwrap.dedent("""\
self._value = textwrap.dedent(f"""\
from cpl.application import ApplicationBuilder
from {name}_cli.application import Application