2021.4 #19
@ -13,6 +13,7 @@ from setuptools import sandbox
|
|||||||
from cpl.console.foreground_color_enum import ForegroundColorEnum
|
from cpl.console.foreground_color_enum import ForegroundColorEnum
|
||||||
from cpl.console.console import Console
|
from cpl.console.console import Console
|
||||||
from cpl.environment.application_environment_abc import ApplicationEnvironmentABC
|
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.build_settings import BuildSettings
|
||||||
from cpl_cli.configuration.project_settings import ProjectSettings
|
from cpl_cli.configuration.project_settings import ProjectSettings
|
||||||
from cpl_cli.configuration.project_type_enum import ProjectTypeEnum
|
from cpl_cli.configuration.project_type_enum import ProjectTypeEnum
|
||||||
@ -292,11 +293,11 @@ class PublisherService(PublisherABC):
|
|||||||
|
|
||||||
main = None
|
main = None
|
||||||
try:
|
try:
|
||||||
main_name = ''
|
main_name = self._build_settings.main
|
||||||
|
|
||||||
if '.' in self._build_settings.main:
|
if '.' in self._build_settings.main:
|
||||||
length = len(self._build_settings.main.split('.'))
|
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)
|
sys.path.insert(0, self._source_path)
|
||||||
main_mod = __import__(self._build_settings.main)
|
main_mod = __import__(self._build_settings.main)
|
||||||
@ -406,25 +407,44 @@ class PublisherService(PublisherABC):
|
|||||||
4. Remove all included source from dist_path/publish
|
4. Remove all included source from dist_path/publish
|
||||||
:return:
|
: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')
|
self._output_path = os.path.join(self._output_path, 'publish')
|
||||||
|
|
||||||
Console.write_line('Build:')
|
Console.write_line('Build:')
|
||||||
Console.spinner('Reading source files:', self._read_sources, text_foreground_color=ForegroundColorEnum.green,
|
Console.spinner(
|
||||||
spinner_foreground_color=ForegroundColorEnum.blue)
|
'Reading source files:',
|
||||||
Console.spinner('Creating internal packages:', self._create_packages,
|
self._read_sources,
|
||||||
text_foreground_color=ForegroundColorEnum.green,
|
text_foreground_color=ForegroundColorEnum.green,
|
||||||
spinner_foreground_color=ForegroundColorEnum.blue)
|
spinner_foreground_color=ForegroundColorEnum.blue
|
||||||
Console.spinner('Building application:', self._dist_files, text_foreground_color=ForegroundColorEnum.green,
|
)
|
||||||
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.write_line('\nPublish:')
|
||||||
Console.spinner('Generating setup.py:', self._create_setup, text_foreground_color=ForegroundColorEnum.green,
|
Console.spinner(
|
||||||
spinner_foreground_color=ForegroundColorEnum.blue)
|
'Generating setup.py:',
|
||||||
|
self._create_setup,
|
||||||
|
text_foreground_color=ForegroundColorEnum.green,
|
||||||
|
spinner_foreground_color=ForegroundColorEnum.blue
|
||||||
|
)
|
||||||
|
|
||||||
Console.write_line('Running setup.py:\n')
|
Console.write_line('Running setup.py:\n')
|
||||||
self._run_setup()
|
self._run_setup()
|
||||||
Console.spinner('Cleaning dist path:', self._clean_dist_files, text_foreground_color=ForegroundColorEnum.green,
|
Console.spinner(
|
||||||
spinner_foreground_color=ForegroundColorEnum.blue)
|
'Cleaning dist path:',
|
||||||
|
self._clean_dist_files,
|
||||||
|
text_foreground_color=ForegroundColorEnum.green,
|
||||||
|
spinner_foreground_color=ForegroundColorEnum.blue
|
||||||
|
)
|
||||||
|
@ -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.appsettings_json import AppsettingsTemplate
|
||||||
from cpl_cli.templates.new.console.license import LicenseTemplate
|
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.readme_py import ReadmeTemplate
|
||||||
from cpl_cli.templates.new.console.src.application import ApplicationTemplate
|
from cpl_cli.templates.new.console.src.name.application import ApplicationTemplate
|
||||||
from cpl_cli.templates.new.console.src.main import MainWithApplicationHostAndStartupTemplate, \
|
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
|
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.new.console.src.tests.init import TestsInitTemplate
|
||||||
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
||||||
|
|
||||||
@ -43,22 +44,23 @@ class ConsoleBuilder:
|
|||||||
LicenseTemplate(),
|
LicenseTemplate(),
|
||||||
ReadmeTemplate(),
|
ReadmeTemplate(),
|
||||||
TestsInitTemplate(),
|
TestsInitTemplate(),
|
||||||
AppsettingsTemplate()
|
AppsettingsTemplate(),
|
||||||
|
MainInitTemplate(project_name)
|
||||||
]
|
]
|
||||||
|
|
||||||
if use_application_api:
|
if use_application_api:
|
||||||
templates.append(ApplicationTemplate())
|
templates.append(ApplicationTemplate(project_name))
|
||||||
|
|
||||||
if use_startup:
|
if use_startup:
|
||||||
templates.append(StartupTemplate())
|
templates.append(StartupTemplate(project_name))
|
||||||
templates.append(MainWithApplicationHostAndStartupTemplate())
|
templates.append(MainWithApplicationHostAndStartupTemplate(project_name))
|
||||||
else:
|
else:
|
||||||
templates.append(MainWithApplicationBaseTemplate())
|
templates.append(MainWithApplicationBaseTemplate(project_name))
|
||||||
else:
|
else:
|
||||||
if use_service_providing:
|
if use_service_providing:
|
||||||
templates.append(MainWithDependencyInjection())
|
templates.append(MainWithDependencyInjection(project_name))
|
||||||
else:
|
else:
|
||||||
templates.append(MainWithoutApplicationBaseTemplate())
|
templates.append(MainWithoutApplicationBaseTemplate(project_name))
|
||||||
|
|
||||||
for template in templates:
|
for template in templates:
|
||||||
Console.spinner(
|
Console.spinner(
|
||||||
|
@ -1,15 +1,17 @@
|
|||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
|
from cpl.utils.string import String
|
||||||
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
||||||
|
|
||||||
|
|
||||||
class ApplicationTemplate(TemplateFileABC):
|
class ApplicationTemplate(TemplateFileABC):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, name: str):
|
||||||
TemplateFileABC.__init__(self)
|
TemplateFileABC.__init__(self)
|
||||||
|
|
||||||
|
name = String.convert_to_snake_case(name)
|
||||||
self._name = 'application.py'
|
self._name = 'application.py'
|
||||||
self._path = 'src/'
|
self._path = f'src/{name}/'
|
||||||
self._value = textwrap.dedent("""\
|
self._value = textwrap.dedent("""\
|
||||||
from cpl.application import ApplicationABC
|
from cpl.application import ApplicationABC
|
||||||
from cpl.configuration import ConfigurationABC
|
from cpl.configuration import ConfigurationABC
|
29
src/cpl_cli/templates/new/console/src/name/init.py
Normal file
29
src/cpl_cli/templates/new/console/src/name/init.py
Normal 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
|
@ -1,20 +1,22 @@
|
|||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
|
from cpl.utils.string import String
|
||||||
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
||||||
|
|
||||||
|
|
||||||
class MainWithApplicationHostAndStartupTemplate(TemplateFileABC):
|
class MainWithApplicationHostAndStartupTemplate(TemplateFileABC):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, name: str):
|
||||||
TemplateFileABC.__init__(self)
|
TemplateFileABC.__init__(self)
|
||||||
|
|
||||||
|
name = String.convert_to_snake_case(name)
|
||||||
self._name = 'main.py'
|
self._name = 'main.py'
|
||||||
self._path = 'src/'
|
self._path = f'src/{name}/'
|
||||||
self._value = textwrap.dedent("""\
|
self._value = textwrap.dedent(f"""\
|
||||||
from cpl.application import ApplicationBuilder
|
from cpl.application import ApplicationBuilder
|
||||||
|
|
||||||
from application import Application
|
from {name}.application import Application
|
||||||
from startup import Startup
|
from {name}.startup import Startup
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -42,15 +44,16 @@ class MainWithApplicationHostAndStartupTemplate(TemplateFileABC):
|
|||||||
|
|
||||||
class MainWithApplicationBaseTemplate(TemplateFileABC):
|
class MainWithApplicationBaseTemplate(TemplateFileABC):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, name: str):
|
||||||
TemplateFileABC.__init__(self)
|
TemplateFileABC.__init__(self)
|
||||||
|
|
||||||
|
name = String.convert_to_snake_case(name)
|
||||||
self._name = 'main.py'
|
self._name = 'main.py'
|
||||||
self._path = 'src/'
|
self._path = f'src/{name}'
|
||||||
self._value = textwrap.dedent("""\
|
self._value = textwrap.dedent(f"""\
|
||||||
from cpl.application import ApplicationBuilder
|
from cpl.application import ApplicationBuilder
|
||||||
|
|
||||||
from application import Application
|
from {name}.application import Application
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -77,11 +80,12 @@ class MainWithApplicationBaseTemplate(TemplateFileABC):
|
|||||||
|
|
||||||
class MainWithoutApplicationBaseTemplate(TemplateFileABC):
|
class MainWithoutApplicationBaseTemplate(TemplateFileABC):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, name: str):
|
||||||
TemplateFileABC.__init__(self)
|
TemplateFileABC.__init__(self)
|
||||||
|
|
||||||
|
name = String.convert_to_snake_case(name)
|
||||||
self._name = 'main.py'
|
self._name = 'main.py'
|
||||||
self._path = 'src/'
|
self._path = f'src/{name}'
|
||||||
self._value = textwrap.dedent("""\
|
self._value = textwrap.dedent("""\
|
||||||
from cpl.console import Console
|
from cpl.console import Console
|
||||||
|
|
||||||
@ -109,11 +113,12 @@ class MainWithoutApplicationBaseTemplate(TemplateFileABC):
|
|||||||
|
|
||||||
class MainWithDependencyInjection(TemplateFileABC):
|
class MainWithDependencyInjection(TemplateFileABC):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, name: str):
|
||||||
TemplateFileABC.__init__(self)
|
TemplateFileABC.__init__(self)
|
||||||
|
|
||||||
|
name = String.convert_to_snake_case(name)
|
||||||
self._name = 'main.py'
|
self._name = 'main.py'
|
||||||
self._path = 'src/'
|
self._path = f'src/{name}'
|
||||||
self._value = textwrap.dedent("""\
|
self._value = textwrap.dedent("""\
|
||||||
from cpl.configuration import Configuration, ConfigurationABC
|
from cpl.configuration import Configuration, ConfigurationABC
|
||||||
from cpl.console import Console
|
from cpl.console import Console
|
@ -1,15 +1,17 @@
|
|||||||
import textwrap
|
import textwrap
|
||||||
|
|
||||||
|
from cpl.utils.string import String
|
||||||
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
||||||
|
|
||||||
|
|
||||||
class StartupTemplate(TemplateFileABC):
|
class StartupTemplate(TemplateFileABC):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, name: str):
|
||||||
TemplateFileABC.__init__(self)
|
TemplateFileABC.__init__(self)
|
||||||
|
|
||||||
|
name = String.convert_to_snake_case(name)
|
||||||
self._name = 'startup.py'
|
self._name = 'startup.py'
|
||||||
self._path = 'src/'
|
self._path = f'src/{name}/'
|
||||||
self._value = textwrap.dedent("""\
|
self._value = textwrap.dedent("""\
|
||||||
from cpl.application import StartupABC
|
from cpl.application import StartupABC
|
||||||
from cpl.configuration import ConfigurationABC
|
from cpl.configuration import ConfigurationABC
|
@ -47,7 +47,7 @@ class MainWithApplicationBaseTemplate(TemplateFileABC):
|
|||||||
|
|
||||||
self._name = 'main.py'
|
self._name = 'main.py'
|
||||||
self._path = 'src/'
|
self._path = 'src/'
|
||||||
self._value = textwrap.dedent("""\
|
self._value = textwrap.dedent(f"""\
|
||||||
from cpl.application import ApplicationBuilder
|
from cpl.application import ApplicationBuilder
|
||||||
|
|
||||||
from {name}_cli.application import Application
|
from {name}_cli.application import Application
|
||||||
|
Loading…
Reference in New Issue
Block a user