From b931ba6e17ff88fc6b319b1d899e0891bc99c31d Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 19 May 2021 08:01:02 +0200 Subject: [PATCH] Fixed source creation bug --- src/cpl/configuration/configuration_abc.py | 4 ++-- .../new/console/source/name/application.py | 5 +---- .../new/console/source/name/init.py | 5 +---- .../new/console/source/name/main.py | 17 ++++------------ .../new/console/source/name/startup.py | 5 +---- .../new/library/source/name/application.py | 5 +---- .../new/library/source/name/init.py | 5 +---- .../new/library/source/name/main.py | 20 ++++--------------- .../new/library/source/name/startup.py | 5 +---- src/cpl_cli/command_handler_service.py | 3 ++- src/cpl_cli/live_server/live_server_thread.py | 2 ++ src/cpl_cli/source_creator/console_builder.py | 12 +++++------ src/cpl_cli/source_creator/library_builder.py | 5 ++--- .../source_creator/template_builder.py | 6 +++--- 14 files changed, 31 insertions(+), 68 deletions(-) diff --git a/src/cpl/configuration/configuration_abc.py b/src/cpl/configuration/configuration_abc.py index 046eb055..61498d70 100644 --- a/src/cpl/configuration/configuration_abc.py +++ b/src/cpl/configuration/configuration_abc.py @@ -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 diff --git a/src/cpl_cli/_templates/new/console/source/name/application.py b/src/cpl_cli/_templates/new/console/source/name/application.py index 56fa6729..934f0522 100644 --- a/src/cpl_cli/_templates/new/console/source/name/application.py +++ b/src/cpl_cli/_templates/new/console/source/name/application.py @@ -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 diff --git a/src/cpl_cli/_templates/new/console/source/name/init.py b/src/cpl_cli/_templates/new/console/source/name/init.py index 83956b6e..b3cbdecb 100644 --- a/src/cpl_cli/_templates/new/console/source/name/init.py +++ b/src/cpl_cli/_templates/new/console/source/name/init.py @@ -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: """) diff --git a/src/cpl_cli/_templates/new/console/source/name/main.py b/src/cpl_cli/_templates/new/console/source/name/main.py index 716e80c3..861258a1 100644 --- a/src/cpl_cli/_templates/new/console/source/name/main.py +++ b/src/cpl_cli/_templates/new/console/source/name/main.py @@ -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 diff --git a/src/cpl_cli/_templates/new/console/source/name/startup.py b/src/cpl_cli/_templates/new/console/source/name/startup.py index f60f6f7e..6e68b355 100644 --- a/src/cpl_cli/_templates/new/console/source/name/startup.py +++ b/src/cpl_cli/_templates/new/console/source/name/startup.py @@ -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 diff --git a/src/cpl_cli/_templates/new/library/source/name/application.py b/src/cpl_cli/_templates/new/library/source/name/application.py index 9dd7917c..934f0522 100644 --- a/src/cpl_cli/_templates/new/library/source/name/application.py +++ b/src/cpl_cli/_templates/new/library/source/name/application.py @@ -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 diff --git a/src/cpl_cli/_templates/new/library/source/name/init.py b/src/cpl_cli/_templates/new/library/source/name/init.py index dcbbccb0..a3b0b8ea 100644 --- a/src/cpl_cli/_templates/new/library/source/name/init.py +++ b/src/cpl_cli/_templates/new/library/source/name/init.py @@ -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: """) diff --git a/src/cpl_cli/_templates/new/library/source/name/main.py b/src/cpl_cli/_templates/new/library/source/name/main.py index 402ffabc..5d43bf3a 100644 --- a/src/cpl_cli/_templates/new/library/source/name/main.py +++ b/src/cpl_cli/_templates/new/library/source/name/main.py @@ -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 diff --git a/src/cpl_cli/_templates/new/library/source/name/startup.py b/src/cpl_cli/_templates/new/library/source/name/startup.py index 8c037860..6e68b355 100644 --- a/src/cpl_cli/_templates/new/library/source/name/startup.py +++ b/src/cpl_cli/_templates/new/library/source/name/startup.py @@ -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 diff --git a/src/cpl_cli/command_handler_service.py b/src/cpl_cli/command_handler_service.py index 62d0c73c..852345fd 100644 --- a/src/cpl_cli/command_handler_service.py +++ b/src/cpl_cli/command_handler_service.py @@ -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 diff --git a/src/cpl_cli/live_server/live_server_thread.py b/src/cpl_cli/live_server/live_server_thread.py index 183d8703..0a32b5c1 100644 --- a/src/cpl_cli/live_server/live_server_thread.py +++ b/src/cpl_cli/live_server/live_server_thread.py @@ -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)}' diff --git a/src/cpl_cli/source_creator/console_builder.py b/src/cpl_cli/source_creator/console_builder.py index 3636df0a..4633d821 100644 --- a/src/cpl_cli/source_creator/console_builder.py +++ b/src/cpl_cli/source_creator/console_builder.py @@ -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: diff --git a/src/cpl_cli/source_creator/library_builder.py b/src/cpl_cli/source_creator/library_builder.py index 7fdfc018..6e6d9a4b 100644 --- a/src/cpl_cli/source_creator/library_builder.py +++ b/src/cpl_cli/source_creator/library_builder.py @@ -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)) diff --git a/src/cpl_cli/source_creator/template_builder.py b/src/cpl_cli/source_creator/template_builder.py index 8a498af7..20939a64 100644 --- a/src/cpl_cli/source_creator/template_builder.py +++ b/src/cpl_cli/source_creator/template_builder.py @@ -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()