From a6122536a634fd2493b76cdb047cf59825540f22 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Wed, 16 Dec 2020 18:14:11 +0100 Subject: [PATCH] Added publish command to cli --- src/sh_edraft/cli/cpl_cli/cli.py | 3 +- .../cli/cpl_cli/commands/publish/__init__.py | 25 ++++++++++ .../cli/cpl_cli/commands/publish/app.py | 48 +++++++++++++++++++ .../cli/cpl_cli/commands/publish/publish.py | 23 +++++++++ .../publishing/base/publisher_base.py | 5 +- src/sh_edraft/publishing/publisher.py | 15 +++++- src/tests_dev/publisher.py | 2 +- 7 files changed, 116 insertions(+), 5 deletions(-) create mode 100644 src/sh_edraft/cli/cpl_cli/commands/publish/__init__.py create mode 100644 src/sh_edraft/cli/cpl_cli/commands/publish/app.py create mode 100644 src/sh_edraft/cli/cpl_cli/commands/publish/publish.py diff --git a/src/sh_edraft/cli/cpl_cli/cli.py b/src/sh_edraft/cli/cpl_cli/cli.py index a1eb8a70..f0728d13 100644 --- a/src/sh_edraft/cli/cpl_cli/cli.py +++ b/src/sh_edraft/cli/cpl_cli/cli.py @@ -1,10 +1,10 @@ import sys import traceback -from typing import Optional from sh_edraft.cli.cpl_cli.commands.build.build import Build from sh_edraft.cli.cpl_cli.commands.help import Help from sh_edraft.cli.cpl_cli.commands.new import New +from sh_edraft.cli.cpl_cli.commands.publish.publish import Publish from sh_edraft.cli.cpl_cli.commands.version import Version from sh_edraft.cli.interpreter.interpreter import Interpreter from sh_edraft.console.console import Console @@ -19,6 +19,7 @@ class CLI: self._interpreter.add_command(Build()) self._interpreter.add_command(Help()) self._interpreter.add_command(New()) + self._interpreter.add_command(Publish()) self._interpreter.add_command(Version()) def main(self): diff --git a/src/sh_edraft/cli/cpl_cli/commands/publish/__init__.py b/src/sh_edraft/cli/cpl_cli/commands/publish/__init__.py new file mode 100644 index 00000000..3963f7a7 --- /dev/null +++ b/src/sh_edraft/cli/cpl_cli/commands/publish/__init__.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- + +""" +sh_edraft.cli.cpl_cli.commands.publish +~~~~~~~~~~~~~~~~~~~ + + + +:copyright: (c) 2020 sh-edraft.de +:license: MIT, see LICENSE for more details. + +""" + +__title__ = 'sh_edraft.cli.cpl_cli.commands.publish' +__author__ = 'Sven Heidemann' +__license__ = 'MIT' +__copyright__ = 'Copyright (c) 2020 sh-edraft.de' +__version__ = '2020.12.9' + +from collections import namedtuple + +# imports: + +VersionInfo = namedtuple('VersionInfo', 'major minor micro') +version_info = VersionInfo(major=2020, minor=12, micro=9) diff --git a/src/sh_edraft/cli/cpl_cli/commands/publish/app.py b/src/sh_edraft/cli/cpl_cli/commands/publish/app.py new file mode 100644 index 00000000..c7ce661a --- /dev/null +++ b/src/sh_edraft/cli/cpl_cli/commands/publish/app.py @@ -0,0 +1,48 @@ +from typing import Optional + +from sh_edraft.configuration.base.configuration_base import ConfigurationBase +from sh_edraft.hosting.application_host import ApplicationHost +from sh_edraft.hosting.base.application_base import ApplicationBase +from sh_edraft.logging.logger import Logger +from sh_edraft.logging.base.logger_base import LoggerBase +from sh_edraft.publishing.publisher import Publisher +from sh_edraft.publishing.base.publisher_base import PublisherBase +from sh_edraft.service.providing.base.service_provider_base import ServiceProviderBase + + +class PublishApp(ApplicationBase): + + def __init__(self): + ApplicationBase.__init__(self) + + self._app_host: Optional[ApplicationHost] = None + self._services: Optional[ServiceProviderBase] = None + self._configuration: Optional[ConfigurationBase] = None + self._logger: Optional[LoggerBase] = None + self._publisher: Optional[PublisherBase] = None + + def create_application_host(self): + self._app_host = ApplicationHost() + self._configuration = self._app_host.configuration + self._services = self._app_host.services + + def create_configuration(self): + self._configuration.add_json_file(f'build.json') + + def create_services(self): + # Add and create logger + self._services.add_singleton(LoggerBase, Logger) + self._logger = self._services.get_service(LoggerBase) + + # Add and create publisher + self._services.add_singleton(PublisherBase, Publisher) + self._publisher: Publisher = self._services.get_service(PublisherBase) + + def main(self): + self._logger.header(f'{self._configuration.environment.application_name}:') + self._logger.debug(__name__, f'Host: {self._configuration.environment.host_name}') + self._logger.debug(__name__, f'Environment: {self._configuration.environment.environment_name}') + self._logger.debug(__name__, f'Customer: {self._configuration.environment.customer}') + self._publisher.create() + self._publisher.build() + self._publisher.publish() diff --git a/src/sh_edraft/cli/cpl_cli/commands/publish/publish.py b/src/sh_edraft/cli/cpl_cli/commands/publish/publish.py new file mode 100644 index 00000000..f21c331e --- /dev/null +++ b/src/sh_edraft/cli/cpl_cli/commands/publish/publish.py @@ -0,0 +1,23 @@ +from sh_edraft.cli.command.base.command_base import CommandBase +from sh_edraft.cli.cpl_cli.commands.publish.app import PublishApp +from sh_edraft.console.console import Console + + +class Publish(CommandBase): + + def __init__(self): + CommandBase.__init__(self) + self._app = PublishApp() + + self._aliases.append('-b') + self._aliases.append('-B') + + def run(self, args: list[str]): + if len(args) > 0: + Console.error(f'Invalid arguments {args}') + Console.error('Run \'cpl help\'') + + self._app.create_application_host() + self._app.create_configuration() + self._app.create_services() + self._app.main() diff --git a/src/sh_edraft/publishing/base/publisher_base.py b/src/sh_edraft/publishing/base/publisher_base.py index f3f899ca..092dec3d 100644 --- a/src/sh_edraft/publishing/base/publisher_base.py +++ b/src/sh_edraft/publishing/base/publisher_base.py @@ -24,4 +24,7 @@ class PublisherBase(ServiceBase): def exclude(self, path: str): pass @abstractmethod - def publish(self) -> str: pass + def build(self): pass + + @abstractmethod + def publish(self): pass diff --git a/src/sh_edraft/publishing/publisher.py b/src/sh_edraft/publishing/publisher.py index 7bb9fa87..9a9a1518 100644 --- a/src/sh_edraft/publishing/publisher.py +++ b/src/sh_edraft/publishing/publisher.py @@ -2,6 +2,8 @@ import os import shutil from string import Template as stringTemplate +from setuptools import sandbox + from sh_edraft.logging.base.logger_base import LoggerBase from sh_edraft.publishing.base.publisher_base import PublisherBase from sh_edraft.publishing.model.publish_settings_model import PublishSettings @@ -255,8 +257,17 @@ class Publisher(PublisherBase): self._create_dist_path() self._logger.trace(__name__, f'Stopped {__name__}.create') - def publish(self): - self._logger.trace(__name__, f'Started {__name__}.publish') + def build(self): + self._logger.trace(__name__, f'Started {__name__}.build') self._write_templates() self._copy_all_included_files() + self._logger.trace(__name__, f'Stopped {__name__}.build') + + def publish(self): + self._logger.trace(__name__, f'Started {__name__}.publish') + setup_py = os.path.join(self._publish_settings.dist_path, 'setup.py') + if not os.path.isfile(setup_py): + self._logger.fatal(__name__, f'setup.py not found in {self._publish_settings.dist_path}') + + sandbox.run_setup(os.path.abspath(setup_py), ['sdist', 'bdist_wheel']) self._logger.trace(__name__, f'Stopped {__name__}.publish') diff --git a/src/tests_dev/publisher.py b/src/tests_dev/publisher.py index f9eea080..06b75735 100644 --- a/src/tests_dev/publisher.py +++ b/src/tests_dev/publisher.py @@ -54,7 +54,7 @@ class Program(ApplicationBase): self._publisher.include('../../README.MD') self._publisher.include('../../requirements.txt') self._publisher.create() - self._publisher.publish() + self._publisher.build() if __name__ == '__main__':