From 1bff2ea1685ca463785e56e597d1972862b8a77f Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 10 Mar 2021 14:07:52 +0100 Subject: [PATCH] Refactoring --- src/cpl_cli/command/help.py | 2 +- src/cpl_cli/command/new.py | 7 ++++--- src/cpl_cli/publish/publisher.py | 20 +++++++++---------- .../build/{init.py => init_template.py} | 2 +- .../publish/{setup.py => setup_template.py} | 2 +- 5 files changed, 17 insertions(+), 16 deletions(-) rename src/cpl_cli/templates/build/{init.py => init_template.py} (97%) rename src/cpl_cli/templates/publish/{setup.py => setup_template.py} (97%) diff --git a/src/cpl_cli/command/help.py b/src/cpl_cli/command/help.py index 065b12c6..1a16f922 100644 --- a/src/cpl_cli/command/help.py +++ b/src/cpl_cli/command/help.py @@ -15,7 +15,7 @@ class Help(CommandABC): ['help (h|H)', 'Lists available command and their short descriptions.'], ['new (n|N)', 'Creates new CPL project.'], ['start (s|S)', 'Starts CPL project, restarting on file changes'], - ['publish (p|P)', 'Prepares files for publish into an output directory named dist/ at the given output path and executes setup.py. Must be executed from within a workspace directory.'], + ['publish (p|P)', 'Prepares files for publish into an output directory named dist/ at the given output path and executes setup_template.py. Must be executed from within a workspace directory.'], ['update (u|u)', 'Update CPL and project dependencies.'], ['version (v|V)', 'Outputs CPL CLI version.'] ] diff --git a/src/cpl_cli/command/new.py b/src/cpl_cli/command/new.py index 59e8d3af..1b753b77 100644 --- a/src/cpl_cli/command/new.py +++ b/src/cpl_cli/command/new.py @@ -104,9 +104,10 @@ class New(CommandABC): if result.lower() == 'y': self._use_startup = True - # result = Console.read('Do you want to use service providing? (y/n) ') - # if result.lower() == 'y': - # self._use_service_providing = True + # else: + # result = Console.read('Do you want to use service providing? (y/n) ') + # if result.lower() == 'y': + # self._use_service_providing = True def _build_project_dir(self, project_path: str): if not os.path.isdir(project_path): diff --git a/src/cpl_cli/publish/publisher.py b/src/cpl_cli/publish/publisher.py index 0b0aa09c..58b8b12d 100644 --- a/src/cpl_cli/publish/publisher.py +++ b/src/cpl_cli/publish/publisher.py @@ -11,8 +11,8 @@ from cpl.console.console import Console from cpl_cli.configuration.build_settings import BuildSettings from cpl_cli.configuration.project_settings import ProjectSettings from cpl_cli.publish.publisher_abc import PublisherABC -from cpl_cli.templates.build.init import Init -from cpl_cli.templates.publish.setup import Setup +from cpl_cli.templates.build.init_template import InitTemplate +from cpl_cli.templates.publish.setup_template import SetupTemplate class Publisher(PublisherABC): @@ -146,7 +146,7 @@ class Publisher(PublisherABC): if len(module_py_lines) > 0: imports = '\n'.join(module_py_lines) - template_content = stringTemplate(Init.get_init_py()).substitute( + template_content = stringTemplate(InitTemplate.get_init_py()).substitute( Name=self._project_settings.name, Description=self._project_settings.description, LongDescription=self._project_settings.long_description, @@ -224,7 +224,7 @@ class Publisher(PublisherABC): return paths def _create_setup(self): - setup_file = os.path.join(self._output_path, 'setup.py') + setup_file = os.path.join(self._output_path, 'setup_template.py') if os.path.isfile(setup_file): os.remove(setup_file) @@ -239,7 +239,7 @@ class Publisher(PublisherABC): return with open(setup_file, 'w+') as setup_py: - setup_string = stringTemplate(Setup.get_setup_py()).substitute( + setup_string = stringTemplate(SetupTemplate.get_setup_py()).substitute( Name=self._project_settings.name, Version=self._project_settings.version.to_str(), Packages=setuptools.find_packages(where=self._output_path, exclude=self._build_settings.excluded), @@ -262,9 +262,9 @@ class Publisher(PublisherABC): setup_py.close() def _run_setup(self): - setup_py = os.path.join(self._output_path, 'setup.py') + setup_py = os.path.join(self._output_path, 'setup_template.py') if not os.path.isfile(setup_py): - Console.error(__name__, f'setup.py not found in {self._output_path}') + Console.error(__name__, f'setup_template.py not found in {self._output_path}') return try: @@ -277,7 +277,7 @@ class Publisher(PublisherABC): ]) os.remove(setup_py) except Exception as e: - Console.error('Executing setup.py failed', str(e)) + Console.error('Executing setup_template.py failed', str(e)) def include(self, path: str): self._build_settings.included.append(path) @@ -301,7 +301,7 @@ class Publisher(PublisherABC): Console.spinner('Building application:', self._dist_files) Console.write_line('\nPublish:') - Console.spinner('Generating setup.py:', self._create_setup) - Console.write_line('Running setup.py:\n') + Console.spinner('Generating setup_template.py:', self._create_setup) + Console.write_line('Running setup_template.py:\n') self._run_setup() Console.spinner('Cleaning dist path:', self._clean_dist_files) diff --git a/src/cpl_cli/templates/build/init.py b/src/cpl_cli/templates/build/init_template.py similarity index 97% rename from src/cpl_cli/templates/build/init.py rename to src/cpl_cli/templates/build/init_template.py index 0d74cc11..e249d74f 100644 --- a/src/cpl_cli/templates/build/init.py +++ b/src/cpl_cli/templates/build/init_template.py @@ -1,7 +1,7 @@ import textwrap -class Init: +class InitTemplate: @staticmethod def get_init_py() -> str: diff --git a/src/cpl_cli/templates/publish/setup.py b/src/cpl_cli/templates/publish/setup_template.py similarity index 97% rename from src/cpl_cli/templates/publish/setup.py rename to src/cpl_cli/templates/publish/setup_template.py index 315f9bef..abae3251 100644 --- a/src/cpl_cli/templates/publish/setup.py +++ b/src/cpl_cli/templates/publish/setup_template.py @@ -1,7 +1,7 @@ import textwrap -class Setup: +class SetupTemplate: @staticmethod def get_setup_py() -> str: