2021.4.1 #11

Merged
edraft merged 172 commits from 2021.04.01 into 2021.04 2021-03-21 20:04:24 +01:00
13 changed files with 205 additions and 15 deletions
Showing only changes of commit 314049f22b - Show all commits

View File

@ -1,9 +1,19 @@
prefix: cpl prefix: cpl
commands: commands:
new: build
app
base generate:
class abc | a
configmodel class | c
enum configmodel | cm
service enum | e
service | s
help
new
console
start
publish
update
version

View File

@ -1,4 +1,7 @@
/docs/
/src/ /src/
/src/assets
/src/tests
/.gitignore /.gitignore
/cpl.json /cpl.json
/LICENSE /LICENSE

View File

@ -1,4 +0,0 @@
from cpl_cli.main import main
if __name__ == '__main__':
main()

View File

@ -2,6 +2,7 @@ from typing import Optional
from cpl.application.application_abc import ApplicationABC from cpl.application.application_abc import ApplicationABC
from cpl_cli.command.build import Build from cpl_cli.command.build import Build
from cpl_cli.command.new import New
from cpl_cli.command.publish import Publish from cpl_cli.command.publish import Publish
from cpl_cli.command_handler import CommandHandler from cpl_cli.command_handler import CommandHandler
from cpl_cli.command_model import CommandModel from cpl_cli.command_model import CommandModel
@ -22,6 +23,7 @@ class CLI(ApplicationABC):
self._command_handler.add_command(CommandModel('build', ['h', 'B'], Build, True)) self._command_handler.add_command(CommandModel('build', ['h', 'B'], Build, True))
self._command_handler.add_command(CommandModel('help', ['h', 'H'], Help, False)) self._command_handler.add_command(CommandModel('help', ['h', 'H'], Help, False))
self._command_handler.add_command(CommandModel('new', ['n', 'N'], New, False))
self._command_handler.add_command(CommandModel('publish', ['p', 'P'], Publish, True)) self._command_handler.add_command(CommandModel('publish', ['p', 'P'], Publish, True))
self._command_handler.add_command(CommandModel('version', ['v', 'V'], Version, False)) self._command_handler.add_command(CommandModel('version', ['v', 'V'], Version, False))

View File

@ -0,0 +1,109 @@
import json
import os
import sys
from distutils.dir_util import copy_tree
from cpl.application.application_runtime_abc import ApplicationRuntimeABC
from cpl.configuration.configuration_abc import ConfigurationABC
from cpl.console.console import Console
from cpl_cli.command_abc import CommandABC
from cpl_cli.configuration.build_settings import BuildSettings
from cpl_cli.configuration.build_settings_name import BuildSettingsName
from cpl_cli.configuration.project_settings import ProjectSettings
from cpl_cli.configuration.project_settings_name import ProjectSettingsName
from cpl_cli.configuration.version_settings_name import VersionSettingsName
class New(CommandABC):
def __init__(self, configuration: ConfigurationABC, runtime: ApplicationRuntimeABC):
CommandABC.__init__(self)
self._config = configuration
self._runtime = runtime
self._project: ProjectSettings = ProjectSettings()
self._project_dict = {}
self._build: BuildSettings = BuildSettings()
self._build_dict = {}
self._project_json = {}
self._command: str = ''
def _create_project_settings(self, name: str):
self._project_dict = {
ProjectSettingsName.name.value: name,
ProjectSettingsName.version.value: {
VersionSettingsName.major.value: '0',
VersionSettingsName.minor.value: '0',
VersionSettingsName.micro.value: '0'
},
ProjectSettingsName.author.value: '',
ProjectSettingsName.author_email.value: '',
ProjectSettingsName.description.value: '',
ProjectSettingsName.long_description.value: '',
ProjectSettingsName.url.value: '',
ProjectSettingsName.copyright_date.value: '',
ProjectSettingsName.copyright_name.value: '',
ProjectSettingsName.license_name.value: '',
ProjectSettingsName.license_description.value: '',
ProjectSettingsName.dependencies.value: [],
ProjectSettingsName.python_version.value: f'>={sys.version.split(" ")[0]}'
}
self._project.from_dict(self._project_dict)
def _create_build_settings(self):
self._build_dict = {
BuildSettingsName.source_path.value: 'src',
BuildSettingsName.output_path.value: 'dist',
BuildSettingsName.main.value: 'main',
BuildSettingsName.entry_point.value: self._project.name,
BuildSettingsName.include_package_data.value: 'False',
BuildSettingsName.included.value: [],
BuildSettingsName.excluded.value: [
'*/__pycache__',
'*/logs',
'*/tests'
],
BuildSettingsName.package_data.value: {}
}
self._build.from_dict(self._build_dict)
def _create_project_json(self):
self._project_json = {
ProjectSettings.__name__: self._project_dict,
BuildSettings.__name__: self._build_dict
}
def _create_project_dir(self):
project_path = os.path.join(self._runtime.working_directory, self._project.name)
if os.path.isdir(project_path) and len(os.listdir(project_path)) > 0:
Console.error('Project path is not empty\n')
exit()
if not os.path.isdir(project_path):
os.makedirs(project_path)
with open(os.path.join(project_path, 'cpl.json'), 'w') as project_json:
project_json.write(json.dumps(self._project_json, indent=4))
project_json.close()
template_path = os.path.join(self._runtime.runtime_directory, f'templates/new/{self._command}')
if not os.path.isdir(template_path):
Console.error(template_path, '\n\nTemplate path not found\n')
exit()
copy_tree(template_path, project_path)
def _console(self, args: list[str]):
name = self._config.get_configuration(self._command)
self._create_project_settings(name)
self._create_build_settings()
self._create_project_json()
self._create_project_dir()
def run(self, args: list[str]):
self._command = args[0]
if self._command == 'console':
self._console(args)

