Fixed source creation bug

This commit is contained in:
Sven Heidemann 2021-05-19 08:01:02 +02:00
parent f611aa73db
commit b931ba6e17
14 changed files with 31 additions and 68 deletions

View File

@ -81,14 +81,14 @@ class ConfigurationABC(ABC):
pass
@abstractmethod
def add_configuration(self, key_type: Union[str, type], value: ConfigurationModelABC):
def add_configuration(self, key_type: Union[str, type], value: Union[str, ConfigurationModelABC]):
r"""Add configuration object
Parameter
---------
key_type: Union[:class:`str`, :class:`type`]
Type of the value
value: :class:`cpl.configuration.configuration_model_abc.ConfigurationModelABC`
value: Union[:class:`str`, :class:`cpl.configuration.configuration_model_abc.ConfigurationModelABC`]
Object of the value
"""
pass

View File

@ -1,7 +1,5 @@
import os.path
import textwrap
from cpl.utils.string import String
from cpl_cli._templates.template_file_abc import TemplateFileABC
@ -10,9 +8,8 @@ class ApplicationTemplate(TemplateFileABC):
def __init__(self, name: str, path: str):
TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name)
self._name = 'application.py'
self._path = os.path.join(path, name)
self._path = path
self._value = textwrap.dedent("""\
from cpl.application import ApplicationABC
from cpl.configuration import ConfigurationABC

View File

@ -1,7 +1,5 @@
import os.path
import textwrap
from cpl.utils.string import String
from cpl_cli._templates.template_file_abc import TemplateFileABC
@ -10,9 +8,8 @@ class MainInitTemplate(TemplateFileABC):
def __init__(self, name: str, path: str):
TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name)
self._name = '__init__.py'
self._path = os.path.join(path, name)
self._path = path
self._value = textwrap.dedent("""\
# imports:
""")

View File

@ -1,4 +1,3 @@
import os.path
import textwrap
from cpl.utils.string import String
@ -12,11 +11,9 @@ class MainWithApplicationHostAndStartupTemplate(TemplateFileABC):
name = String.convert_to_snake_case(name)
self._name = 'main.py'
self._path = os.path.join(path, name)
self._path = path
import_pkg = f'{name}.'
if name == '':
import_pkg = ''
self._value = textwrap.dedent(f"""\
from cpl.application import ApplicationBuilder
@ -55,11 +52,9 @@ class MainWithApplicationBaseTemplate(TemplateFileABC):
name = String.convert_to_snake_case(name)
self._name = 'main.py'
self._path = os.path.join(path, name)
self._path = path
import_pkg = f'{name}.'
if name == '':
import_pkg = ''
self._value = textwrap.dedent(f"""\
from cpl.application import ApplicationBuilder
@ -96,11 +91,9 @@ class MainWithoutApplicationBaseTemplate(TemplateFileABC):
name = String.convert_to_snake_case(name)
self._name = 'main.py'
self._path = os.path.join(path, name)
self._path = path
import_pkg = f'{name}.'
if name == '':
import_pkg = ''
self._value = textwrap.dedent("""\
from cpl.console import Console
@ -134,11 +127,9 @@ class MainWithDependencyInjection(TemplateFileABC):
name = String.convert_to_snake_case(name)
self._name = 'main.py'
self._path = os.path.join(path, name)
self._path = path
import_pkg = f'{name}.'
if name == '':
import_pkg = ''
self._value = textwrap.dedent("""\
from cpl.configuration import Configuration, ConfigurationABC

View File

@ -1,7 +1,5 @@
import os.path
import textwrap
from cpl.utils.string import String
from cpl_cli._templates.template_file_abc import TemplateFileABC
@ -10,9 +8,8 @@ class StartupTemplate(TemplateFileABC):
def __init__(self, name: str, path: str):
TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name)
self._name = 'startup.py'
self._path = os.path.join(path, name)
self._path = path
self._value = textwrap.dedent("""\
from cpl.application import StartupABC
from cpl.configuration import ConfigurationABC

View File

@ -1,7 +1,5 @@
import os
import textwrap
from cpl.utils.string import String
from cpl_cli._templates.template_file_abc import TemplateFileABC
@ -10,9 +8,8 @@ class ApplicationTemplate(TemplateFileABC):
def __init__(self, name: str, path: str):
TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name)
self._name = 'application.py'
self._path = os.path.join(path, name)
self._path = path
self._value = textwrap.dedent("""\
from cpl.application import ApplicationABC
from cpl.configuration import ConfigurationABC

View File

@ -1,7 +1,5 @@
import os
import textwrap
from cpl.utils.string import String
from cpl_cli._templates.template_file_abc import TemplateFileABC
@ -10,9 +8,8 @@ class NameInitTemplate(TemplateFileABC):
def __init__(self, name: str, path: str):
TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name)
self._name = '__init__.py'
self._path = os.path.join(path, name)
self._path = path
self._value = textwrap.dedent("""\
# imports:
""")

View File

@ -1,7 +1,5 @@
import os.path
import textwrap
from cpl.utils.string import String
from cpl_cli._templates.template_file_abc import TemplateFileABC
@ -10,9 +8,8 @@ class MainWithApplicationHostAndStartupTemplate(TemplateFileABC):
def __init__(self, name: str, path: str):
TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name)
self._name = 'main.py'
self._path = os.path.join(path, name)
self._path = path
import_pkg = f'{name}.'
if name == '':
@ -53,9 +50,8 @@ class MainWithApplicationBaseTemplate(TemplateFileABC):
def __init__(self, name: str, path: str):
TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name)
self._name = 'main.py'
self._path = os.path.join(path, name)
self._path = path
import_pkg = f'{name}.'
if name == '':
@ -95,11 +91,7 @@ class MainWithoutApplicationBaseTemplate(TemplateFileABC):
TemplateFileABC.__init__(self)
self._name = 'main.py'
self._path = os.path.join(path, name)
import_pkg = f'{name}.'
if name == '':
import_pkg = ''
self._path = path
self._value = textwrap.dedent("""\
from cpl.console import Console
@ -132,11 +124,7 @@ class MainWithDependencyInjection(TemplateFileABC):
TemplateFileABC.__init__(self)
self._name = 'main.py'
self._path = os.path.join(path, name)
import_pkg = f'{name}.'
if name == '':
import_pkg = ''
self._path = path
self._value = textwrap.dedent("""\
from cpl.configuration import Configuration, ConfigurationABC

View File

@ -1,7 +1,5 @@
import os
import textwrap
from cpl.utils.string import String
from cpl_cli._templates.template_file_abc import TemplateFileABC
@ -10,9 +8,8 @@ class StartupTemplate(TemplateFileABC):
def __init__(self, name: str, path: str):
TemplateFileABC.__init__(self)
name = String.convert_to_snake_case(name)
self._name = 'startup.py'
self._path = os.path.join(path, name)
self._path = path
self._value = textwrap.dedent("""\
from cpl.application import StartupABC
from cpl.configuration import ConfigurationABC

View File

@ -67,7 +67,8 @@ class CommandHandler(ABC):
if file.endswith('.json'):
f_name = file.split('.json')[0]
if f_name == name or \
String.convert_to_camel_case(f_name) == String.convert_to_camel_case(name):
String.convert_to_camel_case(f_name).lower() == String.convert_to_camel_case(
name).lower():
project_name = f_name
break

View File

@ -70,6 +70,8 @@ class LiveServerThread(threading.Thread):
Console.error('Entry point main.py not found')
return
# set cwd to src/
self._env.set_working_directory(os.path.abspath(os.path.join(self._path, '../')))
if sys.platform == 'win32':
self._env_vars['PYTHONPATH'] = f'{self._env.working_directory};' \
f'{os.path.join(self._env.working_directory, self._build_settings.source_path)}'

View File

@ -97,10 +97,9 @@ class ConsoleBuilder:
os.makedirs(project_path)
src_rel_path = ''
src_name = ''
src_name = project_name_snake
if workspace is None:
src_rel_path = 'src/'
src_name = project_name_snake
src_rel_path = os.path.join('src/', src_name)
if use_application_api:
templates.append(ApplicationTemplate(src_name, src_rel_path))
@ -122,11 +121,12 @@ class ConsoleBuilder:
project_file_path = f'{project_name_snake}/{project_name}.json'
if workspace is None:
src_path = f'{proj_name}/src/{project_name_snake}'
src_path = f'src/{project_name_snake}'
workspace_file_path = f'{proj_name}/cpl-workspace.json'
project_file_path = f'{src_path}/{project_name}.json'
project_file_rel_path = f'{src_path}/{project_name}.json'
project_file_path = f'{proj_name}/{src_path}/{project_name}.json'
cls._create_workspace(workspace_file_path, project_name, {
project_name: project_file_path
project_name: project_file_rel_path
})
else:

View File

@ -98,10 +98,9 @@ class LibraryBuilder:
os.makedirs(project_path)
src_rel_path = ''
src_name = ''
src_name = project_name_snake
if workspace is None:
src_rel_path = 'src/'
src_name = project_name_snake
src_rel_path = os.path.join('src/', src_name)
if use_application_api:
templates.append(ApplicationTemplate(src_name, src_rel_path))

View File

@ -19,6 +19,6 @@ class TemplateBuilder:
if not os.path.isdir(file_rel_path):
os.makedirs(file_rel_path)
with open(file_path, 'w') as license_file:
license_file.write(template.value)
license_file.close()
with open(file_path, 'w') as file:
file.write(template.value)
file.close()