Improved new console command
This commit is contained in:
@@ -1,35 +1,36 @@
|
||||
from cpl_cli.templates.template import Template
|
||||
import textwrap
|
||||
|
||||
|
||||
class Init:
|
||||
|
||||
@staticmethod
|
||||
def get_init_py() -> str:
|
||||
string = """# -*- coding: utf-8 -*-
|
||||
|
||||
\"\"\"
|
||||
$Name $Description
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
string = textwrap.dedent("""\
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
$LongDescription
|
||||
|
||||
:copyright: (c) $CopyrightDate $CopyrightName
|
||||
:license: $LicenseDescription
|
||||
|
||||
\"\"\"
|
||||
|
||||
__title__ = '$Title'
|
||||
__author__ = '$Author'
|
||||
__license__ = '$LicenseName'
|
||||
__copyright__ = 'Copyright (c) $CopyrightDate $CopyrightName'
|
||||
__version__ = '$Version'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
$Imports
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=$Major, minor=$Minor, micro=$Micro)
|
||||
"""
|
||||
\"\"\"
|
||||
$Name $Description
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
$LongDescription
|
||||
|
||||
:copyright: (c) $CopyrightDate $CopyrightName
|
||||
:license: $LicenseDescription
|
||||
|
||||
\"\"\"
|
||||
|
||||
__title__ = '$Title'
|
||||
__author__ = '$Author'
|
||||
__license__ = '$LicenseName'
|
||||
__copyright__ = 'Copyright (c) $CopyrightDate $CopyrightName'
|
||||
__version__ = '$Version'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
$Imports
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=$Major, minor=$Minor, micro=$Micro)
|
||||
""")
|
||||
|
||||
return Template.build_template_string(string)
|
||||
return string
|
||||
|
25
src/cpl_cli/templates/new/__init__.py
Normal file
25
src/cpl_cli/templates/new/__init__.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_cpl sh-edraft Common Python library
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library
|
||||
|
||||
:copyright: (c) 2020 - 2021 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_cli.templates.new'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||
__version__ = '2021.4.1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2021, minor=4, micro=1)
|
25
src/cpl_cli/templates/new/console/__init__.py
Normal file
25
src/cpl_cli/templates/new/console/__init__.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_cpl sh-edraft Common Python library
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library
|
||||
|
||||
:copyright: (c) 2020 - 2021 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_cli.templates.new.console'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||
__version__ = '2021.4.1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2021, minor=4, micro=1)
|
23
src/cpl_cli/templates/new/console/license.py
Normal file
23
src/cpl_cli/templates/new/console/license.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
||||
|
||||
|
||||
class LicenseTemplate(TemplateFileABC):
|
||||
|
||||
def __init__(self):
|
||||
TemplateFileABC.__init__(self)
|
||||
|
||||
self._name = 'LICENSE'
|
||||
self._path = ''
|
||||
self._value = """"""
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self._value
|
23
src/cpl_cli/templates/new/console/readme_py.py
Normal file
23
src/cpl_cli/templates/new/console/readme_py.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
||||
|
||||
|
||||
class ReadmeTemplate(TemplateFileABC):
|
||||
|
||||
def __init__(self):
|
||||
TemplateFileABC.__init__(self)
|
||||
|
||||
self._name = 'README.md'
|
||||
self._path = ''
|
||||
self._value = """"""
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self._value
|
25
src/cpl_cli/templates/new/console/src/__init__.py
Normal file
25
src/cpl_cli/templates/new/console/src/__init__.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
sh_cpl sh-edraft Common Python library
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library
|
||||
|
||||
:copyright: (c) 2020 - 2021 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_cli.templates.new.console.src'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||
__version__ = '2021.4.1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major=2021, minor=4, micro=1)
|
@@ -1,14 +1,40 @@
|
||||
from cpl.application.application_abc import ApplicationABC
|
||||
from cpl.console.console import Console
|
||||
import textwrap
|
||||
|
||||
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
class ApplicationTemplate(TemplateFileABC):
|
||||
|
||||
def __init__(self):
|
||||
ApplicationABC.__init__(self)
|
||||
TemplateFileABC.__init__(self)
|
||||
|
||||
def configure(self):
|
||||
pass
|
||||
self._name = 'application.py'
|
||||
self._path = 'src/'
|
||||
self._value = textwrap.dedent("""\
|
||||
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')
|
||||
""")
|
||||
|
||||
def main(self):
|
||||
Console.write_line('Hello World')
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self._value
|
||||
|
@@ -1,13 +1,105 @@
|
||||
from startup import Startup
|
||||
from application import Application
|
||||
import textwrap
|
||||
|
||||
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
||||
|
||||
|
||||
def main():
|
||||
app = Application()
|
||||
app.use_startup(Startup)
|
||||
app.build()
|
||||
app.run()
|
||||
class MainWithApplicationHostAndStartupTemplate(TemplateFileABC):
|
||||
|
||||
def __init__(self):
|
||||
TemplateFileABC.__init__(self)
|
||||
|
||||
self._name = 'main.py'
|
||||
self._path = 'src/'
|
||||
self._value = textwrap.dedent("""\
|
||||
from startup import Startup
|
||||
from application import Application
|
||||
|
||||
|
||||
def main():
|
||||
app = Application()
|
||||
app.use_startup(Startup)
|
||||
app.build()
|
||||
app.run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
""")
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self._value
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
class MainWithApplicationHostTemplate(TemplateFileABC):
|
||||
|
||||
def __init__(self):
|
||||
TemplateFileABC.__init__(self)
|
||||
|
||||
self._name = 'main.py'
|
||||
self._path = 'src/'
|
||||
self._value = textwrap.dedent("""\
|
||||
from application import Application
|
||||
|
||||
|
||||
def main():
|
||||
app = Application()
|
||||
app.build()
|
||||
app.run()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
""")
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self._value
|
||||
|
||||
|
||||
class MainWithoutApplicationHostTemplate(TemplateFileABC):
|
||||
|
||||
def __init__(self):
|
||||
TemplateFileABC.__init__(self)
|
||||
|
||||
self._name = 'main.py'
|
||||
self._path = 'src/'
|
||||
self._value = textwrap.dedent("""\
|
||||
from cpl.console.console import Console
|
||||
|
||||
|
||||
def main():
|
||||
Console.write_line('Hello World')
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
""")
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self._value
|
||||
|
@@ -1,33 +1,59 @@
|
||||
from typing import Optional
|
||||
import textwrap
|
||||
|
||||
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
|
||||
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
||||
|
||||
|
||||
class Startup(StartupABC):
|
||||
class StartupTemplate(TemplateFileABC):
|
||||
|
||||
def __init__(self):
|
||||
StartupABC.__init__(self)
|
||||
TemplateFileABC.__init__(self)
|
||||
|
||||
self._app_host: Optional[ApplicationHostABC] = None
|
||||
self._configuration: Optional[ConfigurationABC] = None
|
||||
self._services: Optional[ServiceProviderABC] = None
|
||||
self._name = 'startup.py'
|
||||
self._path = 'src/'
|
||||
self._value = textwrap.dedent("""\
|
||||
from typing import Optional
|
||||
|
||||
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
|
||||
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
|
||||
""")
|
||||
|
||||
def create_configuration(self) -> ConfigurationABC:
|
||||
pass
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
return self._configuration
|
||||
@property
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
def create_services(self) -> ServiceProviderABC:
|
||||
pass
|
||||
|
||||
return self._services
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self._value
|
||||
|
@@ -11,7 +11,7 @@ sh-edraft Common Python library
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_cli.templates.new.console.src.tests'
|
||||
__title__ = 'cpl_cli.templates.new.console_old.src.tests'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
|
||||
|
27
src/cpl_cli/templates/new/console/src/tests/init.py
Normal file
27
src/cpl_cli/templates/new/console/src/tests/init.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import textwrap
|
||||
|
||||
from cpl_cli.templates.template_file_abc import TemplateFileABC
|
||||
|
||||
|
||||
class TestsInitTemplate(TemplateFileABC):
|
||||
|
||||
def __init__(self):
|
||||
TemplateFileABC.__init__(self)
|
||||
|
||||
self._name = '__init__.py'
|
||||
self._path = 'src/tests/'
|
||||
self._value = textwrap.dedent("""\
|
||||
# imports:
|
||||
""")
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self._value
|
@@ -1,11 +1,12 @@
|
||||
from cpl_cli.templates.template import Template
|
||||
import textwrap
|
||||
|
||||
|
||||
class Setup:
|
||||
|
||||
@staticmethod
|
||||
def get_setup_py() -> str:
|
||||
string = """\"\"\"
|
||||
string = textwrap.dedent("""\
|
||||
\"\"\"
|
||||
This file is generated by CPL CLI
|
||||
\"\"\"
|
||||
|
||||
@@ -26,6 +27,6 @@ class Setup:
|
||||
entry_points=$EntryPoints,
|
||||
package_data=$PackageData
|
||||
)
|
||||
"""
|
||||
""")
|
||||
|
||||
return Template.build_template_string(string)
|
||||
return string
|
||||
|
@@ -1,14 +0,0 @@
|
||||
class Template:
|
||||
|
||||
@staticmethod
|
||||
def build_template_string(string: str) -> str:
|
||||
return_value = ''
|
||||
for i in range(0, len(string.splitlines())):
|
||||
line = string.splitlines()[i]
|
||||
if i == len(string.splitlines())-1:
|
||||
return_value += f'{line.strip()}'
|
||||
break
|
||||
|
||||
return_value += f'{line.strip()}\n'
|
||||
|
||||
return return_value
|
19
src/cpl_cli/templates/template_file_abc.py
Normal file
19
src/cpl_cli/templates/template_file_abc.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class TemplateFileABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def name(self) -> str: pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def path(self) -> str: pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def value(self) -> str: pass
|
Reference in New Issue
Block a user