View File

@ -7,3 +7,7 @@ def main():
cli.use_startup(Startup) cli.use_startup(Startup)
cli.build() cli.build()
cli.run() cli.run()
if __name__ == '__main__':
main()

View File

@ -3,9 +3,11 @@ from typing import Optional
from cpl.application.application_host import ApplicationHost from cpl.application.application_host import ApplicationHost
from cpl.application.application_host_abc import ApplicationHostABC from cpl.application.application_host_abc import ApplicationHostABC
from cpl.application.startup_abc import StartupABC from cpl.application.startup_abc import StartupABC
from cpl.configuration.console_argument import ConsoleArgument
from cpl.configuration.configuration_abc import ConfigurationABC from cpl.configuration.configuration_abc import ConfigurationABC
from cpl.dependency_injection.service_provider_abc import ServiceProviderABC from cpl.dependency_injection.service_provider_abc import ServiceProviderABC
from cpl_cli.command.build import Build from cpl_cli.command.build import Build
from cpl_cli.command.new import New
from cpl_cli.command.publish import Publish from cpl_cli.command.publish import Publish
from cpl_cli.command_handler import CommandHandler from cpl_cli.command_handler import CommandHandler
from cpl_cli.command.help import Help from cpl_cli.command.help import Help
@ -39,10 +41,13 @@ class Startup(StartupABC):
self._configuration.add_environment_variables('PYTHON_') self._configuration.add_environment_variables('PYTHON_')
self._configuration.add_environment_variables('CPL_') self._configuration.add_environment_variables('CPL_')
self._configuration.add_json_file('cpl.json', optional=True, output=False) self._configuration.add_json_file('cpl.json', optional=True, output=False)
self._configuration.add_console_argument('', 'build', ['-b', '-B'], '') self._configuration.add_console_argument(ConsoleArgument('', 'build', ['b', 'B'], ''))
self._configuration.add_console_argument('', 'help', ['-h', '-H'], '') self._configuration.add_console_argument(ConsoleArgument('', 'help', ['h', 'H'], ''))
self._configuration.add_console_argument('', 'publish', ['-p', '-P'], '') self._configuration.add_console_argument(ConsoleArgument('', 'new', ['n', 'N'], '', [
self._configuration.add_console_argument('', 'version', ['-v', '-V'], '') ConsoleArgument('', 'console', ['c', 'C'], ' ')
]))
self._configuration.add_console_argument(ConsoleArgument('', 'publish', ['p', 'P'], ''))
self._configuration.add_console_argument(ConsoleArgument('', 'version', ['v', 'V'], ''))
self._configuration.add_console_arguments() self._configuration.add_console_arguments()
return self._configuration return self._configuration
@ -54,6 +59,7 @@ class Startup(StartupABC):
self._services.add_transient(Build) self._services.add_transient(Build)
self._services.add_transient(Help) self._services.add_transient(Help)
self._services.add_transient(New)
self._services.add_transient(Publish) self._services.add_transient(Publish)
self._services.add_transient(Version) self._services.add_transient(Version)

View File

@ -0,0 +1,14 @@
from cpl.application.application_abc import ApplicationABC
from cpl.console.console import Console
class Application(ApplicationABC):
def __init__(self):
ApplicationABC.__init__(self)
def configure(self):
pass
def main(self):
Console.write_line('Hello World')

View File

@ -0,0 +1,13 @@
from startup import Startup
from application import Application
def main():
app = Application()
app.use_startup(Startup)
app.build()
app.run()
if __name__ == '__main__':
main()

View File

@ -0,0 +1,33 @@
from typing import Optional
from cpl.application.application_host import ApplicationHost
from cpl.application.application_host_abc import ApplicationHostABC
from cpl.application.startup_abc import StartupABC
from cpl.configuration.configuration_abc import ConfigurationABC
from cpl.dependency_injection.service_provider_abc import ServiceProviderABC
class Startup(StartupABC):
def __init__(self):
StartupABC.__init__(self)
self._app_host: Optional[ApplicationHostABC] = None
self._configuration: Optional[ConfigurationABC] = None
self._services: Optional[ServiceProviderABC] = None
def create_application_host(self) -> ApplicationHostABC:
self._app_host = ApplicationHost()
self._configuration = self._app_host.configuration
self._services = self._app_host.services
return self._app_host
def create_configuration(self) -> ConfigurationABC:
pass
return self._configuration
def create_services(self) -> ServiceProviderABC:
pass
return self._services