Compare commits
114 Commits
419fcc3d29
...
2022.6.0rc
Author | SHA1 | Date | |
---|---|---|---|
b9e0b7ccd0 | |||
4b9e428abb | |||
63ad13e09a | |||
cc06a308a1 | |||
e9fdd20181 | |||
8692686cb5 | |||
db29ad36fe | |||
0710b25317 | |||
cbd2964f42 | |||
f51118f13c | |||
323e363b42 | |||
e8a4fe6142 | |||
587d9b359c | |||
c2632253ac | |||
45be77dd10 | |||
78ffbcc33d | |||
d83d1a244e | |||
fa002a50ac | |||
32507afae9 | |||
6de3bbdaf4 | |||
6e50d0cb22 | |||
9e978f3ece | |||
32478926c8 | |||
2925788d01 | |||
c0789cf4f7 | |||
89d591ce0a | |||
77c560b40c | |||
dad4913bcd | |||
9b56650d4b | |||
9fca2018e5 | |||
e5dd890931 | |||
beadbf8e91 | |||
ff5f9b833d | |||
162f06001a | |||
348fad24c7 | |||
f9748cdb76 | |||
56380763a9 | |||
3a1630b687 | |||
a593f34cde | |||
49cce5fa1a | |||
df7bd06629 | |||
e0da77fd4b | |||
833dd83008 | |||
ce0ad4013f | |||
698f80adfe | |||
d0b0f4bfcb | |||
d23ea86ccf | |||
15d938b172 | |||
6c1d7a3b29 | |||
c28f551682 | |||
def92c78c8 | |||
ddff9dec11 | |||
9e0e85d646 | |||
b05ca7e980 | |||
8f8a9f7dd7 | |||
df32978a31 | |||
79b51cf8c5 | |||
a72dd0dc2e | |||
d937c4c0e6 | |||
46cceb0910 | |||
e74e39c189 | |||
c2706c7737 | |||
d0e66d24bd | |||
c1a1849ad2 | |||
0675105731 | |||
7ee0b951a8 | |||
d8168f024c | |||
2654dc7c69 | |||
4224960837 | |||
907c3a8fff | |||
28505479ba | |||
84d3abce3f | |||
9050dffc53 | |||
e0f69c9bdf | |||
bbd0a60f98 | |||
e23f4187fe | |||
15f200df3a | |||
a1a3ad6fb5 | |||
d6677d53a3 | |||
07e43b50d1 | |||
ac83555b24 | |||
1ab358059c | |||
5bf83c0d77 | |||
03ac00c6e3 | |||
0122d8fc78 | |||
a66ce96dbf | |||
6da8e30446 | |||
539ed13be4 | |||
036a553f64 | |||
976a14584b | |||
ed69f52927 | |||
98847495e6 | |||
40f132da33 | |||
5feb44595a | |||
48c6941f1a | |||
a8756d493a | |||
9f4077a073 | |||
3e7a3d75c5 | |||
477d2d87d3 | |||
7a65dbe39b | |||
f83755ac77 | |||
a590cfd066 | |||
f317035342 | |||
8900bdd446 | |||
35ecf158a2 | |||
353c1d30ec | |||
1c94fb5bd1 | |||
cf305aeebb | |||
90e97433e0 | |||
125a85a0af | |||
cfb8838c73 | |||
824d491ebc | |||
d694c408c0 | |||
d1bb266d49 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -135,3 +135,6 @@ dmypy.json
|
||||
# IDE
|
||||
.idea/
|
||||
PythonImportHelper-v2-Completion.json
|
||||
|
||||
# cpl unittest stuff
|
||||
unittests/test_*_playground
|
||||
|
@@ -1,71 +1,95 @@
|
||||
{
|
||||
"WorkspaceSettings": {
|
||||
"DefaultProject": "cpl_cli",
|
||||
"DefaultProject": "cpl-cli",
|
||||
"Projects": {
|
||||
"cpl_core": "src/cpl_core/cpl_core.json",
|
||||
"cpl_cli": "src/cpl_cli/cpl_cli.json",
|
||||
"cpl_query": "src/cpl_query/cpl_query.json"
|
||||
"cpl-core": "src/cpl_core/cpl-core.json",
|
||||
"cpl-cli": "src/cpl_cli/cpl-cli.json",
|
||||
"cpl-query": "src/cpl_query/cpl-query.json",
|
||||
"set-version": "tools/set_version/set-version.json",
|
||||
"set-pip-urls": "tools/set_pip_urls/set-pip-urls.json",
|
||||
"unittests": "unittests/unittests/unittests.json",
|
||||
"unittests_cli": "unittests/unittests_cli/unittests_cli.json",
|
||||
"unittests_core": "unittests/unittests_core/unittests_core.json",
|
||||
"unittests_query": "unittests/unittests_query/unittests_query.json",
|
||||
"unittests_shared": "unittests/unittests_shared/unittests_shared.json"
|
||||
},
|
||||
"Scripts": {
|
||||
"hello-world": "echo 'Hello World'",
|
||||
|
||||
"sv": "cpl set-version",
|
||||
"set-version": "cpl run set-version $ARGS; echo '';",
|
||||
|
||||
"spu": "cpl set-pip-urls",
|
||||
"set-pip-urls": "cpl run set-pip-urls $ARGS; echo '';",
|
||||
|
||||
"docs-build": "echo 'Build Documentation'; cd docs/; sphinx-apidoc -o source/ ../src/cpl_core; sphinx-apidoc -o source/ ../src/cpl_query; make clean; make html; rm source/cpl_query.tests.rst;",
|
||||
"db": "cpl build-docs",
|
||||
"docs-open": "xdg-open $PWD/docs/build/html/index.html &",
|
||||
"do": "cpl docs-open",
|
||||
|
||||
"build-all": "cpl build-cli; cpl build-core; cpl build-query;",
|
||||
"ba": "cpl build-all",
|
||||
"build-cli": "echo 'Build cpl_cli'; cd ./src/cpl_cli; cpl build; cd ../../;",
|
||||
"build-core": "echo 'Build cpl_core'; cd ./src/cpl_core; cpl build; cd ../../;",
|
||||
"build-query": "echo 'Build cpl_query'; cd ./src/cpl_query; cpl build; cd ../../;",
|
||||
"test": "cpl run unittests",
|
||||
|
||||
"pre-build-all": "cpl sv $ARGS; cpl spu $ARGS;",
|
||||
"build-all": "cpl build-cli; cpl build-core; cpl build-query; cpl build-set-pip-urls; cpl build-set-version",
|
||||
"ba": "cpl build-all $ARGS",
|
||||
"build-cli": "echo 'Build cpl-cli'; cd ./src/cpl_cli; cpl build; cd ../../;",
|
||||
"build-core": "echo 'Build cpl-core'; cd ./src/cpl_core; cpl build; cd ../../;",
|
||||
"build-query": "echo 'Build cpl-query'; cd ./src/cpl_query; cpl build; cd ../../;",
|
||||
"build-set-pip-urls": "echo 'Build set-pip-urls'; cd ./tools/set_pip_urls; cpl build; cd ../../;",
|
||||
"build-set-version": "echo 'Build set-version'; cd ./tools/set_version; cpl build; cd ../../;",
|
||||
|
||||
"pre-publish-all": "cpl sv $ARGS; cpl spu $ARGS;",
|
||||
"publish-all": "cpl publish-cli; cpl publish-core; cpl publish-query;",
|
||||
"pa": "cpl build-all",
|
||||
"publish-cli": "echo 'Publish cpl_cli'; cd ./src/cpl_cli; cpl publish; cd ../../;",
|
||||
"publish-core": "echo 'Publish cpl_core'; cd ./src/cpl_core; cpl publish; cd ../../;",
|
||||
"pa": "cpl build-all $ARGS",
|
||||
"publish-cli": "echo 'Publish cpl-cli'; cd ./src/cpl_cli; cpl publish; cd ../../;",
|
||||
"publish-core": "echo 'Publish cpl-core'; cd ./src/cpl_core; cpl publish; cd ../../;",
|
||||
"publish-query": "echo 'Publish cpl_query'; cd ./src/cpl_query; cpl publish; cd ../../;",
|
||||
|
||||
"upload-prod-cli": "echo 'PROD Upload cpl_cli'; cpl upl-prod-cli;",
|
||||
"upload-prod-core": "echo 'PROD Upload cpl_core'; cpl upl-prod-core;",
|
||||
"upload-prod-query": "echo 'PROD Upload cpl_query'; cpl upl-prod-query;",
|
||||
|
||||
"upload-exp-cli": "echo 'EXP Upload cpl_cli'; cpl upl-exp-cli;",
|
||||
"upload-exp-core": "echo 'EXP Upload cpl_core'; cpl upl-exp-core;",
|
||||
"upload-exp-query": "echo 'EXP Upload cpl_query'; cpl upl-exp-query;",
|
||||
|
||||
"upload-dev-cli": "echo 'DEV Upload cpl_cli'; cpl upl-dev-cli;",
|
||||
"upload-dev-core": "echo 'DEV Upload cpl_core'; cpl upl-dev-core;",
|
||||
"upload-dev-query": "echo 'DEV Upload cpl_query'; cpl upl-dev-query;",
|
||||
|
||||
"upload-prod-cli": "echo 'PROD Upload cpl-cli'; cpl upl-prod-cli;",
|
||||
"upl-prod-cli": "twine upload -r pip.sh-edraft.de dist/cpl-cli/publish/setup/*",
|
||||
"upload-prod-core": "echo 'PROD Upload cpl-core'; cpl upl-prod-core;",
|
||||
"upl-prod-core": "twine upload -r pip.sh-edraft.de dist/cpl-core/publish/setup/*",
|
||||
"upload-prod-query": "echo 'PROD Upload cpl_query'; cpl upl-prod-query;",
|
||||
"upl-prod-query": "twine upload -r pip.sh-edraft.de dist/cpl-query/publish/setup/*",
|
||||
|
||||
"upload-exp-cli": "echo 'EXP Upload cpl-cli'; cpl upl-exp-cli;",
|
||||
"upl-exp-cli": "twine upload -r pip-exp.sh-edraft.de dist/cpl-cli/publish/setup/*",
|
||||
"upload-exp-core": "echo 'EXP Upload cpl-core'; cpl upl-exp-core;",
|
||||
"upl-exp-core": "twine upload -r pip-exp.sh-edraft.de dist/cpl-core/publish/setup/*",
|
||||
"upload-exp-query": "echo 'EXP Upload cpl_query'; cpl upl-exp-query;",
|
||||
"upl-exp-query": "twine upload -r pip-exp.sh-edraft.de dist/cpl-query/publish/setup/*",
|
||||
|
||||
"upload-dev-cli": "echo 'DEV Upload cpl-cli'; cpl upl-dev-cli;",
|
||||
"upl-dev-cli": "twine upload -r pip-dev.sh-edraft.de dist/cpl-cli/publish/setup/*",
|
||||
"upload-dev-core": "echo 'DEV Upload cpl-core'; cpl upl-dev-core;",
|
||||
"upl-dev-core": "twine upload -r pip-dev.sh-edraft.de dist/cpl-core/publish/setup/*",
|
||||
"upload-dev-query": "echo 'DEV Upload cpl_query'; cpl upl-dev-query;",
|
||||
"upl-dev-query": "twine upload -r pip-dev.sh-edraft.de dist/cpl-query/publish/setup/*",
|
||||
|
||||
"pre-deploy-prod": "cpl sv $ARGS; cpl spu --environment=production;",
|
||||
"deploy-prod": "cpl deploy-prod-cli; cpl deploy-prod-core; cpl deploy-prod-query;",
|
||||
"dp": "cpl deploy-prod",
|
||||
"dp": "cpl deploy-prod $ARGS",
|
||||
"deploy-prod-cli": "cpl publish-cli; cpl upload-prod-cli",
|
||||
"deploy-prod-core": "cpl publish-core; cpl upload-prod-core",
|
||||
"deploy-prod-query": "cpl publish-query; cpl upload-prod-query",
|
||||
|
||||
"pre-deploy-exp": "cpl sv $ARGS; cpl spu --environment=staging;",
|
||||
"deploy-exp": "cpl deploy-exp-cli; cpl deploy-exp-core; cpl deploy-exp-query;",
|
||||
"de": "cpl deploy-exp",
|
||||
"de": "cpl deploy-exp $ARGS",
|
||||
"deploy-exp-cli": "cpl publish-cli; cpl upload-exp-cli",
|
||||
"deploy-exp-core": "cpl publish-core; cpl upload-exp-core",
|
||||
"deploy-exp-query": "cpl publish-query; cpl upload-exp-query",
|
||||
|
||||
"pre-deploy-dev": "cpl sv $ARGS; cpl spu --environment=development;",
|
||||
"deploy-dev": "cpl deploy-dev-cli; cpl deploy-dev-core; cpl deploy-dev-query;",
|
||||
"dd": "cpl deploy-dev",
|
||||
"dd": "cpl deploy-dev $ARGS",
|
||||
"deploy-dev-cli": "cpl publish-cli; cpl upload-dev-cli",
|
||||
"deploy-dev-core": "cpl publish-core; cpl upload-dev-core",
|
||||
"deploy-dev-query": "cpl publish-query; cpl upload-dev-query"
|
||||
"deploy-dev-query": "cpl publish-query; cpl upload-dev-query",
|
||||
|
||||
"dev-install": "cpl di-core; cpl di-cli; cpl di-query;",
|
||||
"di": "cpl dev-install",
|
||||
"di-core": "pip install cpl-query --pre --upgrade --extra-index-url https://pip-dev.sh-edraft.de",
|
||||
"di-cli": "pip install cpl-query --pre --upgrade --extra-index-url https://pip-dev.sh-edraft.de",
|
||||
"di-query": "pip install cpl-query --pre --upgrade --extra-index-url https://pip-dev.sh-edraft.de"
|
||||
}
|
||||
}
|
||||
}
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -27,4 +27,4 @@ from .main import main
|
||||
from .startup import Startup
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.build'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.generate'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
40
src/cpl_cli/_templates/generate/pipe_template.py
Normal file
40
src/cpl_cli/_templates/generate/pipe_template.py
Normal file
@@ -0,0 +1,40 @@
|
||||
import textwrap
|
||||
from string import Template
|
||||
|
||||
from cpl_core.utils.string import String
|
||||
from cpl_cli._templates.template_file_abc import TemplateFileABC
|
||||
|
||||
|
||||
class PipeTemplate(TemplateFileABC):
|
||||
|
||||
def __init__(self, name: str, schematic: str, schematic_upper: str, path: str):
|
||||
TemplateFileABC.__init__(self)
|
||||
|
||||
self._name = f'{String.convert_to_snake_case(name)}_{schematic}.py'
|
||||
self._class_name = f'{String.first_to_upper(name)}{schematic_upper}'
|
||||
self._path = path
|
||||
self._value = textwrap.dedent("""\
|
||||
from cpl_core.pipes.pipe_abc import PipeABC
|
||||
|
||||
|
||||
class $Name(PipeABC):
|
||||
|
||||
def __init__(self): pass
|
||||
|
||||
def transform(self, value: any, *args):
|
||||
return value
|
||||
""")
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return Template(self._value).substitute(
|
||||
Name=self._class_name
|
||||
)
|
41
src/cpl_cli/_templates/generate/test_case_template.py
Normal file
41
src/cpl_cli/_templates/generate/test_case_template.py
Normal file
@@ -0,0 +1,41 @@
|
||||
import textwrap
|
||||
from string import Template
|
||||
|
||||
from cpl_core.utils.string import String
|
||||
from cpl_cli._templates.template_file_abc import TemplateFileABC
|
||||
|
||||
|
||||
class TestCaseTemplate(TemplateFileABC):
|
||||
|
||||
def __init__(self, name: str, schematic: str, schematic_upper: str, path: str):
|
||||
TemplateFileABC.__init__(self)
|
||||
|
||||
self._name = f'{String.convert_to_snake_case(name)}_{schematic}.py'
|
||||
self._class_name = f'{String.first_to_upper(name)}{schematic_upper}'
|
||||
self._path = path
|
||||
self._value = textwrap.dedent("""\
|
||||
import unittest
|
||||
|
||||
|
||||
class $Name(unittest.TestCase):
|
||||
|
||||
def setUp(self):
|
||||
pass
|
||||
|
||||
def test_equal(self):
|
||||
pass
|
||||
""")
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return Template(self._value).substitute(
|
||||
Name=self._class_name
|
||||
)
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.console'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.console.source'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.console.source.name'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.console.source.tests'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.library'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.library.source'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.library.source.name'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.new.library.source.tests'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
25
src/cpl_cli/_templates/new/unittest/__init__.py
Normal file
25
src/cpl_cli/_templates/new/unittest/__init__.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-cli sh-edraft Common Python library CLI
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library Command Line Interface
|
||||
|
||||
:copyright: (c) 2020 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_cli._templates.new.unittest'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
23
src/cpl_cli/_templates/new/unittest/license.py
Normal file
23
src/cpl_cli/_templates/new/unittest/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/unittest/readme_py.py
Normal file
23
src/cpl_cli/_templates/new/unittest/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/unittest/source/__init__.py
Normal file
25
src/cpl_cli/_templates/new/unittest/source/__init__.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-cli sh-edraft Common Python library CLI
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library Command Line Interface
|
||||
|
||||
:copyright: (c) 2020 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_cli._templates.new.unittest.source'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
25
src/cpl_cli/_templates/new/unittest/source/name/__init__.py
Normal file
25
src/cpl_cli/_templates/new/unittest/source/name/__init__.py
Normal file
@@ -0,0 +1,25 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-cli sh-edraft Common Python library CLI
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library Command Line Interface
|
||||
|
||||
:copyright: (c) 2020 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_cli._templates.new.unittest.source.name'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
@@ -0,0 +1,74 @@
|
||||
import textwrap
|
||||
|
||||
from cpl_cli._templates.template_file_abc import TemplateFileABC
|
||||
|
||||
|
||||
class ApplicationTemplate(TemplateFileABC):
|
||||
|
||||
def __init__(self, name: str, path: str, use_async: bool):
|
||||
TemplateFileABC.__init__(self)
|
||||
|
||||
self._name = 'application.py'
|
||||
self._path = path
|
||||
self._use_async = use_async
|
||||
|
||||
if self._use_async:
|
||||
self._value = textwrap.dedent("""\
|
||||
import unittest
|
||||
from unittest import TestSuite
|
||||
|
||||
from cpl_core.application import ApplicationABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from unittests.test_case import TestCase
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
self._suite: TestSuite = unittest.TestSuite()
|
||||
|
||||
async def configure(self):
|
||||
self._suite.addTest(TestCase('test_equal'))
|
||||
|
||||
async def main(self):
|
||||
runner = unittest.TextTestRunner()
|
||||
runner.run(self._suite)
|
||||
""")
|
||||
else:
|
||||
self._value = textwrap.dedent("""\
|
||||
import unittest
|
||||
from unittest import TestSuite
|
||||
|
||||
from cpl_core.application import ApplicationABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from unittests.test_case import TestCase
|
||||
|
||||
|
||||
class Application(ApplicationABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, services: ServiceProviderABC):
|
||||
ApplicationABC.__init__(self, config, services)
|
||||
self._suite: TestSuite = unittest.TestSuite()
|
||||
|
||||
def configure(self):
|
||||
self._suite.addTest(TestCase('test_equal'))
|
||||
|
||||
def main(self):
|
||||
runner = unittest.TextTestRunner()
|
||||
runner.run(self._suite)
|
||||
""")
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self._value
|
27
src/cpl_cli/_templates/new/unittest/source/name/init.py
Normal file
27
src/cpl_cli/_templates/new/unittest/source/name/init.py
Normal file
@@ -0,0 +1,27 @@
|
||||
import textwrap
|
||||
|
||||
from cpl_cli._templates.template_file_abc import TemplateFileABC
|
||||
|
||||
|
||||
class MainInitTemplate(TemplateFileABC):
|
||||
|
||||
def __init__(self, name: str, path: str):
|
||||
TemplateFileABC.__init__(self)
|
||||
|
||||
self._name = '__init__.py'
|
||||
self._path = path
|
||||
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
|
63
src/cpl_cli/_templates/new/unittest/source/name/main.py
Normal file
63
src/cpl_cli/_templates/new/unittest/source/name/main.py
Normal file
@@ -0,0 +1,63 @@
|
||||
import textwrap
|
||||
|
||||
from cpl_core.utils.string import String
|
||||
from cpl_cli._templates.template_file_abc import TemplateFileABC
|
||||
|
||||
|
||||
class MainWithApplicationBaseTemplate(TemplateFileABC):
|
||||
|
||||
def __init__(self, name: str, path: str, use_async: bool):
|
||||
TemplateFileABC.__init__(self)
|
||||
|
||||
name = String.convert_to_snake_case(name)
|
||||
self._name = 'main.py'
|
||||
self._path = path
|
||||
|
||||
import_pkg = f'{name}.'
|
||||
|
||||
if use_async:
|
||||
self._value = textwrap.dedent(f"""\
|
||||
import asyncio
|
||||
|
||||
from cpl_core.application import ApplicationBuilder
|
||||
|
||||
from {import_pkg}application import Application
|
||||
|
||||
|
||||
async def main():
|
||||
app_builder = ApplicationBuilder(Application)
|
||||
app: Application = await app_builder.build_async()
|
||||
await app.run_async()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
ml = asyncio.get_event_loop()
|
||||
ml.run_until_complete(main())
|
||||
""")
|
||||
else:
|
||||
self._value = textwrap.dedent(f"""\
|
||||
from cpl_core.application import ApplicationBuilder
|
||||
|
||||
from {import_pkg}application import Application
|
||||
|
||||
|
||||
def main():
|
||||
app_builder = ApplicationBuilder(Application)
|
||||
app_builder.build().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
|
52
src/cpl_cli/_templates/new/unittest/source/name/test_case.py
Normal file
52
src/cpl_cli/_templates/new/unittest/source/name/test_case.py
Normal file
@@ -0,0 +1,52 @@
|
||||
import textwrap
|
||||
|
||||
from cpl_cli._templates.template_file_abc import TemplateFileABC
|
||||
|
||||
|
||||
class TestCaseTemplate(TemplateFileABC):
|
||||
|
||||
def __init__(self, name: str, path: str, use_async: bool):
|
||||
TemplateFileABC.__init__(self)
|
||||
|
||||
self._name = 'test_case.py'
|
||||
self._path = path
|
||||
self._use_async = use_async
|
||||
|
||||
if self._use_async:
|
||||
self._value = textwrap.dedent("""\
|
||||
import unittest
|
||||
|
||||
|
||||
class TestCase(unittest.TestCase):
|
||||
|
||||
async def setUp(self) -> None:
|
||||
pass
|
||||
|
||||
async def test_equal(self):
|
||||
self.assertEqual(True, True)
|
||||
""")
|
||||
else:
|
||||
self._value = textwrap.dedent("""\
|
||||
import unittest
|
||||
|
||||
|
||||
class TestCase(unittest.TestCase):
|
||||
|
||||
def setUp(self) -> None:
|
||||
pass
|
||||
|
||||
def test_equal(self):
|
||||
self.assertEqual(True, True)
|
||||
""")
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name
|
||||
|
||||
@property
|
||||
def path(self) -> str:
|
||||
return self._path
|
||||
|
||||
@property
|
||||
def value(self) -> str:
|
||||
return self._value
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli._templates.publish'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -1,5 +1,5 @@
|
||||
{
|
||||
"CLI": {
|
||||
"PipPath": "https://pip.sh-edraft.de"
|
||||
"PipPath": "https://pip-exp.sh-edraft.de"
|
||||
}
|
||||
}
|
@@ -5,7 +5,7 @@ from cpl_cli.error import Error
|
||||
from cpl_core.application.application_abc import ApplicationABC
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_core.dependency_injection.service_provider_abc import ServiceProviderABC
|
||||
|
||||
|
||||
class CLI(ApplicationABC):
|
||||
@@ -29,6 +29,7 @@ class CLI(ApplicationABC):
|
||||
try:
|
||||
result = self._configuration.parse_console_arguments(self._services)
|
||||
if result:
|
||||
Console.write_line()
|
||||
return
|
||||
|
||||
if len(self._configuration.additional_arguments) == 0:
|
||||
@@ -37,6 +38,7 @@ class CLI(ApplicationABC):
|
||||
|
||||
unexpected_arguments = ', '.join(self._configuration.additional_arguments)
|
||||
Error.error(f'Unexpected argument(s): {unexpected_arguments}')
|
||||
Console.write_line()
|
||||
except KeyboardInterrupt:
|
||||
Console.write_line()
|
||||
sys.exit()
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli.command'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -28,4 +28,4 @@ from .publish_service import PublishService
|
||||
from .version_service import VersionService
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -1,6 +1,8 @@
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_cli.command_abc import CommandABC
|
||||
@@ -9,13 +11,14 @@ from cpl_cli.configuration.workspace_settings import WorkspaceSettings
|
||||
|
||||
class CustomScriptService(CommandABC):
|
||||
|
||||
def __init__(self, config: ConfigurationABC, ws: WorkspaceSettings):
|
||||
def __init__(self, config: ConfigurationABC, env: ApplicationEnvironmentABC, ws: WorkspaceSettings):
|
||||
"""
|
||||
Service for CLI scripts
|
||||
"""
|
||||
CommandABC.__init__(self)
|
||||
|
||||
self._config = config
|
||||
self._env = env
|
||||
self._workspace = ws
|
||||
|
||||
@property
|
||||
@@ -24,11 +27,24 @@ class CustomScriptService(CommandABC):
|
||||
|
||||
def execute(self, args: list[str]):
|
||||
cmd = self._config.get_configuration('ACTIVE_EXECUTABLE')
|
||||
wd = self._config.get_configuration('PATH_WORKSPACE')
|
||||
if wd is not None:
|
||||
self._env.set_working_directory(wd)
|
||||
|
||||
for script in self._workspace.scripts:
|
||||
if script == cmd:
|
||||
command = self._workspace.scripts[script]
|
||||
try:
|
||||
subprocess.run(command, shell=True if os.name == 'posix' else None)
|
||||
except Exception as e:
|
||||
Console.error(str(e))
|
||||
if script != cmd:
|
||||
continue
|
||||
|
||||
command = ''
|
||||
external_args = self._config.get_configuration('ARGS')
|
||||
if external_args is not None:
|
||||
command += f'ARGS="{external_args}";'
|
||||
|
||||
command += self._workspace.scripts[script]
|
||||
env_vars = os.environ
|
||||
env_vars['CPL_ARGS'] = " ".join(args)
|
||||
|
||||
try:
|
||||
subprocess.run(command, shell=True if os.name == 'posix' else None)
|
||||
except Exception as e:
|
||||
Console.error(str(e))
|
||||
|
@@ -2,20 +2,22 @@ import os
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
from cpl_cli._templates.generate.validator_template import ValidatorTemplate
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.utils.string import String
|
||||
from cpl_cli.command_abc import CommandABC
|
||||
from cpl_cli._templates.generate.init_template import InitTemplate
|
||||
from cpl_cli._templates.generate.abc_template import ABCTemplate
|
||||
from cpl_cli._templates.generate.class_template import ClassTemplate
|
||||
from cpl_cli._templates.generate.configmodel_template import ConfigModelTemplate
|
||||
from cpl_cli._templates.generate.enum_template import EnumTemplate
|
||||
from cpl_cli._templates.generate.init_template import InitTemplate
|
||||
from cpl_cli._templates.generate.pipe_template import PipeTemplate
|
||||
from cpl_cli._templates.generate.service_template import ServiceTemplate
|
||||
from cpl_cli._templates.generate.test_case_template import TestCaseTemplate
|
||||
from cpl_cli._templates.generate.thread_template import ThreadTemplate
|
||||
from cpl_cli._templates.generate.validator_template import ValidatorTemplate
|
||||
from cpl_cli._templates.template_file_abc import TemplateFileABC
|
||||
from cpl_cli.command_abc import CommandABC
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl_core.utils.string import String
|
||||
|
||||
|
||||
class GenerateService(CommandABC):
|
||||
@@ -40,6 +42,10 @@ class GenerateService(CommandABC):
|
||||
"Upper": "Enum",
|
||||
"Template": EnumTemplate
|
||||
},
|
||||
"pipe": {
|
||||
"Upper": "Pipe",
|
||||
"Template": PipeTemplate
|
||||
},
|
||||
"service": {
|
||||
"Upper": "Service",
|
||||
"Template": ServiceTemplate
|
||||
@@ -48,6 +54,10 @@ class GenerateService(CommandABC):
|
||||
"Upper": "Settings",
|
||||
"Template": ConfigModelTemplate
|
||||
},
|
||||
"test_case": {
|
||||
"Upper": "TestCase",
|
||||
"Template": TestCaseTemplate
|
||||
},
|
||||
"thread": {
|
||||
"Upper": "Thread",
|
||||
"Template": ThreadTemplate
|
||||
@@ -75,8 +85,10 @@ class GenerateService(CommandABC):
|
||||
abc
|
||||
class
|
||||
enum
|
||||
pipe
|
||||
service
|
||||
settings
|
||||
test_case
|
||||
thread
|
||||
validator
|
||||
""")
|
||||
@@ -94,8 +106,10 @@ class GenerateService(CommandABC):
|
||||
'abc (a|A)',
|
||||
'class (c|C)',
|
||||
'enum (e|E)',
|
||||
'pipe (p|P)',
|
||||
'service (s|S)',
|
||||
'settings (st|ST)',
|
||||
'test-case (tc|TC)',
|
||||
'thread (t|T)',
|
||||
'validator (v|V)'
|
||||
]
|
||||
@@ -130,7 +144,7 @@ class GenerateService(CommandABC):
|
||||
rel_path = '/'.join(parts[:-1])
|
||||
class_name = parts[len(parts) - 1]
|
||||
|
||||
if 'src' not in rel_path:
|
||||
if 'src' not in rel_path and not os.path.exists(os.path.join(self._env.working_directory, rel_path)):
|
||||
rel_path = f'src/{rel_path}'
|
||||
|
||||
template = template(class_name, schematic, self._schematics[schematic]["Upper"], rel_path)
|
||||
@@ -185,6 +199,7 @@ class GenerateService(CommandABC):
|
||||
|
||||
if schematic is None:
|
||||
self._help('Usage: cpl generate <schematic> [options]')
|
||||
Console.write_line()
|
||||
sys.exit()
|
||||
|
||||
name = value
|
||||
@@ -197,4 +212,5 @@ class GenerateService(CommandABC):
|
||||
|
||||
else:
|
||||
self._help('Usage: cpl generate <schematic> [options]')
|
||||
Console.write_line()
|
||||
sys.exit()
|
||||
|
@@ -4,19 +4,20 @@ import subprocess
|
||||
import textwrap
|
||||
import time
|
||||
|
||||
from packaging import version
|
||||
|
||||
from cpl_cli.cli_settings import CLISettings
|
||||
from cpl_cli.command_abc import CommandABC
|
||||
from cpl_cli.configuration.build_settings import BuildSettings
|
||||
from cpl_cli.configuration.project_settings import ProjectSettings
|
||||
from cpl_cli.configuration.settings_helper import SettingsHelper
|
||||
from cpl_cli.configuration.venv_helper_service import VenvHelper
|
||||
from cpl_cli.error import Error
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl_core.environment.application_environment_abc import \
|
||||
ApplicationEnvironmentABC
|
||||
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
|
||||
from cpl_core.utils.pip import Pip
|
||||
from packaging import version
|
||||
|
||||
|
||||
class InstallService(CommandABC):
|
||||
@@ -41,8 +42,9 @@ class InstallService(CommandABC):
|
||||
|
||||
self._is_simulation = False
|
||||
self._is_virtual = False
|
||||
self._is_dev = False
|
||||
|
||||
self._project_file = f'{self._config.get_configuration("ProjectName")}.json'
|
||||
self._project_file = f'{self._project_settings.name}.json'
|
||||
|
||||
@property
|
||||
def help_message(self) -> str:
|
||||
@@ -62,7 +64,6 @@ class InstallService(CommandABC):
|
||||
Installs dependencies of CPl project
|
||||
:return:
|
||||
"""
|
||||
|
||||
if self._project_settings is None or self._build_settings is None:
|
||||
Error.error('The command requires to be run in an CPL project, but a project could not be found.')
|
||||
return
|
||||
@@ -71,13 +72,22 @@ class InstallService(CommandABC):
|
||||
Error.error(f'Found invalid dependencies in {self._project_file}.')
|
||||
return
|
||||
|
||||
if not self._is_virtual:
|
||||
Pip.set_executable(self._project_settings.python_executable)
|
||||
for dependency in self._project_settings.dependencies:
|
||||
Console.spinner(
|
||||
f'Installing: {dependency}',
|
||||
Pip.install if not self._is_virtual else self._wait, dependency if not self._is_virtual else 2,
|
||||
source=self._cli_settings.pip_path if 'sh_cpl' in dependency else None,
|
||||
source=self._cli_settings.pip_path if 'cpl-' in dependency else None,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
spinner_foreground_color=ForegroundColorEnum.cyan
|
||||
)
|
||||
|
||||
for dependency in self._project_settings.dev_dependencies:
|
||||
Console.spinner(
|
||||
f'Installing dev: {dependency}',
|
||||
Pip.install if not self._is_virtual else self._wait, dependency if not self._is_virtual else 2,
|
||||
source=self._cli_settings.pip_path if 'cpl-' in dependency else None,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
@@ -94,9 +104,6 @@ class InstallService(CommandABC):
|
||||
:return:
|
||||
"""
|
||||
is_already_in_project = False
|
||||
if not self._is_virtual:
|
||||
Pip.set_executable(self._project_settings.python_executable)
|
||||
|
||||
if self._project_settings is None or self._build_settings is None:
|
||||
Error.error('The command requires to be run in an CPL project, but a project could not be found.')
|
||||
return
|
||||
@@ -112,7 +119,11 @@ class InstallService(CommandABC):
|
||||
package_version = package.split('==')[1]
|
||||
|
||||
to_remove_list = []
|
||||
for dependency in self._project_settings.dependencies:
|
||||
deps = self._project_settings.dependencies
|
||||
if self._is_dev:
|
||||
deps = self._project_settings.dev_dependencies
|
||||
|
||||
for dependency in deps:
|
||||
dependency_version = ''
|
||||
|
||||
if '==' in dependency:
|
||||
@@ -126,7 +137,10 @@ class InstallService(CommandABC):
|
||||
is_already_in_project = True
|
||||
|
||||
for to_remove in to_remove_list:
|
||||
self._project_settings.dependencies.remove(to_remove)
|
||||
if self._is_dev:
|
||||
self._project_settings.dev_dependencies.remove(to_remove)
|
||||
else:
|
||||
self._project_settings.dependencies.remove(to_remove)
|
||||
|
||||
local_package = Pip.get_package(package)
|
||||
if local_package is not None and local_package in self._project_settings.dependencies:
|
||||
@@ -138,9 +152,9 @@ class InstallService(CommandABC):
|
||||
return
|
||||
|
||||
Console.spinner(
|
||||
f'Installing: {package}',
|
||||
f'Installing: {package}' if not self._is_dev else f'Installing dev: {package}',
|
||||
Pip.install if not self._is_virtual else self._wait, package if not self._is_virtual else 2,
|
||||
source=self._cli_settings.pip_path if 'sh_cpl' in package else None,
|
||||
source=self._cli_settings.pip_path if 'cpl-' in package or 'cpl_' in package else None,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
@@ -170,7 +184,10 @@ class InstallService(CommandABC):
|
||||
if '\r' in new_name:
|
||||
new_name = new_name.replace('\r', '')
|
||||
|
||||
self._project_settings.dependencies.append(new_name)
|
||||
if self._is_dev:
|
||||
self._project_settings.dev_dependencies.append(new_name)
|
||||
else:
|
||||
self._project_settings.dependencies.append(new_name)
|
||||
|
||||
if not self._is_simulation:
|
||||
config = {
|
||||
@@ -190,6 +207,10 @@ class InstallService(CommandABC):
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
if 'dev' in args:
|
||||
self._is_dev = True
|
||||
args.remove('dev')
|
||||
|
||||
if 'virtual' in args:
|
||||
self._is_virtual = True
|
||||
args.remove('virtual')
|
||||
@@ -200,7 +221,12 @@ class InstallService(CommandABC):
|
||||
args.remove('simulate')
|
||||
Console.write_line('Running in simulation mode:')
|
||||
|
||||
VenvHelper.init_venv(self._is_virtual, self._env, self._project_settings)
|
||||
|
||||
if len(args) == 0:
|
||||
self._install_project()
|
||||
else:
|
||||
self._install_package(args[0])
|
||||
|
||||
if not self._is_virtual:
|
||||
Pip.reset_executable()
|
||||
|
@@ -5,7 +5,10 @@ from typing import Optional
|
||||
|
||||
from packaging import version
|
||||
|
||||
import cpl_cli
|
||||
import cpl_core
|
||||
from cpl_cli.configuration.venv_helper_service import VenvHelper
|
||||
from cpl_cli.source_creator.unittest_builder import UnittestBuilder
|
||||
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
|
||||
@@ -35,7 +38,7 @@ class NewService(CommandABC):
|
||||
self._config = configuration
|
||||
self._env = self._config.environment
|
||||
|
||||
self._workspace = self._config.get_configuration(WorkspaceSettings)
|
||||
self._workspace: WorkspaceSettings = self._config.get_configuration(WorkspaceSettings)
|
||||
self._project: ProjectSettings = ProjectSettings()
|
||||
self._project_dict = {}
|
||||
self._build: BuildSettings = BuildSettings()
|
||||
@@ -43,11 +46,14 @@ class NewService(CommandABC):
|
||||
self._project_json = {}
|
||||
|
||||
self._name: str = ''
|
||||
self._rel_path: str = ''
|
||||
self._schematic: ProjectTypeEnum = ProjectTypeEnum.console
|
||||
self._use_nothing: bool = False
|
||||
self._use_application_api: bool = False
|
||||
self._use_startup: bool = False
|
||||
self._use_service_providing: bool = False
|
||||
self._use_async: bool = False
|
||||
self._use_venv: bool = False
|
||||
|
||||
@property
|
||||
def help_message(self) -> str:
|
||||
@@ -81,9 +87,10 @@ class NewService(CommandABC):
|
||||
for name in schematics:
|
||||
Console.write(f'\n\t{name} ')
|
||||
|
||||
def _create_project_settings(self, name: str):
|
||||
def _create_project_settings(self):
|
||||
self._rel_path = os.path.dirname(self._name)
|
||||
self._project_dict = {
|
||||
ProjectSettingsNameEnum.name.value: name,
|
||||
ProjectSettingsNameEnum.name.value: os.path.basename(self._name),
|
||||
ProjectSettingsNameEnum.version.value: {
|
||||
VersionSettingsNameEnum.major.value: '0',
|
||||
VersionSettingsNameEnum.minor.value: '0',
|
||||
@@ -99,11 +106,14 @@ class NewService(CommandABC):
|
||||
ProjectSettingsNameEnum.license_name.value: '',
|
||||
ProjectSettingsNameEnum.license_description.value: '',
|
||||
ProjectSettingsNameEnum.dependencies.value: [
|
||||
f'sh_cpl-core>={version.parse(cpl_core.__version__)}'
|
||||
f'cpl-core>={version.parse(cpl_core.__version__)}'
|
||||
],
|
||||
ProjectSettingsNameEnum.dev_dependencies.value: [
|
||||
f'cpl-cli>={version.parse(cpl_cli.__version__)}'
|
||||
],
|
||||
ProjectSettingsNameEnum.python_version.value: f'>={sys.version.split(" ")[0]}',
|
||||
ProjectSettingsNameEnum.python_path.value: {
|
||||
sys.platform: ''
|
||||
sys.platform: '../../venv/bin/python' if self._use_venv else ''
|
||||
},
|
||||
ProjectSettingsNameEnum.classifiers.value: []
|
||||
}
|
||||
@@ -111,15 +121,11 @@ class NewService(CommandABC):
|
||||
self._project.from_dict(self._project_dict)
|
||||
|
||||
def _create_build_settings(self):
|
||||
main = f'{String.convert_to_snake_case(self._project.name)}.main'
|
||||
if self._schematic == ProjectTypeEnum.library.value:
|
||||
main = f'{String.convert_to_snake_case(self._project.name)}.main'
|
||||
|
||||
self._build_dict = {
|
||||
BuildSettingsNameEnum.project_type.value: self._schematic,
|
||||
BuildSettingsNameEnum.source_path.value: '',
|
||||
BuildSettingsNameEnum.output_path.value: '../../dist',
|
||||
BuildSettingsNameEnum.main.value: main,
|
||||
BuildSettingsNameEnum.main.value: f'{String.convert_to_snake_case(self._project.name)}.main',
|
||||
BuildSettingsNameEnum.entry_point.value: self._project.name,
|
||||
BuildSettingsNameEnum.include_package_data.value: False,
|
||||
BuildSettingsNameEnum.included.value: [],
|
||||
@@ -149,40 +155,38 @@ class NewService(CommandABC):
|
||||
:return:
|
||||
"""
|
||||
if self._workspace is None:
|
||||
project_path = os.path.join(self._env.working_directory, self._project.name)
|
||||
project_path = os.path.join(self._env.working_directory, self._rel_path, self._project.name)
|
||||
else:
|
||||
project_path = os.path.join(
|
||||
self._env.working_directory,
|
||||
'src',
|
||||
String.convert_to_snake_case(self._project.name)
|
||||
)
|
||||
project_path = os.path.join(self._env.working_directory, 'src', self._rel_path, String.convert_to_snake_case(self._project.name))
|
||||
|
||||
if os.path.isdir(project_path) and len(os.listdir(project_path)) > 0:
|
||||
Console.write_line(project_path)
|
||||
Console.error('Project path is not empty\n')
|
||||
return None
|
||||
|
||||
return project_path
|
||||
|
||||
def _get_project_information(self):
|
||||
def _get_project_information(self, is_unittest=False):
|
||||
"""
|
||||
Gets project information's from user
|
||||
:return:
|
||||
"""
|
||||
result = Console.read('Do you want to use application base? (y/n) ')
|
||||
if result.lower() == 'y':
|
||||
self._use_application_api = True
|
||||
if self._use_application_api or self._use_startup or self._use_service_providing or self._use_async or self._use_nothing:
|
||||
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||
Console.write_line('Skipping question due to given flags')
|
||||
return
|
||||
|
||||
result = Console.read('Do you want to use startup? (y/n) ')
|
||||
if result.lower() == 'y':
|
||||
self._use_startup = True
|
||||
else:
|
||||
result = Console.read('Do you want to use service providing? (y/n) ')
|
||||
if result.lower() == 'y':
|
||||
self._use_service_providing = True
|
||||
if not is_unittest:
|
||||
self._use_application_api = Console.read('Do you want to use application base? (y/n) ').lower() == 'y'
|
||||
|
||||
result = Console.read('Do you want to use async? (y/n) ')
|
||||
if result.lower() == 'y':
|
||||
self._use_async = True
|
||||
if not is_unittest and self._use_application_api:
|
||||
self._use_startup = Console.read('Do you want to use startup? (y/n) ').lower() == 'y'
|
||||
|
||||
if not is_unittest and not self._use_application_api:
|
||||
self._use_service_providing = Console.read('Do you want to use service providing? (y/n) ').lower() == 'y'
|
||||
|
||||
if not self._use_async:
|
||||
self._use_async = Console.read('Do you want to use async? (y/n) ').lower() == 'y'
|
||||
|
||||
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||
|
||||
@@ -192,7 +196,7 @@ class NewService(CommandABC):
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
self._create_project_settings(self._name)
|
||||
self._create_project_settings()
|
||||
self._create_build_settings()
|
||||
self._create_project_json()
|
||||
path = self._get_project_path()
|
||||
@@ -200,6 +204,9 @@ class NewService(CommandABC):
|
||||
return
|
||||
|
||||
self._get_project_information()
|
||||
project_name = self._project.name
|
||||
if self._rel_path != '':
|
||||
project_name = f'{self._rel_path}/{project_name}'
|
||||
try:
|
||||
ConsoleBuilder.build(
|
||||
path,
|
||||
@@ -207,7 +214,36 @@ class NewService(CommandABC):
|
||||
self._use_startup,
|
||||
self._use_service_providing,
|
||||
self._use_async,
|
||||
self._project.name,
|
||||
project_name,
|
||||
self._project_json,
|
||||
self._workspace
|
||||
)
|
||||
except Exception as e:
|
||||
Console.error('Could not create project', str(e))
|
||||
|
||||
def _unittest(self, args: list[str]):
|
||||
"""
|
||||
Generates new unittest project
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
self._create_project_settings()
|
||||
self._create_build_settings()
|
||||
self._create_project_json()
|
||||
path = self._get_project_path()
|
||||
if path is None:
|
||||
return
|
||||
|
||||
self._get_project_information(is_unittest=True)
|
||||
project_name = self._project.name
|
||||
if self._rel_path != '':
|
||||
project_name = f'{self._rel_path}/{project_name}'
|
||||
try:
|
||||
UnittestBuilder.build(
|
||||
path,
|
||||
self._use_application_api,
|
||||
self._use_async,
|
||||
project_name,
|
||||
self._project_json,
|
||||
self._workspace
|
||||
)
|
||||
@@ -220,7 +256,7 @@ class NewService(CommandABC):
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
self._create_project_settings(self._name)
|
||||
self._create_project_settings()
|
||||
self._create_build_settings()
|
||||
self._create_project_json()
|
||||
path = self._get_project_path()
|
||||
@@ -228,6 +264,9 @@ class NewService(CommandABC):
|
||||
return
|
||||
|
||||
self._get_project_information()
|
||||
project_name = self._project.name
|
||||
if self._rel_path != '':
|
||||
project_name = f'{self._rel_path}/{project_name}'
|
||||
try:
|
||||
LibraryBuilder.build(
|
||||
path,
|
||||
@@ -235,30 +274,89 @@ class NewService(CommandABC):
|
||||
self._use_startup,
|
||||
self._use_service_providing,
|
||||
self._use_async,
|
||||
self._project.name,
|
||||
project_name,
|
||||
self._project_json,
|
||||
self._workspace
|
||||
)
|
||||
except Exception as e:
|
||||
Console.error('Could not create project', str(e))
|
||||
|
||||
def _create_venv(self):
|
||||
|
||||
project = self._project.name
|
||||
if self._workspace is not None:
|
||||
project = self._workspace.default_project
|
||||
|
||||
if self._env.working_directory.endswith(project):
|
||||
project = ''
|
||||
|
||||
VenvHelper.init_venv(
|
||||
False,
|
||||
self._env,
|
||||
self._project,
|
||||
explicit_path=os.path.join(self._env.working_directory, project, self._project.python_executable.replace('../', ''))
|
||||
)
|
||||
|
||||
def execute(self, args: list[str]):
|
||||
"""
|
||||
Entry point of command
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
if 'nothing' in args:
|
||||
self._use_nothing = True
|
||||
self._use_async = False
|
||||
self._use_application_api = False
|
||||
self._use_startup = False
|
||||
self._use_service_providing = False
|
||||
if 'async' in args:
|
||||
args.remove('async')
|
||||
if 'application-base' in args:
|
||||
args.remove('application-base')
|
||||
if 'startup' in args:
|
||||
args.remove('startup')
|
||||
if 'service-providing' in args:
|
||||
args.remove('service-providing')
|
||||
|
||||
if 'async' in args:
|
||||
self._use_async = True
|
||||
args.remove('async')
|
||||
if 'application-base' in args:
|
||||
self._use_application_api = True
|
||||
args.remove('application-base')
|
||||
if 'startup' in args:
|
||||
self._use_startup = True
|
||||
args.remove('startup')
|
||||
if 'service-providing' in args:
|
||||
self._use_service_providing = True
|
||||
args.remove('service-providing')
|
||||
if 'venv' in args:
|
||||
self._use_venv = True
|
||||
args.remove('venv')
|
||||
|
||||
console = self._config.get_configuration(ProjectTypeEnum.console.value)
|
||||
library = self._config.get_configuration(ProjectTypeEnum.library.value)
|
||||
if console is not None and library is None:
|
||||
unittest = self._config.get_configuration(ProjectTypeEnum.unittest.value)
|
||||
if console is not None and library is None and unittest is None:
|
||||
self._name = console
|
||||
self._schematic = ProjectTypeEnum.console.value
|
||||
self._console(args)
|
||||
if self._use_venv:
|
||||
self._create_venv()
|
||||
|
||||
elif console is None and library is not None:
|
||||
elif console is None and library is not None and unittest is None:
|
||||
self._name = library
|
||||
self._schematic = ProjectTypeEnum.library.value
|
||||
self._library(args)
|
||||
if self._use_venv:
|
||||
self._create_venv()
|
||||
|
||||
elif console is None and library is None and unittest is not None:
|
||||
self._name = unittest
|
||||
self._schematic = ProjectTypeEnum.unittest.value
|
||||
self._unittest(args)
|
||||
if self._use_venv:
|
||||
self._create_venv()
|
||||
|
||||
else:
|
||||
self._help('Usage: cpl new <schematic> [options]')
|
||||
|
@@ -3,12 +3,14 @@ import shutil
|
||||
import json
|
||||
import textwrap
|
||||
|
||||
from cpl_cli.configuration.settings_helper import SettingsHelper
|
||||
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
|
||||
from cpl_cli.command_abc import CommandABC
|
||||
from cpl_cli.configuration import WorkspaceSettings, WorkspaceSettingsNameEnum
|
||||
from cpl_cli.configuration import WorkspaceSettings, WorkspaceSettingsNameEnum, BuildSettingsNameEnum, ProjectSettings, BuildSettings
|
||||
|
||||
|
||||
class RemoveService(CommandABC):
|
||||
@@ -52,8 +54,9 @@ class RemoveService(CommandABC):
|
||||
project_json.write(json.dumps(content, indent=2))
|
||||
project_json.close()
|
||||
|
||||
@staticmethod
|
||||
def _remove_sources(path: str):
|
||||
def _remove_sources(self, path: str):
|
||||
if self._is_simulation:
|
||||
return
|
||||
shutil.rmtree(path)
|
||||
|
||||
def _create_workspace(self, path: str):
|
||||
@@ -67,6 +70,50 @@ class RemoveService(CommandABC):
|
||||
|
||||
self._create_file(path, ws_dict)
|
||||
|
||||
def _get_project_settings(self, project: str) -> dict:
|
||||
with open(os.path.join(os.getcwd(), self._workspace.projects[project]), 'r', encoding='utf-8') as cfg:
|
||||
# load json
|
||||
project_json = json.load(cfg)
|
||||
cfg.close()
|
||||
|
||||
return project_json
|
||||
|
||||
def _write_project_settings(self, project: str, project_settings: dict, build_settings: dict):
|
||||
with open(os.path.join(os.getcwd(), self._workspace.projects[project]), 'w', encoding='utf-8') as file:
|
||||
file.write(json.dumps({
|
||||
ProjectSettings.__name__: project_settings,
|
||||
BuildSettings.__name__: build_settings
|
||||
}, indent=2))
|
||||
file.close()
|
||||
|
||||
def _find_deps_in_projects(self, project_name: str, rel_path: str):
|
||||
for project in self._workspace.projects:
|
||||
if project == project_name:
|
||||
continue
|
||||
|
||||
project_settings = self._get_project_settings(project)
|
||||
if BuildSettings.__name__ not in project_settings or BuildSettingsNameEnum.project_references.value not in project_settings[BuildSettings.__name__]:
|
||||
continue
|
||||
|
||||
ref_to_delete = ''
|
||||
for ref in project_settings[BuildSettings.__name__][BuildSettingsNameEnum.project_references.value]:
|
||||
if os.path.basename(ref) == f'{project_name}.json':
|
||||
ref_to_delete = ref
|
||||
|
||||
if ref_to_delete not in project_settings[BuildSettings.__name__][BuildSettingsNameEnum.project_references.value]:
|
||||
continue
|
||||
|
||||
project_settings[BuildSettings.__name__][BuildSettingsNameEnum.project_references.value].remove(ref_to_delete)
|
||||
Console.spinner(
|
||||
f'Removing {project_name} from {project}',
|
||||
self._write_project_settings,
|
||||
project,
|
||||
project_settings[ProjectSettings.__name__],
|
||||
project_settings[BuildSettings.__name__],
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
spinner_foreground_color=ForegroundColorEnum.cyan
|
||||
)
|
||||
|
||||
def execute(self, args: list[str]):
|
||||
"""
|
||||
Entry point of command
|
||||
@@ -87,15 +134,17 @@ class RemoveService(CommandABC):
|
||||
Console.error(f'Project {project_name} is the default project.')
|
||||
return
|
||||
|
||||
src_path = os.path.abspath(os.path.dirname(self._workspace.projects[project_name]))
|
||||
src_path = os.path.dirname(self._workspace.projects[project_name])
|
||||
Console.spinner(
|
||||
f'Removing {src_path}',
|
||||
self._remove_sources,
|
||||
src_path,
|
||||
os.path.abspath(src_path),
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
spinner_foreground_color=ForegroundColorEnum.cyan
|
||||
)
|
||||
|
||||
self._find_deps_in_projects(project_name, src_path)
|
||||
|
||||
del self._workspace.projects[project_name]
|
||||
path = 'cpl-workspace.json'
|
||||
Console.spinner(
|
||||
|
95
src/cpl_cli/command/run_service.py
Normal file
95
src/cpl_cli/command/run_service.py
Normal file
@@ -0,0 +1,95 @@
|
||||
import os
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
from cpl_cli import Error
|
||||
from cpl_cli.command_abc import CommandABC
|
||||
from cpl_cli.configuration import WorkspaceSettings
|
||||
from cpl_cli.configuration.build_settings import BuildSettings
|
||||
from cpl_cli.configuration.project_settings import ProjectSettings
|
||||
from cpl_cli.live_server.start_executable import StartExecutable
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
|
||||
|
||||
|
||||
class RunService(CommandABC):
|
||||
|
||||
def __init__(self,
|
||||
config: ConfigurationABC,
|
||||
env: ApplicationEnvironmentABC,
|
||||
services: ServiceProviderABC,
|
||||
project_settings: ProjectSettings,
|
||||
build_settings: BuildSettings,
|
||||
workspace: WorkspaceSettings
|
||||
):
|
||||
"""
|
||||
Service for the CLI command start
|
||||
:param config:
|
||||
:param env:
|
||||
:param services:
|
||||
:param project_settings:
|
||||
:param build_settings:
|
||||
:param workspace:
|
||||
"""
|
||||
CommandABC.__init__(self)
|
||||
|
||||
self._config = config
|
||||
self._env = env
|
||||
self._services = services
|
||||
self._project_settings = project_settings
|
||||
self._build_settings = build_settings
|
||||
self._workspace = workspace
|
||||
|
||||
self._src_dir = os.path.join(self._env.working_directory, self._build_settings.source_path)
|
||||
|
||||
@property
|
||||
def help_message(self) -> str:
|
||||
return textwrap.dedent("""\
|
||||
Starts your application.
|
||||
Usage: cpl run
|
||||
""")
|
||||
|
||||
def _set_project_by_args(self, name: str):
|
||||
if self._workspace is None:
|
||||
Error.error('The command requires to be run in an CPL workspace, but a workspace could not be found.')
|
||||
sys.exit()
|
||||
|
||||
if name not in self._workspace.projects:
|
||||
Error.error(f'Project {name} not found in workspace')
|
||||
sys.exit()
|
||||
|
||||
project_path = self._workspace.projects[name]
|
||||
|
||||
self._config.add_configuration(ProjectSettings, None)
|
||||
self._config.add_configuration(BuildSettings, None)
|
||||
|
||||
working_directory = self._config.get_configuration('PATH_WORKSPACE')
|
||||
if working_directory is not None:
|
||||
self._env.set_working_directory(working_directory)
|
||||
|
||||
json_file = os.path.join(self._env.working_directory, project_path)
|
||||
self._config.add_json_file(json_file, optional=True, output=False)
|
||||
self._project_settings: ProjectSettings = self._config.get_configuration(ProjectSettings)
|
||||
self._build_settings: BuildSettings = self._config.get_configuration(BuildSettings)
|
||||
|
||||
if self._project_settings is None or self._build_settings is None:
|
||||
Error.error(f'Project {name} not found')
|
||||
sys.exit()
|
||||
|
||||
self._src_dir = os.path.dirname(json_file)
|
||||
|
||||
def execute(self, args: list[str]):
|
||||
"""
|
||||
Entry point of command
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
if len(args) >= 1:
|
||||
self._set_project_by_args(args[0])
|
||||
args.remove(args[0])
|
||||
|
||||
start_service = StartExecutable(self._env, self._build_settings)
|
||||
start_service.run(args, self._project_settings.python_executable, self._src_dir, output=False)
|
||||
Console.write_line()
|
@@ -4,6 +4,7 @@ import subprocess
|
||||
import textwrap
|
||||
import time
|
||||
|
||||
from cpl_cli.configuration.venv_helper_service import VenvHelper
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
|
||||
@@ -35,6 +36,9 @@ class UninstallService(CommandABC):
|
||||
|
||||
self._is_simulating = False
|
||||
self._is_virtual = False
|
||||
self._is_dev = False
|
||||
|
||||
self._project_file = f'{self._project_settings.name}.json'
|
||||
|
||||
@property
|
||||
def help_message(self) -> str:
|
||||
@@ -60,6 +64,9 @@ class UninstallService(CommandABC):
|
||||
Console.error(f'Usage: cpl uninstall <package>')
|
||||
return
|
||||
|
||||
if 'dev' in args:
|
||||
self._is_dev = True
|
||||
args.remove('dev')
|
||||
|
||||
if '--virtual' in args:
|
||||
self._is_virtual = True
|
||||
@@ -71,8 +78,7 @@ class UninstallService(CommandABC):
|
||||
args.remove('--simulate')
|
||||
Console.write_line('Running in simulation mode:')
|
||||
|
||||
if not self._is_virtual:
|
||||
Pip.set_executable(self._project_settings.python_executable)
|
||||
VenvHelper.init_venv(self._is_virtual, self._env, self._project_settings)
|
||||
|
||||
package = args[0]
|
||||
is_in_dependencies = False
|
||||
@@ -82,7 +88,11 @@ class UninstallService(CommandABC):
|
||||
else:
|
||||
pip_package = package
|
||||
|
||||
for dependency in self._project_settings.dependencies:
|
||||
deps = self._project_settings.dependencies
|
||||
if self._is_dev:
|
||||
deps = self._project_settings.dev_dependencies
|
||||
|
||||
for dependency in deps:
|
||||
if package in dependency:
|
||||
is_in_dependencies = True
|
||||
package = dependency
|
||||
@@ -95,7 +105,7 @@ class UninstallService(CommandABC):
|
||||
package = pip_package
|
||||
|
||||
Console.spinner(
|
||||
f'Uninstalling: {package}',
|
||||
f'Uninstalling: {package}' if not self._is_dev else f'Uninstalling dev: {package}',
|
||||
Pip.uninstall if not self._is_virtual else self._wait, package if not self._is_virtual else 2,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
@@ -103,14 +113,18 @@ class UninstallService(CommandABC):
|
||||
spinner_foreground_color=ForegroundColorEnum.cyan
|
||||
)
|
||||
|
||||
if package in self._project_settings.dependencies:
|
||||
self._project_settings.dependencies.remove(package)
|
||||
deps = self._project_settings.dependencies
|
||||
if self._is_dev:
|
||||
deps = self._project_settings.dev_dependencies
|
||||
|
||||
if package in deps:
|
||||
deps.remove(package)
|
||||
if not self._is_simulating:
|
||||
config = {
|
||||
ProjectSettings.__name__: SettingsHelper.get_project_settings_dict(self._project_settings),
|
||||
BuildSettings.__name__: SettingsHelper.get_build_settings_dict(self._build_settings)
|
||||
}
|
||||
with open(os.path.join(self._env.working_directory, f'{self._config.get_configuration("ProjectName")}.json'), 'w') as project_file:
|
||||
with open(os.path.join(self._env.working_directory, self._project_file), 'w') as project_file:
|
||||
project_file.write(json.dumps(config, indent=2))
|
||||
project_file.close()
|
||||
|
||||
|
@@ -3,6 +3,7 @@ import os
|
||||
import subprocess
|
||||
import textwrap
|
||||
|
||||
from cpl_cli.configuration.venv_helper_service import VenvHelper
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
|
||||
@@ -40,6 +41,8 @@ class UpdateService(CommandABC):
|
||||
self._cli_settings = cli_settings
|
||||
self._is_simulation = False
|
||||
|
||||
self._project_file = f'{self._project_settings.name}.json'
|
||||
|
||||
@property
|
||||
def help_message(self) -> str:
|
||||
return textwrap.dedent("""\
|
||||
@@ -73,7 +76,7 @@ class UpdateService(CommandABC):
|
||||
'--upgrade',
|
||||
'--upgrade-strategy',
|
||||
'eager',
|
||||
source=self._cli_settings.pip_path if 'sh_cpl' in name else None,
|
||||
source=self._cli_settings.pip_path if 'cpl-' in name else None,
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL
|
||||
)
|
||||
@@ -81,7 +84,7 @@ class UpdateService(CommandABC):
|
||||
new_package = Pip.get_package(name)
|
||||
if new_package is None:
|
||||
Console.error(f'Update for package {package} failed')
|
||||
return
|
||||
continue
|
||||
|
||||
self._project_json_update_dependency(package, new_package)
|
||||
|
||||
@@ -151,8 +154,7 @@ class UpdateService(CommandABC):
|
||||
BuildSettings.__name__: SettingsHelper.get_build_settings_dict(self._build_settings)
|
||||
}
|
||||
|
||||
with open(os.path.join(self._env.working_directory, f'{self._config.get_configuration("ProjectName")}.json'),
|
||||
'w') as project:
|
||||
with open(os.path.join(self._env.working_directory, self._project_file), 'w') as project:
|
||||
project.write(json.dumps(config, indent=2))
|
||||
project.close()
|
||||
|
||||
@@ -167,7 +169,8 @@ class UpdateService(CommandABC):
|
||||
Console.write_line('Running in simulation mode:')
|
||||
self._is_simulation = True
|
||||
|
||||
Pip.set_executable(self._project_settings.python_executable)
|
||||
VenvHelper.init_venv(False, self._env, self._project_settings)
|
||||
|
||||
self._check_project_dependencies()
|
||||
self._check_outdated()
|
||||
Pip.reset_executable()
|
||||
|
@@ -5,7 +5,6 @@ import pkg_resources
|
||||
import textwrap
|
||||
|
||||
import cpl_cli
|
||||
import cpl_core
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl_cli.command_abc import CommandABC
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli.configuration'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -30,4 +30,4 @@ from .workspace_settings import WorkspaceSettings
|
||||
from .workspace_settings_name_enum import WorkspaceSettingsNameEnum
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -3,12 +3,12 @@ import sys
|
||||
import traceback
|
||||
from typing import Optional
|
||||
|
||||
from cpl_cli.configuration.project_settings_name_enum import ProjectSettingsNameEnum
|
||||
from cpl_cli.configuration.version_settings import VersionSettings
|
||||
from cpl_cli.error import Error
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl_cli.configuration.version_settings import VersionSettings
|
||||
from cpl_cli.configuration.project_settings_name_enum import ProjectSettingsNameEnum
|
||||
from cpl_cli.error import Error
|
||||
|
||||
|
||||
class ProjectSettings(ConfigurationModelABC):
|
||||
@@ -28,6 +28,7 @@ class ProjectSettings(ConfigurationModelABC):
|
||||
self._license_name: Optional[str] = None
|
||||
self._license_description: Optional[str] = None
|
||||
self._dependencies: Optional[list[str]] = None
|
||||
self._dev_dependencies: Optional[list[str]] = None
|
||||
self._python_version: Optional[str] = None
|
||||
self._python_path: Optional[str] = None
|
||||
self._python_executable: Optional[str] = None
|
||||
@@ -81,6 +82,10 @@ class ProjectSettings(ConfigurationModelABC):
|
||||
def dependencies(self) -> list[str]:
|
||||
return self._dependencies
|
||||
|
||||
@property
|
||||
def dev_dependencies(self) -> list[str]:
|
||||
return self._dev_dependencies
|
||||
|
||||
@property
|
||||
def python_version(self) -> str:
|
||||
return self._python_version
|
||||
@@ -111,16 +116,16 @@ class ProjectSettings(ConfigurationModelABC):
|
||||
self._license_name = settings[ProjectSettingsNameEnum.license_name.value]
|
||||
self._license_description = settings[ProjectSettingsNameEnum.license_description.value]
|
||||
self._dependencies = settings[ProjectSettingsNameEnum.dependencies.value]
|
||||
if ProjectSettingsNameEnum.dev_dependencies.value not in settings:
|
||||
settings[ProjectSettingsNameEnum.dev_dependencies.value] = []
|
||||
self._dev_dependencies = settings[ProjectSettingsNameEnum.dev_dependencies.value]
|
||||
self._python_version = settings[ProjectSettingsNameEnum.python_version.value]
|
||||
self._python_path = settings[ProjectSettingsNameEnum.python_path.value]
|
||||
|
||||
if ProjectSettingsNameEnum.python_path.value in settings and \
|
||||
sys.platform in settings[ProjectSettingsNameEnum.python_path.value]:
|
||||
if ProjectSettingsNameEnum.python_path.value in settings and sys.platform in settings[ProjectSettingsNameEnum.python_path.value]:
|
||||
path = settings[ProjectSettingsNameEnum.python_path.value][sys.platform]
|
||||
if not os.path.isfile(path) and not os.path.islink(path):
|
||||
if path != '' and path is not None:
|
||||
Error.warn(f'{ProjectSettingsNameEnum.python_path.value} not found')
|
||||
|
||||
if path == '' or path is None:
|
||||
Error.warn(f'{ProjectSettingsNameEnum.python_path.value} not found')
|
||||
path = sys.executable
|
||||
else:
|
||||
path = sys.executable
|
||||
@@ -134,7 +139,6 @@ class ProjectSettings(ConfigurationModelABC):
|
||||
|
||||
except Exception as e:
|
||||
Console.set_foreground_color(ForegroundColorEnum.red)
|
||||
Console.write_line(
|
||||
f'[ ERROR ] [ {__name__} ]: Reading error in {ProjectSettings.__name__} settings')
|
||||
Console.write_line(f'[ ERROR ] [ {__name__} ]: Reading error in {ProjectSettings.__name__} settings')
|
||||
Console.write_line(f'[ EXCEPTION ] [ {__name__} ]: {e} -> {traceback.format_exc()}')
|
||||
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||
|
@@ -14,6 +14,7 @@ class ProjectSettingsNameEnum(Enum):
|
||||
license_name = 'LicenseName'
|
||||
license_description = 'LicenseDescription'
|
||||
dependencies = 'Dependencies'
|
||||
dev_dependencies = 'DevDependencies'
|
||||
python_version = 'PythonVersion'
|
||||
python_path = 'PythonPath'
|
||||
classifiers = 'Classifiers'
|
||||
|
@@ -5,3 +5,4 @@ class ProjectTypeEnum(Enum):
|
||||
|
||||
console = 'console'
|
||||
library = 'library'
|
||||
unittest = 'unittest'
|
||||
|
@@ -26,6 +26,7 @@ class SettingsHelper:
|
||||
ProjectSettingsNameEnum.license_name.value: project.license_name,
|
||||
ProjectSettingsNameEnum.license_description.value: project.license_description,
|
||||
ProjectSettingsNameEnum.dependencies.value: project.dependencies,
|
||||
ProjectSettingsNameEnum.dev_dependencies.value: project.dev_dependencies,
|
||||
ProjectSettingsNameEnum.python_version.value: project.python_version,
|
||||
ProjectSettingsNameEnum.python_path.value: project.python_path,
|
||||
ProjectSettingsNameEnum.classifiers.value: project.classifiers
|
||||
|
43
src/cpl_cli/configuration/venv_helper_service.py
Normal file
43
src/cpl_cli/configuration/venv_helper_service.py
Normal file
@@ -0,0 +1,43 @@
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from cpl_cli.configuration import ProjectSettings
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
|
||||
from cpl_core.utils import Pip
|
||||
|
||||
from cpl_core.console import Console, ForegroundColorEnum
|
||||
|
||||
|
||||
class VenvHelper:
|
||||
|
||||
@staticmethod
|
||||
def init_venv(is_virtual: bool, env: ApplicationEnvironmentABC, project_settings: ProjectSettings, explicit_path=None):
|
||||
if is_virtual:
|
||||
return
|
||||
|
||||
venv_path = os.path.abspath(os.path.join(env.working_directory, project_settings.python_executable))
|
||||
|
||||
if explicit_path is not None:
|
||||
venv_path = os.path.abspath(explicit_path)
|
||||
|
||||
if not os.path.exists(venv_path):
|
||||
Console.spinner(
|
||||
f'Creating venv: {venv_path}',
|
||||
VenvHelper.create_venv,
|
||||
venv_path,
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
spinner_foreground_color=ForegroundColorEnum.cyan
|
||||
)
|
||||
|
||||
Pip.set_executable(venv_path)
|
||||
|
||||
@staticmethod
|
||||
def create_venv(path):
|
||||
subprocess.run(
|
||||
[sys.executable, '-m', 'venv', os.path.abspath(os.path.join(path, '../../'))],
|
||||
stdout=subprocess.DEVNULL,
|
||||
stderr=subprocess.DEVNULL,
|
||||
stdin=subprocess.DEVNULL
|
||||
)
|
@@ -4,7 +4,7 @@
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "6",
|
||||
"Micro": "3"
|
||||
"Micro": "0.rc1"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
@@ -16,10 +16,13 @@
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.6.3"
|
||||
"cpl-core>=2022.6.0.rc1"
|
||||
],
|
||||
"DevDependencies": [],
|
||||
"PythonVersion": ">=3.10",
|
||||
"PythonPath": {},
|
||||
"PythonPath": {
|
||||
"linux": "../../venv"
|
||||
},
|
||||
"Classifiers": []
|
||||
},
|
||||
"BuildSettings": {
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli.live_server'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -35,8 +35,6 @@ class LiveServerThread(threading.Thread):
|
||||
self._command = []
|
||||
self._env_vars = os.environ
|
||||
|
||||
self._set_venv()
|
||||
|
||||
@property
|
||||
def command(self) -> list[str]:
|
||||
return self._command
|
||||
@@ -45,16 +43,6 @@ class LiveServerThread(threading.Thread):
|
||||
def main(self) -> str:
|
||||
return self._main
|
||||
|
||||
def _set_venv(self):
|
||||
if self._executable != sys.executable:
|
||||
path = os.path.abspath(os.path.dirname(os.path.dirname(self._executable)))
|
||||
if sys.platform == 'win32':
|
||||
self._env_vars['PATH'] = f'{path}\\bin' + os.pathsep + os.environ.get('PATH', '')
|
||||
else:
|
||||
self._env_vars['PATH'] = f'{path}/bin' + os.pathsep + os.environ.get('PATH', '')
|
||||
|
||||
self._env_vars['VIRTUAL_ENV'] = path
|
||||
|
||||
def run(self):
|
||||
"""
|
||||
Starts the CPL project
|
||||
@@ -88,7 +76,9 @@ class LiveServerThread(threading.Thread):
|
||||
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||
|
||||
self._command = [self._executable, self._main]
|
||||
if len(self._args) > 0:
|
||||
self._command.append(''.join(self._args))
|
||||
# if len(self._args) > 0:
|
||||
# self._command.append(' '.join(self._args))
|
||||
for arg in self._args:
|
||||
self._command.append(arg)
|
||||
|
||||
subprocess.run(self._command, env=self._env_vars)
|
||||
|
81
src/cpl_cli/live_server/start_executable.py
Normal file
81
src/cpl_cli/live_server/start_executable.py
Normal file
@@ -0,0 +1,81 @@
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import threading
|
||||
from datetime import datetime
|
||||
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
|
||||
from cpl_cli.configuration import BuildSettings
|
||||
|
||||
|
||||
class StartExecutable:
|
||||
|
||||
def __init__(self, env: ApplicationEnvironmentABC, build_settings: BuildSettings):
|
||||
"""
|
||||
Service to start the CPL project for the live development server
|
||||
:param env:
|
||||
:param build_settings:
|
||||
"""
|
||||
|
||||
self._executable = None
|
||||
|
||||
self._env = env
|
||||
self._build_settings = build_settings
|
||||
|
||||
self._main = ''
|
||||
self._command = []
|
||||
self._env_vars = os.environ
|
||||
|
||||
self._set_venv()
|
||||
|
||||
def _set_venv(self):
|
||||
if self._executable is None or self._executable == sys.executable:
|
||||
return
|
||||
|
||||
path = os.path.abspath(os.path.dirname(os.path.dirname(self._executable)))
|
||||
if sys.platform == 'win32':
|
||||
self._env_vars['PATH'] = f'{path}\\bin' + os.pathsep + os.environ.get('PATH', '')
|
||||
else:
|
||||
self._env_vars['PATH'] = f'{path}/bin' + os.pathsep + os.environ.get('PATH', '')
|
||||
|
||||
self._env_vars['VIRTUAL_ENV'] = path
|
||||
|
||||
def run(self, args: list[str], executable: str, path: str, output=True):
|
||||
self._executable = os.path.abspath(executable)
|
||||
|
||||
main = self._build_settings.main
|
||||
if '.' in self._build_settings.main:
|
||||
length = len(self._build_settings.main.split('.')) - 1
|
||||
main = self._build_settings.main.split('.')[length]
|
||||
|
||||
self._main = os.path.join(path, f'{main}.py')
|
||||
if not os.path.isfile(self._main):
|
||||
Console.error('Entry point main.py not found')
|
||||
return
|
||||
|
||||
# set cwd to src/
|
||||
self._env.set_working_directory(os.path.abspath(os.path.join(path)))
|
||||
src_cwd = os.path.abspath(os.path.join(path, '../'))
|
||||
if sys.platform == 'win32':
|
||||
self._env_vars['PYTHONPATH'] = f'{src_cwd};' \
|
||||
f'{os.path.join(self._env.working_directory, self._build_settings.source_path)}'
|
||||
else:
|
||||
self._env_vars['PYTHONPATH'] = f'{src_cwd}:' \
|
||||
f'{os.path.join(self._env.working_directory, self._build_settings.source_path)}'
|
||||
|
||||
if output:
|
||||
Console.set_foreground_color(ForegroundColorEnum.green)
|
||||
Console.write_line('Read successfully')
|
||||
Console.set_foreground_color(ForegroundColorEnum.cyan)
|
||||
Console.write_line(f'Started at {datetime.now().strftime("%Y-%m-%d %H:%M:%S")}\n\n')
|
||||
Console.set_foreground_color(ForegroundColorEnum.default)
|
||||
|
||||
self._command = [self._executable, self._main]
|
||||
# if len(self._args) > 0:
|
||||
# self._command.append(' '.join(self._args))
|
||||
for arg in args:
|
||||
self._command.append(arg)
|
||||
|
||||
subprocess.run(self._command, env=self._env_vars)
|
@@ -5,6 +5,7 @@ import pkg_resources
|
||||
from cpl_cli.cli import CLI
|
||||
from cpl_cli.startup import Startup
|
||||
from cpl_cli.startup_argument_extension import StartupArgumentExtension
|
||||
from cpl_cli.startup_workspace_extension import StartupWorkspaceExtension
|
||||
from cpl_core.application.application_builder import ApplicationBuilder
|
||||
from cpl_core.application.startup_extension_abc import StartupExtensionABC
|
||||
|
||||
@@ -31,6 +32,7 @@ def get_startup_extensions() -> list[Type[StartupExtensionABC]]:
|
||||
def main():
|
||||
app_builder = ApplicationBuilder(CLI)
|
||||
app_builder.use_startup(Startup)
|
||||
app_builder.use_extension(StartupWorkspaceExtension)
|
||||
app_builder.use_extension(StartupArgumentExtension)
|
||||
for extension in get_startup_extensions():
|
||||
app_builder.use_extension(extension)
|
||||
@@ -41,12 +43,12 @@ def main():
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
|
||||
# ((
|
||||
# ( `)
|
||||
# ; / ,
|
||||
# / \/
|
||||
# / |
|
||||
# / ~/
|
||||
# / ) ) ~ edraft
|
||||
# ___// | /
|
||||
# `--' \_~-,
|
||||
# ((
|
||||
# ( `)
|
||||
# ; / ,
|
||||
# / \/
|
||||
# / |
|
||||
# / ~/
|
||||
# / ) ) ~ edraft
|
||||
# ___// | /
|
||||
# `--' \_~-,
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_cli.publish'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -24,4 +24,4 @@ from .publisher_abc import PublisherABC
|
||||
from .publisher_service import PublisherService
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -426,7 +426,7 @@ class PublisherService(PublisherABC):
|
||||
:return:
|
||||
"""
|
||||
self._env.set_working_directory(os.path.join(self._env.working_directory, '../'))
|
||||
self.exclude(f'*/{self._config.get_configuration("ProjectName")}.json')
|
||||
self.exclude(f'*/{self._project_settings.name}.json')
|
||||
self._output_path = os.path.abspath(os.path.join(self._output_path, self._project_settings.name, 'build'))
|
||||
|
||||
Console.spinner('Reading source files:', self._read_sources, text_foreground_color=ForegroundColorEnum.green,
|
||||
@@ -449,7 +449,7 @@ class PublisherService(PublisherABC):
|
||||
:return:
|
||||
"""
|
||||
self._env.set_working_directory(os.path.join(self._env.working_directory, '../'))
|
||||
self.exclude(f'*/{self._config.get_configuration("ProjectName")}.json')
|
||||
self.exclude(f'*/{self._project_settings.name}.json')
|
||||
self._output_path = os.path.abspath(os.path.join(self._output_path, self._project_settings.name, 'publish'))
|
||||
|
||||
Console.write_line('Build:')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli.source_creator'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
164
src/cpl_cli/source_creator/unittest_builder.py
Normal file
164
src/cpl_cli/source_creator/unittest_builder.py
Normal file
@@ -0,0 +1,164 @@
|
||||
import json
|
||||
import os
|
||||
from typing import Optional
|
||||
|
||||
from cpl_cli._templates.new.unittest.license import LicenseTemplate
|
||||
from cpl_cli._templates.new.unittest.readme_py import ReadmeTemplate
|
||||
from cpl_cli._templates.new.unittest.source.name.application import ApplicationTemplate
|
||||
from cpl_cli._templates.new.unittest.source.name.init import MainInitTemplate
|
||||
from cpl_cli._templates.new.unittest.source.name.main import MainWithApplicationBaseTemplate
|
||||
from cpl_cli._templates.new.unittest.source.name.test_case import TestCaseTemplate
|
||||
from cpl_cli._templates.template_file_abc import TemplateFileABC
|
||||
from cpl_cli.configuration.workspace_settings import WorkspaceSettings
|
||||
from cpl_cli.configuration.workspace_settings_name_enum import WorkspaceSettingsNameEnum
|
||||
from cpl_cli.source_creator.template_builder import TemplateBuilder
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.console.foreground_color_enum import ForegroundColorEnum
|
||||
from cpl_core.utils.string import String
|
||||
|
||||
|
||||
class UnittestBuilder:
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def _create_file(file_name: str, content: dict):
|
||||
if not os.path.isabs(file_name):
|
||||
file_name = os.path.abspath(file_name)
|
||||
|
||||
path = os.path.dirname(file_name)
|
||||
if not os.path.isdir(path):
|
||||
os.makedirs(path)
|
||||
|
||||
with open(file_name, 'w') as project_json:
|
||||
project_json.write(json.dumps(content, indent=2))
|
||||
project_json.close()
|
||||
|
||||
@classmethod
|
||||
def _create_workspace(cls, path: str, project_name, projects: dict, scripts: dict):
|
||||
ws_dict = {
|
||||
WorkspaceSettings.__name__: {
|
||||
WorkspaceSettingsNameEnum.default_project.value: project_name,
|
||||
WorkspaceSettingsNameEnum.projects.value: projects,
|
||||
WorkspaceSettingsNameEnum.scripts.value: scripts
|
||||
}
|
||||
}
|
||||
|
||||
Console.spinner(
|
||||
f'Creating {path}',
|
||||
cls._create_file,
|
||||
path,
|
||||
ws_dict,
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
spinner_foreground_color=ForegroundColorEnum.cyan
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def build(cls, project_path: str, use_application_api: bool,
|
||||
use_async: bool, project_name: str, project_settings: dict, workspace: Optional[WorkspaceSettings]):
|
||||
"""
|
||||
Builds the console project files
|
||||
:param project_path:
|
||||
:param use_application_api:
|
||||
:param use_async:
|
||||
:param project_name:
|
||||
:param project_settings:
|
||||
:param workspace:
|
||||
:return:
|
||||
"""
|
||||
pj_name = project_name
|
||||
if '/' in pj_name:
|
||||
pj_name = pj_name.split('/')[len(pj_name.split('/')) - 1]
|
||||
|
||||
project_name_snake = String.convert_to_snake_case(pj_name)
|
||||
|
||||
if workspace is None:
|
||||
templates: list[TemplateFileABC] = [
|
||||
LicenseTemplate(),
|
||||
ReadmeTemplate(),
|
||||
MainInitTemplate(project_name, os.path.join('src/', project_name_snake))
|
||||
]
|
||||
else:
|
||||
project_path = os.path.join(
|
||||
os.path.dirname(project_path),
|
||||
project_name_snake
|
||||
)
|
||||
|
||||
templates: list[TemplateFileABC] = [
|
||||
MainInitTemplate('', '')
|
||||
]
|
||||
|
||||
if not os.path.isdir(project_path):
|
||||
os.makedirs(project_path)
|
||||
|
||||
py_src_rel_path = ''
|
||||
src_name = project_name_snake
|
||||
if workspace is None:
|
||||
py_src_rel_path = f'src/{src_name}'
|
||||
|
||||
templates.append(ApplicationTemplate(src_name, py_src_rel_path, use_async))
|
||||
templates.append(MainWithApplicationBaseTemplate(src_name, py_src_rel_path, use_async))
|
||||
templates.append(TestCaseTemplate(src_name, py_src_rel_path, use_async))
|
||||
|
||||
src_rel_path = ''
|
||||
if '/' in project_name:
|
||||
old_pj_name = project_name
|
||||
parts = project_name.split('/')
|
||||
project_name = parts[len(parts) - 1]
|
||||
src_rel_path = old_pj_name.split(project_name)[0]
|
||||
|
||||
proj_name = project_name
|
||||
if src_rel_path.endswith('/'):
|
||||
src_rel_path = src_rel_path[:len(src_rel_path) - 1]
|
||||
|
||||
if src_rel_path != '':
|
||||
proj_name = f'{src_rel_path}/{project_name}'
|
||||
if workspace is not None:
|
||||
proj_name = project_name_snake
|
||||
|
||||
if src_rel_path != '':
|
||||
project_file_path = f'{src_rel_path}/{project_name_snake}/{project_name}.json'
|
||||
else:
|
||||
project_file_path = f'{project_name_snake}/{project_name}.json'
|
||||
|
||||
if workspace is None:
|
||||
src_path = f'src/{project_name_snake}'
|
||||
workspace_file_path = f'{proj_name}/cpl-workspace.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_rel_path
|
||||
},
|
||||
{}
|
||||
)
|
||||
|
||||
else:
|
||||
workspace.projects[project_name] = f'src/{project_file_path}'
|
||||
cls._create_workspace('cpl-workspace.json', workspace.default_project, workspace.projects, workspace.scripts)
|
||||
|
||||
Console.spinner(
|
||||
f'Creating {project_file_path}',
|
||||
cls._create_file,
|
||||
project_file_path if workspace is None else f'src/{project_file_path}',
|
||||
project_settings,
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
spinner_foreground_color=ForegroundColorEnum.cyan
|
||||
)
|
||||
|
||||
for template in templates:
|
||||
divider = ''
|
||||
if template.path != '' and not template.path.endswith('/'):
|
||||
divider = '/'
|
||||
|
||||
Console.spinner(
|
||||
f'Creating {proj_name}/{template.path}{divider}{template.name}',
|
||||
TemplateBuilder.build,
|
||||
project_path,
|
||||
template,
|
||||
text_foreground_color=ForegroundColorEnum.green,
|
||||
spinner_foreground_color=ForegroundColorEnum.cyan
|
||||
)
|
@@ -1,5 +1,25 @@
|
||||
import os
|
||||
|
||||
from cpl_cli.command.add_service import AddService
|
||||
from cpl_cli.command.build_service import BuildService
|
||||
from cpl_cli.command.custom_script_service import CustomScriptService
|
||||
from cpl_cli.command.generate_service import GenerateService
|
||||
from cpl_cli.command.help_service import HelpService
|
||||
from cpl_cli.command.install_service import InstallService
|
||||
from cpl_cli.command.new_service import NewService
|
||||
from cpl_cli.command.publish_service import PublishService
|
||||
from cpl_cli.command.remove_service import RemoveService
|
||||
from cpl_cli.command.run_service import RunService
|
||||
from cpl_cli.command.start_service import StartService
|
||||
from cpl_cli.command.uninstall_service import UninstallService
|
||||
from cpl_cli.command.update_service import UpdateService
|
||||
from cpl_cli.command.version_service import VersionService
|
||||
from cpl_cli.validators.project_validator import ProjectValidator
|
||||
|
||||
from cpl_cli.validators.workspace_validator import WorkspaceValidator
|
||||
|
||||
from cpl_core.console import Console
|
||||
|
||||
from cpl_cli.error import Error
|
||||
from cpl_cli.live_server.live_server_service import LiveServerService
|
||||
from cpl_cli.publish.publisher_abc import PublisherABC
|
||||
@@ -8,7 +28,7 @@ from cpl_core.application.startup_abc import StartupABC
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.dependency_injection.service_collection_abc import ServiceCollectionABC
|
||||
from cpl_core.dependency_injection.service_provider_abc import ServiceProviderABC
|
||||
from cpl_core.environment import ApplicationEnvironment
|
||||
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
|
||||
|
||||
|
||||
class Startup(StartupABC):
|
||||
@@ -16,18 +36,41 @@ class Startup(StartupABC):
|
||||
def __init__(self):
|
||||
StartupABC.__init__(self)
|
||||
|
||||
def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironment) -> ConfigurationABC:
|
||||
def configure_configuration(self, configuration: ConfigurationABC, environment: ApplicationEnvironmentABC) -> ConfigurationABC:
|
||||
environment.set_runtime_directory(os.path.dirname(__file__))
|
||||
configuration.argument_error_function = Error.error
|
||||
|
||||
configuration.add_environment_variables('PYTHON_')
|
||||
configuration.add_environment_variables('CPL_')
|
||||
|
||||
is_unittest = configuration.get_configuration('IS_UNITTEST')
|
||||
if is_unittest == 'YES':
|
||||
Console.disable()
|
||||
|
||||
configuration.add_json_file('appsettings.json', path=environment.runtime_directory, optional=False, output=False)
|
||||
|
||||
return configuration
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironment) -> ServiceProviderABC:
|
||||
def configure_services(self, services: ServiceCollectionABC, environment: ApplicationEnvironmentABC) -> ServiceProviderABC:
|
||||
services.add_transient(PublisherABC, PublisherService)
|
||||
services.add_transient(LiveServerService)
|
||||
|
||||
services.add_transient(WorkspaceValidator)
|
||||
services.add_transient(ProjectValidator)
|
||||
|
||||
services.add_transient(AddService)
|
||||
services.add_transient(BuildService)
|
||||
services.add_transient(CustomScriptService)
|
||||
services.add_transient(GenerateService)
|
||||
services.add_transient(HelpService)
|
||||
services.add_transient(InstallService)
|
||||
services.add_transient(NewService)
|
||||
services.add_transient(PublishService)
|
||||
services.add_transient(RemoveService)
|
||||
services.add_transient(RunService)
|
||||
services.add_transient(StartService)
|
||||
services.add_transient(UninstallService)
|
||||
services.add_transient(UpdateService)
|
||||
services.add_transient(VersionService)
|
||||
|
||||
return services.build_service_provider()
|
||||
|
@@ -1,28 +1,23 @@
|
||||
import os
|
||||
from typing import Optional
|
||||
|
||||
from cpl_cli.command.add_service import AddService
|
||||
from cpl_cli.command.build_service import BuildService
|
||||
from cpl_cli.command.custom_script_service import CustomScriptService
|
||||
from cpl_cli.command.generate_service import GenerateService
|
||||
from cpl_cli.command.help_service import HelpService
|
||||
from cpl_cli.command.install_service import InstallService
|
||||
from cpl_cli.command.new_service import NewService
|
||||
from cpl_cli.command.publish_service import PublishService
|
||||
from cpl_cli.command.remove_service import RemoveService
|
||||
from cpl_cli.command.run_service import RunService
|
||||
from cpl_cli.command.start_service import StartService
|
||||
from cpl_cli.command.uninstall_service import UninstallService
|
||||
from cpl_cli.command.update_service import UpdateService
|
||||
from cpl_cli.command.version_service import VersionService
|
||||
from cpl_cli.configuration.workspace_settings import WorkspaceSettings
|
||||
from cpl_cli.validators.project_validator import ProjectValidator
|
||||
from cpl_cli.validators.workspace_validator import WorkspaceValidator
|
||||
from cpl_core.application import StartupExtensionABC
|
||||
from cpl_core.application.startup_extension_abc import StartupExtensionABC
|
||||
from cpl_core.configuration.argument_type_enum import ArgumentTypeEnum
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.dependency_injection.service_collection_abc import ServiceCollectionABC
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
from cpl_core.utils import String
|
||||
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
|
||||
|
||||
|
||||
class StartupArgumentExtension(StartupExtensionABC):
|
||||
@@ -30,82 +25,49 @@ class StartupArgumentExtension(StartupExtensionABC):
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def _search_project_json(env: ApplicationEnvironmentABC) -> Optional[str]:
|
||||
project_name = None
|
||||
name = os.path.basename(env.working_directory)
|
||||
for r, d, f in os.walk(env.working_directory):
|
||||
for file in f:
|
||||
if file.endswith('.json'):
|
||||
f_name = file.split('.json')[0]
|
||||
if f_name == name or String.convert_to_camel_case(f_name).lower() == String.convert_to_camel_case(name).lower():
|
||||
project_name = f_name
|
||||
break
|
||||
|
||||
return project_name
|
||||
|
||||
def _read_cpl_environment(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||
workspace: Optional[WorkspaceSettings] = config.get_configuration(WorkspaceSettings)
|
||||
if workspace is not None:
|
||||
for script in workspace.scripts:
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', script, [], CustomScriptService)
|
||||
|
||||
project = workspace.projects[workspace.default_project]
|
||||
else:
|
||||
project = f'{self._search_project_json(env)}.json'
|
||||
|
||||
config.add_json_file(project, optional=True, output=False)
|
||||
|
||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||
config.add_json_file('cpl-workspace.json', path=env.working_directory, optional=True, output=False)
|
||||
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'add', ['a', 'A'], AddService, True) \
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'add', ['a', 'A'], AddService, True, validators=[WorkspaceValidator]) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S'])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'build', ['b', 'B'], BuildService, True, validators=[ProjectValidator])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'generate', ['g', 'G'], GenerateService, True) \
|
||||
.add_console_argument(ArgumentTypeEnum.Variable, '', 'abc', ['a', 'A'], ' ') \
|
||||
.add_console_argument(ArgumentTypeEnum.Variable, '', 'class', ['c', 'C'], ' ') \
|
||||
.add_console_argument(ArgumentTypeEnum.Variable, '', 'enum', ['e', 'E'], ' ') \
|
||||
.add_console_argument(ArgumentTypeEnum.Variable, '', 'pipe', ['p', 'P'], ' ') \
|
||||
.add_console_argument(ArgumentTypeEnum.Variable, '', 'service', ['s', 'S'], ' ') \
|
||||
.add_console_argument(ArgumentTypeEnum.Variable, '', 'settings', ['st', 'ST'], ' ') \
|
||||
.add_console_argument(ArgumentTypeEnum.Variable, '', 'test_case', ['tc', 'TC'], ' ') \
|
||||
.add_console_argument(ArgumentTypeEnum.Variable, '', 'thread', ['t', 'T'], ' ') \
|
||||
.add_console_argument(ArgumentTypeEnum.Variable, '', 'validator', ['v', 'V'], ' ')
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'install', ['i', 'I'], InstallService, True) \
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'install', ['i', 'I'], InstallService, True, validators=[ProjectValidator]) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'dev', ['d', 'D']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'virtual', ['v', 'V']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S'])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'new', ['n', 'N'], NewService, True) \
|
||||
.add_console_argument(ArgumentTypeEnum.Variable, '', 'console', ['c', 'C'], ' ') \
|
||||
.add_console_argument(ArgumentTypeEnum.Variable, '', 'library', ['l', 'L'], ' ')
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'publish', ['p', 'P'], PublishService, True)
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'remove', ['r', 'R'], RemoveService, True) \
|
||||
.add_console_argument(ArgumentTypeEnum.Variable, '', 'library', ['l', 'L'], ' ') \
|
||||
.add_console_argument(ArgumentTypeEnum.Variable, '', 'unittest', ['ut', 'UT'], ' ') \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'async', ['a', 'A']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'application-base', ['ab', 'AB']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'startup', ['s', 'S']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'service-providing', ['sp', 'SP']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'nothing', ['n', 'N']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'venv', ['v', 'V'])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'publish', ['p', 'P'], PublishService, True, validators=[ProjectValidator])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'remove', ['r', 'R'], RemoveService, True, validators=[WorkspaceValidator]) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S'])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'start', ['s', 'S'], StartService, True)
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'uninstall', ['ui', 'UI'], UninstallService, True) \
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'run', [], RunService, True, validators=[ProjectValidator])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'start', ['s', 'S'], StartService, True, validators=[ProjectValidator])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'uninstall', ['ui', 'UI'], UninstallService, True, validators=[ProjectValidator]) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'dev', ['d', 'D']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'virtual', ['v', 'V']) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S'])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'update', ['u', 'U'], UpdateService, True) \
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'update', ['u', 'U'], UpdateService, True, validators=[ProjectValidator]) \
|
||||
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S'])
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'version', ['v', 'V'], VersionService, True)
|
||||
|
||||
config.for_each_argument(lambda a: a.add_console_argument(ArgumentTypeEnum.Flag, '--', 'help', ['h', 'H']))
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'help', ['h', 'H'], HelpService)
|
||||
|
||||
self._read_cpl_environment(config, env)
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
||||
services.add_transient(WorkspaceValidator)
|
||||
services.add_transient(ProjectValidator)
|
||||
|
||||
services.add_transient(AddService)
|
||||
services.add_transient(BuildService)
|
||||
services.add_transient(CustomScriptService)
|
||||
services.add_transient(GenerateService)
|
||||
services.add_transient(HelpService)
|
||||
services.add_transient(InstallService)
|
||||
services.add_transient(NewService)
|
||||
services.add_transient(PublishService)
|
||||
services.add_transient(RemoveService)
|
||||
services.add_transient(StartService)
|
||||
services.add_transient(UninstallService)
|
||||
services.add_transient(UpdateService)
|
||||
services.add_transient(VersionService)
|
||||
pass
|
||||
|
55
src/cpl_cli/startup_workspace_extension.py
Normal file
55
src/cpl_cli/startup_workspace_extension.py
Normal file
@@ -0,0 +1,55 @@
|
||||
import os
|
||||
from typing import Optional
|
||||
|
||||
from cpl_cli.command.custom_script_service import CustomScriptService
|
||||
from cpl_cli.configuration.workspace_settings import WorkspaceSettings
|
||||
from cpl_core.application.startup_extension_abc import StartupExtensionABC
|
||||
from cpl_core.configuration.argument_type_enum import ArgumentTypeEnum
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.dependency_injection.service_collection_abc import ServiceCollectionABC
|
||||
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
|
||||
from cpl_core.utils.string import String
|
||||
|
||||
|
||||
class StartupWorkspaceExtension(StartupExtensionABC):
|
||||
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
def _search_project_json(working_directory: str) -> Optional[str]:
|
||||
project_name = None
|
||||
name = os.path.basename(working_directory)
|
||||
for r, d, f in os.walk(working_directory):
|
||||
for file in f:
|
||||
if file.endswith('.json'):
|
||||
f_name = file.split('.json')[0]
|
||||
if f_name == name or String.convert_to_camel_case(f_name).lower() == String.convert_to_camel_case(name).lower():
|
||||
project_name = f_name
|
||||
break
|
||||
|
||||
return project_name
|
||||
|
||||
def _read_cpl_environment(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||
workspace: Optional[WorkspaceSettings] = config.get_configuration(WorkspaceSettings)
|
||||
config.add_configuration('PATH_WORKSPACE', env.working_directory)
|
||||
if workspace is not None:
|
||||
for script in workspace.scripts:
|
||||
config.create_console_argument(ArgumentTypeEnum.Executable, '', script, [], CustomScriptService)
|
||||
return
|
||||
|
||||
project = self._search_project_json(env.working_directory)
|
||||
if project is not None:
|
||||
project = f'{project}.json'
|
||||
|
||||
if project is None:
|
||||
return
|
||||
|
||||
config.add_json_file(project, optional=True, output=False)
|
||||
|
||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||
config.add_json_file('cpl-workspace.json', path=env.working_directory, optional=True, output=False)
|
||||
self._read_cpl_environment(config, env)
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
||||
pass
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_cli.validators'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -1,17 +1,29 @@
|
||||
import os
|
||||
|
||||
from cpl_cli import Error
|
||||
from cpl_cli.configuration import WorkspaceSettings, ProjectSettings
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.configuration.validator_abc import ValidatorABC
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
|
||||
|
||||
class ProjectValidator(ValidatorABC):
|
||||
|
||||
def __init__(self, workspace: WorkspaceSettings, project: ProjectSettings):
|
||||
self._workspace = workspace
|
||||
self._project = project
|
||||
def __init__(self, config: ConfigurationABC, env: ApplicationEnvironmentABC, workspace: WorkspaceSettings, project: ProjectSettings):
|
||||
self._config: ConfigurationABC = config
|
||||
self._env: ApplicationEnvironmentABC = env
|
||||
self._workspace: WorkspaceSettings = workspace
|
||||
self._project: ProjectSettings = project
|
||||
|
||||
ValidatorABC.__init__(self)
|
||||
|
||||
def validate(self) -> bool:
|
||||
if self._project is None and self._workspace is not None:
|
||||
project = self._workspace.projects[self._workspace.default_project]
|
||||
self._config.add_json_file(project, optional=True, output=False)
|
||||
self._project = self._config.get_configuration(ProjectSettings)
|
||||
self._env.set_working_directory(os.path.join(self._env.working_directory, os.path.dirname(project)))
|
||||
|
||||
result = self._project is not None or self._workspace is not None
|
||||
if not result:
|
||||
Error.error('The command requires to be run in an CPL project, but a project could not be found.')
|
||||
|
@@ -15,11 +15,11 @@ __title__ = 'cpl_core'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.application'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -28,4 +28,4 @@ from .startup_abc import StartupABC
|
||||
from .startup_extension_abc import StartupExtensionABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -4,7 +4,7 @@ from typing import Optional
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.dependency_injection.service_provider_abc import ServiceProviderABC
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
|
||||
|
||||
|
||||
class ApplicationABC(ABC):
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.configuration'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -34,4 +34,4 @@ from .validator_abc import ValidatorABC
|
||||
from .variable_argument import VariableArgument
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -5,9 +5,9 @@ import traceback
|
||||
from collections.abc import Callable
|
||||
from typing import Union, Type, Optional
|
||||
|
||||
from cpl_cli.command_abc import CommandABC
|
||||
from cpl_core.configuration.argument_abc import ArgumentABC
|
||||
from cpl_core.configuration.argument_builder import ArgumentBuilder
|
||||
from cpl_core.configuration.argument_executable_abc import ArgumentExecutableABC
|
||||
from cpl_core.configuration.argument_type_enum import ArgumentTypeEnum
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
@@ -154,6 +154,31 @@ class Configuration(ConfigurationABC):
|
||||
self._print_error(__name__, f'Cannot load config file: {file}! -> {e}')
|
||||
return {}
|
||||
|
||||
def _handle_pre_or_post_executables(self, pre: bool, argument: ExecutableArgument, services: ServiceProviderABC):
|
||||
script_type = 'pre-' if pre else 'post-'
|
||||
|
||||
from cpl_cli.configuration.workspace_settings import WorkspaceSettings
|
||||
workspace: Optional[WorkspaceSettings] = self.get_configuration(WorkspaceSettings)
|
||||
if workspace is None or len(workspace.scripts) == 0:
|
||||
return
|
||||
|
||||
for script in workspace.scripts:
|
||||
if script_type not in script and not script.startswith(script_type):
|
||||
continue
|
||||
|
||||
# split in two ifs to prevent exception
|
||||
if script.split(script_type)[1] != argument.name:
|
||||
continue
|
||||
|
||||
from cpl_cli.command.custom_script_service import CustomScriptService
|
||||
css: CustomScriptService = services.get_service(CustomScriptService)
|
||||
if css is None:
|
||||
continue
|
||||
|
||||
Console.write_line()
|
||||
self._set_variable('ACTIVE_EXECUTABLE', script)
|
||||
css.run([])
|
||||
|
||||
def _parse_arguments(self, executables: list[ArgumentABC], arg_list: list[str], args_types: list[ArgumentABC]):
|
||||
for i in range(0, len(arg_list)):
|
||||
arg_str = arg_list[i]
|
||||
@@ -165,8 +190,7 @@ class Configuration(ConfigurationABC):
|
||||
|
||||
# executable
|
||||
if isinstance(arg, ExecutableArgument):
|
||||
if arg_str.startswith(arg.token) \
|
||||
and arg_str_without_token == arg.name or arg_str_without_token in arg.aliases:
|
||||
if arg_str.startswith(arg.token) and arg_str_without_token == arg.name or arg_str_without_token in arg.aliases:
|
||||
executables.append(arg)
|
||||
self._handled_args.append(arg_str)
|
||||
self._parse_arguments(executables, arg_list[i + 1:], arg.console_arguments)
|
||||
@@ -177,8 +201,7 @@ class Configuration(ConfigurationABC):
|
||||
if arg.value_token in arg_str_without_value:
|
||||
arg_str_without_value = arg_str_without_token.split(arg.value_token)[0]
|
||||
|
||||
if arg_str.startswith(arg.token) \
|
||||
and arg_str_without_value == arg.name or arg_str_without_value in arg.aliases:
|
||||
if arg_str.startswith(arg.token) and arg_str_without_value == arg.name or arg_str_without_value in arg.aliases:
|
||||
if arg.value_token != ' ':
|
||||
value = arg_str_without_token.split(arg.value_token)[1]
|
||||
else:
|
||||
@@ -190,8 +213,9 @@ class Configuration(ConfigurationABC):
|
||||
|
||||
# flags
|
||||
elif isinstance(arg, FlagArgument):
|
||||
if arg_str.startswith(arg.token) \
|
||||
and arg_str_without_token == arg.name or arg_str_without_token in arg.aliases:
|
||||
if arg_str.startswith(arg.token) and arg_str_without_token == arg.name or arg_str_without_token in arg.aliases:
|
||||
if arg_str in self._additional_arguments:
|
||||
self._additional_arguments.remove(arg_str)
|
||||
self._additional_arguments.append(arg.name)
|
||||
self._handled_args.append(arg_str)
|
||||
self._parse_arguments(executables, arg_list[i + 1:], arg.console_arguments)
|
||||
@@ -201,10 +225,11 @@ class Configuration(ConfigurationABC):
|
||||
self._additional_arguments.append(arg_str)
|
||||
|
||||
def add_environment_variables(self, prefix: str):
|
||||
for variable in ConfigurationVariableNameEnum.to_list():
|
||||
var_name = f'{prefix}{variable}'
|
||||
if var_name in [key.upper() for key in os.environ.keys()]:
|
||||
self._set_variable(variable, os.environ[var_name])
|
||||
for env_var in os.environ.keys():
|
||||
if not env_var.startswith(prefix):
|
||||
continue
|
||||
|
||||
self._set_variable(env_var.replace(prefix, ''), os.environ[env_var])
|
||||
|
||||
def add_console_argument(self, argument: ArgumentABC):
|
||||
self._argument_types.append(argument)
|
||||
@@ -304,15 +329,17 @@ class Configuration(ConfigurationABC):
|
||||
break
|
||||
|
||||
if abort:
|
||||
continue
|
||||
sys.exit()
|
||||
|
||||
cmd: CommandABC = services.get_service(exe.executable_type)
|
||||
self.add_configuration('ACTIVE_EXECUTABLE', exe.name)
|
||||
cmd: ArgumentExecutableABC = services.get_service(exe.executable_type)
|
||||
self._handle_pre_or_post_executables(True, exe, services)
|
||||
self._set_variable('ACTIVE_EXECUTABLE', exe.name)
|
||||
cmd.execute(self._additional_arguments)
|
||||
self._handle_pre_or_post_executables(False, exe, services)
|
||||
prevent = exe.prevent_next_executable
|
||||
success = True
|
||||
except Exception as e:
|
||||
Console.error('An error occurred while executing arguments.')
|
||||
Console.error('An error occurred while executing arguments.', traceback.format_exc())
|
||||
sys.exit()
|
||||
|
||||
return success
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.console'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -27,4 +27,4 @@ from .foreground_color_enum import ForegroundColorEnum
|
||||
from .spinner_thread import SpinnerThread
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -456,17 +456,21 @@ class Console:
|
||||
|
||||
cls.write_line(message)
|
||||
cls.set_hold_back(True)
|
||||
spinner = SpinnerThread(len(message), spinner_foreground_color, spinner_background_color)
|
||||
spinner.start()
|
||||
spinner = None
|
||||
if not cls._disabled:
|
||||
spinner = SpinnerThread(len(message), spinner_foreground_color, spinner_background_color)
|
||||
spinner.start()
|
||||
|
||||
return_value = None
|
||||
try:
|
||||
return_value = call(*args, **kwargs)
|
||||
except KeyboardInterrupt:
|
||||
spinner.exit()
|
||||
if spinner is not None:
|
||||
spinner.exit()
|
||||
cls.close()
|
||||
|
||||
spinner.stop_spinning()
|
||||
if spinner is not None:
|
||||
spinner.stop_spinning()
|
||||
cls.set_hold_back(False)
|
||||
|
||||
cls.set_foreground_color(ForegroundColorEnum.default)
|
||||
|
@@ -4,7 +4,7 @@
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "6",
|
||||
"Micro": "3"
|
||||
"Micro": "0.rc1"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
@@ -28,6 +28,7 @@
|
||||
"watchdog==2.1.7",
|
||||
"wheel==0.37.1"
|
||||
],
|
||||
"DevDependencies": [],
|
||||
"PythonVersion": ">=3.10",
|
||||
"PythonPath": {},
|
||||
"Classifiers": []
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.database'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -25,4 +25,4 @@ from .database_settings import DatabaseSettings
|
||||
from .table_abc import TableABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.database.connection'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -24,4 +24,4 @@ from .database_connection import DatabaseConnection
|
||||
from .database_connection_abc import DatabaseConnectionABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.database.context'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -24,4 +24,4 @@ from .database_context import DatabaseContext
|
||||
from .database_context_abc import DatabaseContextABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.dependency_injection'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -30,4 +30,4 @@ from .service_provider import ServiceProvider
|
||||
from .service_provider_abc import ServiceProviderABC
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -1,15 +1,17 @@
|
||||
from typing import Union, Type, Callable, Optional
|
||||
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.database.database_settings import DatabaseSettings
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.database.context.database_context_abc import DatabaseContextABC
|
||||
from cpl_core.dependency_injection.service_provider_abc import ServiceProviderABC
|
||||
from cpl_core.database.database_settings import DatabaseSettings
|
||||
from cpl_core.dependency_injection.service_collection_abc import ServiceCollectionABC
|
||||
from cpl_core.dependency_injection.service_descriptor import ServiceDescriptor
|
||||
from cpl_core.dependency_injection.service_lifetime_enum import ServiceLifetimeEnum
|
||||
from cpl_core.dependency_injection.service_provider import ServiceProvider
|
||||
from cpl_core.logging.logger_service import Logger
|
||||
from cpl_core.dependency_injection.service_provider_abc import ServiceProviderABC
|
||||
from cpl_core.logging.logger_abc import LoggerABC
|
||||
from cpl_core.logging.logger_service import Logger
|
||||
from cpl_core.pipes.pipe_abc import PipeABC
|
||||
|
||||
|
||||
class ServiceCollection(ServiceCollectionABC):
|
||||
@@ -22,7 +24,7 @@ class ServiceCollection(ServiceCollectionABC):
|
||||
self._database_context: Optional[DatabaseContextABC] = None
|
||||
self._service_descriptors: list[ServiceDescriptor] = []
|
||||
|
||||
def _add_descriptor(self, service: Union[type, object], lifetime: ServiceLifetimeEnum):
|
||||
def _add_descriptor(self, service: Union[type, object], lifetime: ServiceLifetimeEnum, base_type: Callable = None):
|
||||
found = False
|
||||
for descriptor in self._service_descriptors:
|
||||
if isinstance(service, descriptor.service_type):
|
||||
@@ -35,7 +37,15 @@ class ServiceCollection(ServiceCollectionABC):
|
||||
|
||||
raise Exception(f'Service of type {service_type} already exists')
|
||||
|
||||
self._service_descriptors.append(ServiceDescriptor(service, lifetime))
|
||||
self._service_descriptors.append(ServiceDescriptor(service, lifetime, base_type))
|
||||
|
||||
def _add_descriptor_by_lifetime(self, service_type: Type, lifetime: ServiceLifetimeEnum, service: Callable = None):
|
||||
if service is not None:
|
||||
self._add_descriptor(service, lifetime, service_type)
|
||||
else:
|
||||
self._add_descriptor(service_type, lifetime)
|
||||
|
||||
return self
|
||||
|
||||
def add_db_context(self, db_context_type: Type[DatabaseContextABC], db_settings: DatabaseSettings):
|
||||
self.add_singleton(DatabaseContextABC, db_context_type)
|
||||
@@ -45,35 +55,20 @@ class ServiceCollection(ServiceCollectionABC):
|
||||
def add_logging(self):
|
||||
self.add_singleton(LoggerABC, Logger)
|
||||
|
||||
def add_pipes(self):
|
||||
for pipe in PipeABC.__subclasses__():
|
||||
self.add_transient(PipeABC, pipe)
|
||||
|
||||
def add_singleton(self, service_type: Union[type, object], service: Union[type, object] = None):
|
||||
impl = None
|
||||
if service is not None:
|
||||
if isinstance(service, type):
|
||||
impl = self.build_service_provider().build_service(service)
|
||||
|
||||
self._add_descriptor(impl, ServiceLifetimeEnum.singleton)
|
||||
else:
|
||||
if isinstance(service_type, type):
|
||||
impl = self.build_service_provider().build_service(service_type)
|
||||
|
||||
self._add_descriptor(impl, ServiceLifetimeEnum.singleton)
|
||||
|
||||
self._add_descriptor_by_lifetime(service_type, ServiceLifetimeEnum.singleton, service)
|
||||
return self
|
||||
|
||||
def add_scoped(self, service_type: Type, service: Callable = None):
|
||||
if service is not None:
|
||||
self._add_descriptor(service, ServiceLifetimeEnum.scoped)
|
||||
else:
|
||||
self._add_descriptor(service_type, ServiceLifetimeEnum.scoped)
|
||||
|
||||
self._add_descriptor_by_lifetime(service_type, ServiceLifetimeEnum.scoped, service)
|
||||
return self
|
||||
|
||||
def add_transient(self, service_type: type, service: type = None):
|
||||
if service is not None:
|
||||
self._add_descriptor(service, ServiceLifetimeEnum.transient)
|
||||
else:
|
||||
self._add_descriptor(service_type, ServiceLifetimeEnum.transient)
|
||||
|
||||
self._add_descriptor_by_lifetime(service_type, ServiceLifetimeEnum.transient, service)
|
||||
return self
|
||||
|
||||
def build_service_provider(self) -> ServiceProviderABC:
|
||||
|
@@ -30,6 +30,11 @@ class ServiceCollectionABC(ABC):
|
||||
r"""Adds the CPL internal logger"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_pipes(self):
|
||||
r"""Adds the CPL internal pipes as transient"""
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def add_transient(self, service_type: Type, service: Callable = None) -> 'ServiceCollectionABC':
|
||||
r"""Adds a service with transient lifetime
|
||||
|
@@ -1,5 +1,6 @@
|
||||
from typing import Union, Optional
|
||||
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.dependency_injection.service_lifetime_enum import ServiceLifetimeEnum
|
||||
|
||||
|
||||
@@ -14,7 +15,7 @@ class ServiceDescriptor:
|
||||
Lifetime of the service
|
||||
"""
|
||||
|
||||
def __init__(self, implementation: Union[type, Optional[object]], lifetime: ServiceLifetimeEnum):
|
||||
def __init__(self, implementation: Union[type, Optional[object]], lifetime: ServiceLifetimeEnum, base_type=None):
|
||||
|
||||
self._service_type = implementation
|
||||
self._implementation = implementation
|
||||
@@ -25,10 +26,16 @@ class ServiceDescriptor:
|
||||
else:
|
||||
self._implementation = None
|
||||
|
||||
self._base_type = base_type if base_type is not None else self._service_type
|
||||
|
||||
@property
|
||||
def service_type(self) -> type:
|
||||
return self._service_type
|
||||
|
||||
@property
|
||||
def base_type(self) -> type:
|
||||
return self._base_type
|
||||
|
||||
@property
|
||||
def implementation(self) -> Union[type, Optional[object]]:
|
||||
return self._implementation
|
||||
|
@@ -4,6 +4,7 @@ from typing import Optional
|
||||
|
||||
from cpl_core.configuration.configuration_abc import ConfigurationABC
|
||||
from cpl_core.configuration.configuration_model_abc import ConfigurationModelABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.database.context.database_context_abc import DatabaseContextABC
|
||||
from cpl_core.dependency_injection.scope_abc import ScopeABC
|
||||
from cpl_core.dependency_injection.scope_builder import ScopeBuilder
|
||||
@@ -36,7 +37,7 @@ class ServiceProvider(ServiceProviderABC):
|
||||
|
||||
def _find_service(self, service_type: type) -> Optional[ServiceDescriptor]:
|
||||
for descriptor in self._service_descriptors:
|
||||
if descriptor.service_type == service_type or issubclass(descriptor.service_type, service_type):
|
||||
if descriptor.service_type == service_type or issubclass(descriptor.base_type, service_type):
|
||||
return descriptor
|
||||
|
||||
return None
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.environment'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -25,4 +25,4 @@ from .environment_name_enum import EnvironmentNameEnum
|
||||
from .application_environment import ApplicationEnvironment
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.logging'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -27,4 +27,4 @@ from .logging_settings import LoggingSettings
|
||||
from .logging_settings_name_enum import LoggingSettingsNameEnum
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.mailing'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -27,4 +27,4 @@ from .email_client_settings import EMailClientSettings
|
||||
from .email_client_settings_name_enum import EMailClientSettingsNameEnum
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
32
src/cpl_core/pipes/__init__.py
Normal file
32
src/cpl_core/pipes/__init__.py
Normal file
@@ -0,0 +1,32 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-core sh-edraft Common Python library
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library
|
||||
|
||||
:copyright: (c) 2020 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_core.pipes'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
from .bool_pipe import BoolPipe
|
||||
from .first_char_to_lower_pipe import FirstCharToLowerPipe
|
||||
from .first_to_upper_pipe import FirstToUpperPipe
|
||||
from .ip_address_pipe import IPAddressPipe
|
||||
from .pipe_abc import PipeABC
|
||||
from .to_camel_case_pipe import ToCamelCasePipe
|
||||
from .to_snake_case_pipe import ToSnakeCasePipe
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
9
src/cpl_core/pipes/bool_pipe.py
Normal file
9
src/cpl_core/pipes/bool_pipe.py
Normal file
@@ -0,0 +1,9 @@
|
||||
from cpl_core.pipes.pipe_abc import PipeABC
|
||||
|
||||
|
||||
class BoolPipe(PipeABC):
|
||||
|
||||
def __init__(self): pass
|
||||
|
||||
def transform(self, value: bool, *args):
|
||||
return 'True' if value else 'False'
|
20
src/cpl_core/pipes/first_char_to_lower_pipe.py
Normal file
20
src/cpl_core/pipes/first_char_to_lower_pipe.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from cpl_core.pipes.pipe_abc import PipeABC
|
||||
|
||||
|
||||
class FirstCharToLowerPipe(PipeABC):
|
||||
|
||||
def __init__(self): pass
|
||||
|
||||
def transform(self, value: any, *args):
|
||||
r"""Converts first char to lower
|
||||
|
||||
Parameter
|
||||
---------
|
||||
value: :class:`str`
|
||||
String to convert
|
||||
|
||||
Returns
|
||||
-------
|
||||
String with first char as lower
|
||||
"""
|
||||
return f'{value[0].lower()}{value[1:]}'
|
20
src/cpl_core/pipes/first_to_upper_pipe.py
Normal file
20
src/cpl_core/pipes/first_to_upper_pipe.py
Normal file
@@ -0,0 +1,20 @@
|
||||
from cpl_core.pipes.pipe_abc import PipeABC
|
||||
|
||||
|
||||
class FirstToUpperPipe(PipeABC):
|
||||
|
||||
def __init__(self): pass
|
||||
|
||||
def transform(self, value: str, *args):
|
||||
r"""Converts first char to upper
|
||||
|
||||
Parameter
|
||||
---------
|
||||
chars: :class:`str`
|
||||
String to convert
|
||||
|
||||
Returns
|
||||
-------
|
||||
String with first char as upper
|
||||
"""
|
||||
return f'{value[0].upper()}{value[1:]}'
|
24
src/cpl_core/pipes/ip_address_pipe.py
Normal file
24
src/cpl_core/pipes/ip_address_pipe.py
Normal file
@@ -0,0 +1,24 @@
|
||||
from cpl_core.pipes.pipe_abc import PipeABC
|
||||
|
||||
|
||||
class IPAddressPipe(PipeABC):
|
||||
|
||||
def __init__(self): pass
|
||||
|
||||
def transform(self, value: list[int], *args):
|
||||
string = ""
|
||||
|
||||
if len(value) != 4:
|
||||
raise Exception('Invalid IP')
|
||||
|
||||
for i in range(0, len(value)):
|
||||
byte = value[i]
|
||||
if byte > 255:
|
||||
raise Exception('Invalid IP')
|
||||
|
||||
if i == len(value) - 1:
|
||||
string += f'{byte}'
|
||||
else:
|
||||
string += f'{byte}.'
|
||||
|
||||
return string
|
10
src/cpl_core/pipes/pipe_abc.py
Normal file
10
src/cpl_core/pipes/pipe_abc.py
Normal file
@@ -0,0 +1,10 @@
|
||||
from abc import ABC, abstractmethod
|
||||
|
||||
|
||||
class PipeABC(ABC):
|
||||
|
||||
@abstractmethod
|
||||
def __init__(self): pass
|
||||
|
||||
@abstractmethod
|
||||
def transform(self, value: any, *args): pass
|
28
src/cpl_core/pipes/to_camel_case_pipe.py
Normal file
28
src/cpl_core/pipes/to_camel_case_pipe.py
Normal file
@@ -0,0 +1,28 @@
|
||||
import string
|
||||
|
||||
from cpl_core.pipes import PipeABC
|
||||
|
||||
|
||||
class ToCamelCasePipe(PipeABC):
|
||||
|
||||
def __init__(self): pass
|
||||
|
||||
def transform(self, value: str, *args) -> str:
|
||||
r"""Converts string to camel case
|
||||
|
||||
Parameter
|
||||
---------
|
||||
chars: :class:`str`
|
||||
String to convert
|
||||
|
||||
Returns
|
||||
-------
|
||||
String converted to CamelCase
|
||||
"""
|
||||
converted_name = value
|
||||
char_set = string.punctuation + ' '
|
||||
for char in char_set:
|
||||
if char in converted_name:
|
||||
converted_name = ''.join(word.title() for word in converted_name.split(char))
|
||||
|
||||
return converted_name
|
29
src/cpl_core/pipes/to_snake_case_pipe.py
Normal file
29
src/cpl_core/pipes/to_snake_case_pipe.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import re
|
||||
|
||||
from cpl_core.pipes import PipeABC
|
||||
|
||||
|
||||
class ToSnakeCasePipe(PipeABC):
|
||||
|
||||
def __init__(self): pass
|
||||
|
||||
def transform(self, value: str, *args) -> str:
|
||||
r"""Converts string to snake case
|
||||
|
||||
Parameter
|
||||
---------
|
||||
chars: :class:`str`
|
||||
String to convert
|
||||
|
||||
Returns
|
||||
-------
|
||||
String converted to snake_case
|
||||
"""
|
||||
# convert to train-case to CamelCase
|
||||
if '-' in value:
|
||||
value = ''.join(word.title() for word in value.split('-'))
|
||||
|
||||
pattern1 = re.compile(r'(.)([A-Z][a-z]+)')
|
||||
pattern2 = re.compile(r'([a-z0-9])([A-Z])')
|
||||
file_name = re.sub(pattern1, r'\1_\2', value)
|
||||
return re.sub(pattern2, r'\1_\2', file_name).lower()
|
14
src/cpl_core/pipes/version_pipe.py
Normal file
14
src/cpl_core/pipes/version_pipe.py
Normal file
@@ -0,0 +1,14 @@
|
||||
from cpl_cli.configuration import VersionSettingsNameEnum
|
||||
from cpl_core.pipes.pipe_abc import PipeABC
|
||||
|
||||
|
||||
class VersionPipe(PipeABC):
|
||||
|
||||
def __init__(self): pass
|
||||
|
||||
def transform(self, value: dict, *args):
|
||||
for atr in VersionSettingsNameEnum:
|
||||
if atr.value not in value:
|
||||
raise KeyError(atr.value)
|
||||
|
||||
return f'{value[VersionSettingsNameEnum.major.value]}.{value[VersionSettingsNameEnum.minor.value]}.{value[VersionSettingsNameEnum.micro.value]}'
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.time'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -24,4 +24,4 @@ from .time_format_settings import TimeFormatSettings
|
||||
from .time_format_settings_names_enum import TimeFormatSettingsNamesEnum
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -15,7 +15,7 @@ __title__ = 'cpl_core.utils'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.3'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -25,4 +25,4 @@ from .string import String
|
||||
from .pip import Pip
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='3')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -4,19 +4,22 @@ import sys
|
||||
from contextlib import suppress
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.console import Console
|
||||
|
||||
|
||||
class Pip:
|
||||
r"""Executes pip commands"""
|
||||
_executable = sys.executable
|
||||
_env = os.environ
|
||||
_is_venv = False
|
||||
|
||||
"""Getter"""
|
||||
|
||||
@classmethod
|
||||
def get_executable(cls) -> str:
|
||||
return cls._executable
|
||||
|
||||
"""Setter"""
|
||||
|
||||
@classmethod
|
||||
def set_executable(cls, executable: str):
|
||||
r"""Sets the executable
|
||||
@@ -26,25 +29,28 @@ class Pip:
|
||||
executable: :class:`str`
|
||||
The python command
|
||||
"""
|
||||
if executable is not None and executable != sys.executable:
|
||||
cls._executable = executable
|
||||
if os.path.islink(cls._executable):
|
||||
cls._is_venv = True
|
||||
path = os.path.dirname(os.path.dirname(cls._executable))
|
||||
cls._env = os.environ
|
||||
if sys.platform == 'win32':
|
||||
cls._env['PATH'] = f'{path}\\bin' + os.pathsep + os.environ.get('PATH', '')
|
||||
else:
|
||||
cls._env['PATH'] = f'{path}/bin' + os.pathsep + os.environ.get('PATH', '')
|
||||
cls._env['VIRTUAL_ENV'] = path
|
||||
if executable is None or executable == sys.executable:
|
||||
return
|
||||
|
||||
cls._executable = executable
|
||||
if not os.path.islink(cls._executable):
|
||||
return
|
||||
|
||||
path = os.path.dirname(os.path.dirname(cls._executable))
|
||||
cls._env = os.environ
|
||||
if sys.platform == 'win32':
|
||||
cls._env['PATH'] = f'{path}\\bin' + os.pathsep + os.environ.get('PATH', '')
|
||||
else:
|
||||
cls._env['PATH'] = f'{path}/bin' + os.pathsep + os.environ.get('PATH', '')
|
||||
cls._env['VIRTUAL_ENV'] = path
|
||||
|
||||
@classmethod
|
||||
def reset_executable(cls):
|
||||
r"""Resets the executable to system standard"""
|
||||
cls._executable = sys.executable
|
||||
cls._is_venv = False
|
||||
|
||||
"""Public utils functions"""
|
||||
|
||||
@classmethod
|
||||
def get_package(cls, package: str) -> Optional[str]:
|
||||
r"""Gets given package py local pip list
|
||||
@@ -60,8 +66,6 @@ class Pip:
|
||||
result = None
|
||||
with suppress(Exception):
|
||||
args = [cls._executable, "-m", "pip", "show", package]
|
||||
if cls._is_venv:
|
||||
args = ["pip", "show", package]
|
||||
|
||||
result = subprocess.check_output(
|
||||
args,
|
||||
@@ -92,8 +96,6 @@ class Pip:
|
||||
Bytes string of the command result
|
||||
"""
|
||||
args = [cls._executable, "-m", "pip", "list", "--outdated"]
|
||||
if cls._is_venv:
|
||||
args = ["pip", "list", "--outdated"]
|
||||
|
||||
return subprocess.check_output(args, env=cls._env)
|
||||
|
||||
@@ -115,8 +117,6 @@ class Pip:
|
||||
Stderr of subprocess.run
|
||||
"""
|
||||
pip_args = [cls._executable, "-m", "pip", "install"]
|
||||
if cls._is_venv:
|
||||
pip_args = ["pip", "install"]
|
||||
|
||||
for arg in args:
|
||||
pip_args.append(arg)
|
||||
@@ -142,8 +142,6 @@ class Pip:
|
||||
Stderr of subprocess.run
|
||||
"""
|
||||
args = [cls._executable, "-m", "pip", "uninstall", "--yes", package]
|
||||
if cls._is_venv:
|
||||
args = ["pip", "uninstall", "--yes", package]
|
||||
|
||||
subprocess.run(
|
||||
args,
|
||||
|
@@ -6,7 +6,7 @@ cpl-query sh-edraft Common Python library Query
|
||||
|
||||
sh-edraft Common Python library Python integrated Queries
|
||||
|
||||
:copyright: (c) 2020 - 2022 sh-edraft.de
|
||||
:copyright: (c) 2021 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
@@ -14,12 +14,12 @@ sh-edraft Common Python library Python integrated Queries
|
||||
__title__ = 'cpl_query'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.1'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -6,7 +6,7 @@ cpl-query sh-edraft Common Python library Query
|
||||
|
||||
sh-edraft Common Python library Python integrated Queries
|
||||
|
||||
:copyright: (c) 2020 - 2022 sh-edraft.de
|
||||
:copyright: (c) 2021 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
@@ -14,12 +14,12 @@ sh-edraft Common Python library Python integrated Queries
|
||||
__title__ = 'cpl_query._query'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.1'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -4,20 +4,19 @@
|
||||
"Version": {
|
||||
"Major": "2022",
|
||||
"Minor": "6",
|
||||
"Micro": "1"
|
||||
"Micro": "0.rc1"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
"Description": "sh-edraft Common Python library Query",
|
||||
"LongDescription": "sh-edraft Common Python library Python integrated Queries",
|
||||
"URL": "https://www.sh-edraft.de",
|
||||
"CopyrightDate": "2020 - 2022",
|
||||
"CopyrightDate": "2021 - 2022",
|
||||
"CopyrightName": "sh-edraft.de",
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.6.1"
|
||||
],
|
||||
"Dependencies": [],
|
||||
"DevDependencies": [],
|
||||
"PythonVersion": ">=3.10",
|
||||
"PythonPath": {},
|
||||
"Classifiers": []
|
@@ -6,7 +6,7 @@ cpl-query sh-edraft Common Python library Query
|
||||
|
||||
sh-edraft Common Python library Python integrated Queries
|
||||
|
||||
:copyright: (c) 2020 - 2022 sh-edraft.de
|
||||
:copyright: (c) 2021 - 2022 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
@@ -14,8 +14,8 @@ sh-edraft Common Python library Python integrated Queries
|
||||
__title__ = 'cpl_query.extension'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.1'
|
||||
__copyright__ = 'Copyright (c) 2021 - 2022 sh-edraft.de'
|
||||
__version__ = '2022.6.0rc1'
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
@@ -27,4 +27,4 @@ from .ordered_iterable_abc import OrderedIterableABC
|
||||
from .ordered_iterable import OrderedIterable
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='1')
|
||||
version_info = VersionInfo(major='2022', minor='6', micro='0.rc1')
|
||||
|
@@ -1,25 +0,0 @@
|
||||
import unittest
|
||||
|
||||
from cpl_query.tests.iterable_test import IterableTest
|
||||
from cpl_query.tests.query_test import QueryTest
|
||||
|
||||
|
||||
class Tester:
|
||||
|
||||
def __init__(self):
|
||||
self._suite = unittest.TestSuite()
|
||||
|
||||
def create(self):
|
||||
loader = unittest.TestLoader()
|
||||
self._suite.addTests(loader.loadTestsFromTestCase(QueryTest))
|
||||
self._suite.addTests(loader.loadTestsFromTestCase(IterableTest))
|
||||
|
||||
def start(self):
|
||||
runner = unittest.TextTestRunner()
|
||||
runner.run(self._suite)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
tester = Tester()
|
||||
tester.create()
|
||||
tester.start()
|
@@ -1,25 +0,0 @@
|
||||
# -*- 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__ = 'sh_cpl.tests'
|
||||
__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,12 +1,13 @@
|
||||
import time
|
||||
from typing import Optional
|
||||
|
||||
from cpl_core.application import ApplicationABC
|
||||
from cpl_core.application.application_abc import ApplicationABC
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.console.console import Console
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.dependency_injection import ServiceProviderABC
|
||||
from cpl_core.logging.logger_abc import LoggerABC
|
||||
from cpl_core.logging import LoggerABC
|
||||
from cpl_core.mailing import EMailClientABC, EMail
|
||||
from cpl_core.pipes import IPAddressPipe
|
||||
from test_service import TestService
|
||||
|
||||
|
||||
@@ -36,12 +37,20 @@ class Application(ApplicationABC):
|
||||
self._mailer = self._services.get_service(EMailClientABC)
|
||||
|
||||
def main(self):
|
||||
self._configuration.parse_console_arguments(self._services)
|
||||
|
||||
if self._configuration.environment.application_name != '':
|
||||
self._logger.header(f'{self._configuration.environment.application_name}:')
|
||||
self._logger.debug(__name__, f'Args: {self._configuration.additional_arguments}')
|
||||
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}')
|
||||
Console.spinner('Test', self._wait, 2, spinner_foreground_color='red')
|
||||
test: TestService = self._services.get_service(TestService)
|
||||
ip_pipe: IPAddressPipe = self._services.get_service(IPAddressPipe)
|
||||
test.run()
|
||||
test2: TestService = self._services.get_service(TestService)
|
||||
ip_pipe2: IPAddressPipe = self._services.get_service(IPAddressPipe)
|
||||
Console.write_line(f'DI working: {test == test2 and ip_pipe != ip_pipe2}')
|
||||
Console.write_line(self._services.get_service(LoggerABC))
|
||||
# self.test_send_mail()
|
||||
|
@@ -1,5 +1,4 @@
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.configuration.argument_executable_abc import ArgumentExecutableABC
|
||||
from cpl_core.configuration import ConfigurationABC, ArgumentExecutableABC
|
||||
from cpl_core.console import Console
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
from cpl_core.configuration.argument_executable_abc import ArgumentExecutableABC
|
||||
from cpl_core.configuration import ArgumentExecutableABC
|
||||
from cpl_core.console import Console
|
||||
|
||||
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user