diff --git a/cpl-workspace.json b/cpl-workspace.json index d07c8cae..081ff298 100644 --- a/cpl-workspace.json +++ b/cpl-workspace.json @@ -131,7 +131,15 @@ "di-cli": "pip install cpl-cli --pre --upgrade --extra-index-url https://pip-dev.sh-edraft.de", "di-discord": "pip install cpl-discord --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", - "di-translation": "pip install cpl-translation --pre --upgrade --extra-index-url https://pip-dev.sh-edraft.de" + "di-translation": "pip install cpl-translation --pre --upgrade --extra-index-url https://pip-dev.sh-edraft.de", + + "prod-install": "cpl pi-core; cpl pi-cli; cpl pi-query; cpl pi-translation;", + "pi": "cpl prod-install", + "pi-core": "pip install cpl-core --pre --upgrade --extra-index-url https://pip.sh-edraft.de", + "pi-cli": "pip install cpl-cli --pre --upgrade --extra-index-url https://pip.sh-edraft.de", + "pi-discord": "pip install cpl-discord --pre --upgrade --extra-index-url https://pip.sh-edraft.de", + "pi-query": "pip install cpl-query --pre --upgrade --extra-index-url https://pip.sh-edraft.de", + "pi-translation": "pip install cpl-translation --pre --upgrade --extra-index-url https://pip.sh-edraft.de" } } } \ No newline at end of file diff --git a/src/cpl_cli/command/generate_service.py b/src/cpl_cli/command/generate_service.py index 18b9505c..12236c83 100644 --- a/src/cpl_cli/command/generate_service.py +++ b/src/cpl_cli/command/generate_service.py @@ -14,6 +14,7 @@ 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_cli.configuration import WorkspaceSettings from cpl_core.configuration.configuration_abc import ConfigurationABC from cpl_core.console.console import Console from cpl_core.console.foreground_color_enum import ForegroundColorEnum @@ -22,13 +23,20 @@ from cpl_core.utils.string import String class GenerateService(CommandABC): - def __init__(self, configuration: ConfigurationABC): + def __init__( + self, + configuration: ConfigurationABC, + workspace: WorkspaceSettings, + ): """ Service for the CLI command generate :param configuration: """ CommandABC.__init__(self) + self._config = configuration + self._workspace = workspace + self._schematics = { "abc": { "Upper": "ABC", @@ -129,27 +137,7 @@ class GenerateService(CommandABC): template.write(value) template.close() - def _generate(self, schematic: str, name: str, template: TemplateFileABC): - """ - Generates files by given schematic, name and template - :param schematic: - :param name: - :param template: - :return: - """ - class_name = name - rel_path = '' - if '/' in name: - parts = name.split('/') - rel_path = '/'.join(parts[:-1]) - class_name = parts[len(parts) - 1] - - 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) - - file_path = os.path.join(self._env.working_directory, template.path, template.name) + def _create_init_files(self, file_path: str, template: TemplateFileABC, class_name: str, schematic: str, rel_path: str): if not os.path.isdir(os.path.dirname(file_path)): os.makedirs(os.path.dirname(file_path)) directory = '' @@ -171,6 +159,29 @@ class GenerateService(CommandABC): spinner_foreground_color=ForegroundColorEnum.cyan ) + def _generate(self, schematic: str, name: str, template: TemplateFileABC): + """ + Generates files by given schematic, name and template + :param schematic: + :param name: + :param template: + :return: + """ + class_name = name + rel_path = '' + if '/' in name: + parts = name.split('/') + rel_path = '/'.join(parts[:-1]) + class_name = parts[len(parts) - 1] + + if self._workspace is not None and parts[0] in self._workspace.projects: + rel_path = os.path.dirname(self._workspace.projects[parts[0]]) + + template = template(class_name, schematic, self._schematics[schematic]["Upper"], rel_path) + + file_path = os.path.join(self._env.working_directory, template.path, template.name) + self._create_init_files(file_path, template, class_name, schematic, rel_path) + if os.path.isfile(file_path): Console.error(f'{String.first_to_upper(schematic)} already exists!\n') sys.exit() diff --git a/src/cpl_cli/publish/publisher_service.py b/src/cpl_cli/publish/publisher_service.py index e7d59ad9..b1639023 100644 --- a/src/cpl_cli/publish/publisher_service.py +++ b/src/cpl_cli/publish/publisher_service.py @@ -433,7 +433,7 @@ class PublisherService(PublisherABC): 3. Copies all included source files to dist_path/build :return: """ - self._env.set_working_directory(os.path.join(self._env.working_directory, '../')) # probably causing some errors (#125) + self._env.set_working_directory(os.path.join(self._env.working_directory, '../')) # probably causing some errors (#125) 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')) @@ -456,7 +456,7 @@ class PublisherService(PublisherABC): 4. Remove all included source from dist_path/publish :return: """ - self._env.set_working_directory(os.path.join(self._env.working_directory, '../')) # probably causing some errors (#125) + self._env.set_working_directory(os.path.join(self._env.working_directory, '../')) # probably causing some errors (#125) 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')) diff --git a/src/cpl_discord/cpl-discord.json b/src/cpl_discord/cpl-discord.json index cdaed19b..dabf8aab 100644 --- a/src/cpl_discord/cpl-discord.json +++ b/src/cpl_discord/cpl-discord.json @@ -24,9 +24,7 @@ "cpl-cli>=2022.10.0" ], "PythonVersion": ">=3.10.4", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/tests/custom/async/src/async/async.json b/tests/custom/async/src/async/async.json index 7e632a65..ab459429 100644 --- a/tests/custom/async/src/async/async.json +++ b/tests/custom/async/src/async/async.json @@ -19,9 +19,7 @@ "sh_cpl>=2021.10.0.post1" ], "PythonVersion": ">=3.9.2", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/tests/custom/database/cpl.json b/tests/custom/database/cpl.json index e964c144..ee84d745 100644 --- a/tests/custom/database/cpl.json +++ b/tests/custom/database/cpl.json @@ -19,9 +19,7 @@ "sh_cpl==2021.4.2.dev1" ], "PythonVersion": ">=3.9.2", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/tests/custom/di/src/di/di.json b/tests/custom/di/src/di/di.json index cd4e3ff2..67ca9bd5 100644 --- a/tests/custom/di/src/di/di.json +++ b/tests/custom/di/src/di/di.json @@ -19,9 +19,7 @@ "sh_cpl>=2021.10.0.post1" ], "PythonVersion": ">=3.9.2", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/tests/custom/discord/src/discord_bot/discord-bot.json b/tests/custom/discord/src/discord_bot/discord-bot.json index d91dbfcc..c543ea19 100644 --- a/tests/custom/discord/src/discord_bot/discord-bot.json +++ b/tests/custom/discord/src/discord_bot/discord-bot.json @@ -22,9 +22,7 @@ "cpl-cli>=2022.7.0" ], "PythonVersion": ">=3.10.4", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/tests/custom/discord/src/modules/hello_world/hello-world.json b/tests/custom/discord/src/modules/hello_world/hello-world.json index 869a7901..f5dd8fcc 100644 --- a/tests/custom/discord/src/modules/hello_world/hello-world.json +++ b/tests/custom/discord/src/modules/hello_world/hello-world.json @@ -22,9 +22,7 @@ "cpl-cli>=2022.7.0.post1" ], "PythonVersion": ">=3.10.4", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/tests/custom/translation/src/translation/translation.json b/tests/custom/translation/src/translation/translation.json index f857761d..dbbe2dcd 100644 --- a/tests/custom/translation/src/translation/translation.json +++ b/tests/custom/translation/src/translation/translation.json @@ -22,9 +22,7 @@ "cpl-cli>=2022.6.0" ], "PythonVersion": ">=3.10.4", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/tests/generated/simple-app/cpl.json b/tests/generated/simple-app/cpl.json index f223da45..1af0f6e6 100644 --- a/tests/generated/simple-app/cpl.json +++ b/tests/generated/simple-app/cpl.json @@ -19,9 +19,7 @@ "sh_cpl==2021.4.2" ], "PythonVersion": ">=3.9.2", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/tests/generated/simple-app/src/simple_app/simple-app.json b/tests/generated/simple-app/src/simple_app/simple-app.json index 5375d662..3aa9d743 100644 --- a/tests/generated/simple-app/src/simple_app/simple-app.json +++ b/tests/generated/simple-app/src/simple_app/simple-app.json @@ -19,9 +19,7 @@ "sh_cpl==2021.4.1rc2" ], "PythonVersion": ">=3.9.2", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/tests/generated/simple-console/cpl.json b/tests/generated/simple-console/cpl.json index 63fe1a4d..5ddc2f0f 100644 --- a/tests/generated/simple-console/cpl.json +++ b/tests/generated/simple-console/cpl.json @@ -19,9 +19,7 @@ "sh_cpl==2021.4.2" ], "PythonVersion": ">=3.9.2", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/tests/generated/simple-console/src/simple_console/simple-console.json b/tests/generated/simple-console/src/simple_console/simple-console.json index e05e9201..24d5c821 100644 --- a/tests/generated/simple-console/src/simple_console/simple-console.json +++ b/tests/generated/simple-console/src/simple_console/simple-console.json @@ -19,9 +19,7 @@ "sh_cpl==2021.4.1rc2" ], "PythonVersion": ">=3.9.2", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/tests/generated/simple-di/cpl.json b/tests/generated/simple-di/cpl.json index 8804958a..a048da7f 100644 --- a/tests/generated/simple-di/cpl.json +++ b/tests/generated/simple-di/cpl.json @@ -19,9 +19,7 @@ "sh_cpl==2021.4.2.dev1" ], "PythonVersion": ">=3.9.2", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/tests/generated/simple-di/src/simple_di/simple-di.json b/tests/generated/simple-di/src/simple_di/simple-di.json index b5591ebf..54751fcc 100644 --- a/tests/generated/simple-di/src/simple_di/simple-di.json +++ b/tests/generated/simple-di/src/simple_di/simple-di.json @@ -19,9 +19,7 @@ "sh_cpl==2021.4.1rc2" ], "PythonVersion": ">=3.9.2", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/tests/generated/simple-startup-app/src/simple_startup_app/simple-startup-app.json b/tests/generated/simple-startup-app/src/simple_startup_app/simple-startup-app.json index 6c036f08..80e4786f 100644 --- a/tests/generated/simple-startup-app/src/simple_startup_app/simple-startup-app.json +++ b/tests/generated/simple-startup-app/src/simple_startup_app/simple-startup-app.json @@ -19,9 +19,7 @@ "sh_cpl==2021.4.1rc2" ], "PythonVersion": ">=3.9.2", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/tests/generated/startup-app/cpl.json b/tests/generated/startup-app/cpl.json index 086c70ae..39de3a85 100644 --- a/tests/generated/startup-app/cpl.json +++ b/tests/generated/startup-app/cpl.json @@ -19,9 +19,7 @@ "sh_cpl==2021.4.2" ], "PythonVersion": ">=3.9.2", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": { diff --git a/unittests/unittests/unittests.json b/unittests/unittests/unittests.json index a3f1e8b3..bae65fc0 100644 --- a/unittests/unittests/unittests.json +++ b/unittests/unittests/unittests.json @@ -19,9 +19,7 @@ "cpl-core>=2022.10.0" ], "PythonVersion": ">=3.10.4", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [], "DevDependencies": [] }, diff --git a/unittests/unittests_cli/cli_test_suite.py b/unittests/unittests_cli/cli_test_suite.py index f26f3f3a..65cb6355 100644 --- a/unittests/unittests_cli/cli_test_suite.py +++ b/unittests/unittests_cli/cli_test_suite.py @@ -32,8 +32,8 @@ class CLITestSuite(unittest.TestSuite): active_tests = [ # nothing needed VersionTestCase, - GenerateTestCase, NewTestCase, + GenerateTestCase, # project needed BuildTestCase, PublishTestCase, @@ -75,4 +75,4 @@ class CLITestSuite(unittest.TestSuite): def run(self, *args): self._setup() self._result = super().run(*args) - self._cleanup() + # self._cleanup() diff --git a/unittests/unittests_cli/generate_test_case.py b/unittests/unittests_cli/generate_test_case.py index 53c03839..c53f28d5 100644 --- a/unittests/unittests_cli/generate_test_case.py +++ b/unittests/unittests_cli/generate_test_case.py @@ -1,41 +1,89 @@ import os.path import unittest +from cpl_core.utils import String from unittests_cli.constants import PLAYGROUND_PATH from unittests_shared.cli_commands import CLICommands class GenerateTestCase(unittest.TestCase): + _project = 'test-console' + _t_path = 'test' - def _test_file(self, schematic: str, suffix: str): - CLICommands.generate(schematic, 'GeneratedFile') - file_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, f'generated_file{suffix}.py')) + @classmethod + def setUpClass(cls): + CLICommands.new('console', cls._project, '--ab', '--s', '--venv') + + def setUp(self): + os.chdir(PLAYGROUND_PATH) + + def _test_file(self, schematic: str, suffix: str, path=None): + file = 'GeneratedFile' + expected_path = f'generated_file{suffix}.py' + if path is not None: + file = f'{path}/{file}' + expected_path = f'{path}/{expected_path}' + CLICommands.generate(schematic, file) + file_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, expected_path)) file_exists = os.path.exists(file_path) self.assertTrue(file_exists) + def _test_file_with_project(self, schematic: str, suffix: str, path=None, enter=True): + file = f'GeneratedFile' + excepted_path = f'generated_file{suffix}.py' + if path is not None: + excepted_path = f'{self._project}/src/{String.convert_to_snake_case(self._project)}/{path}/generated_file_in_project{suffix}.py' + if enter: + os.chdir(path) + excepted_path = f'{path}/src/{String.convert_to_snake_case(self._project)}/generated_file_in_project{suffix}.py' + + file = f'{path}/GeneratedFileInProject' + + CLICommands.generate(schematic, file) + file_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, excepted_path)) + self.assertTrue(os.path.exists(file_path)) + def test_abc(self): self._test_file('abc', '_abc') + self._test_file('abc', '_abc', path=self._t_path) + self._test_file('abc', '_abc', path=f'{self._t_path}/{self._t_path}') + self._test_file_with_project('abc', '_abc', path=self._project) + os.chdir(f'src/{String.convert_to_snake_case(self._project)}') + self._test_file_with_project('abc', '_abc', path='test', enter=False) def test_class(self): self._test_file('class', '') + self._test_file('class', '', path=self._t_path) + self._test_file_with_project('class', '', path=self._project) def test_enum(self): self._test_file('enum', '_enum') + self._test_file('enum', '_enum', path=self._t_path) + self._test_file_with_project('enum', '_enum', path=self._project) + os.chdir(f'src/{String.convert_to_snake_case(self._project)}') + self._test_file_with_project('enum', '_enum', path='test', enter=False) def test_pipe(self): self._test_file('pipe', '_pipe') + self._test_file('pipe', '_pipe', path=self._t_path) + self._test_file_with_project('pipe', '_pipe', path=self._project) def test_service(self): self._test_file('service', '_service') + self._test_file_with_project('service', '_service', path=self._project) def test_settings(self): self._test_file('settings', '_settings') + self._test_file_with_project('settings', '_settings', path=self._project) def test_test_case(self): self._test_file('test_case', '_test_case') + self._test_file_with_project('test_case', '_test_case', path=self._project) def test_thread(self): self._test_file('thread', '_thread') + self._test_file_with_project('thread', '_thread', path=self._project) def test_validator(self): self._test_file('validator', '_validator') + self._test_file_with_project('validator', '_validator', path=self._project) diff --git a/unittests/unittests_cli/unittests_cli.json b/unittests/unittests_cli/unittests_cli.json index aa975a3f..7b81087c 100644 --- a/unittests/unittests_cli/unittests_cli.json +++ b/unittests/unittests_cli/unittests_cli.json @@ -20,9 +20,7 @@ "cpl-cli>=2022.10.0" ], "PythonVersion": ">=3.10.4", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [], "DevDependencies": [] }, diff --git a/unittests/unittests_cli/update_test_case.py b/unittests/unittests_cli/update_test_case.py index de21bf6b..3b50b38c 100644 --- a/unittests/unittests_cli/update_test_case.py +++ b/unittests/unittests_cli/update_test_case.py @@ -22,7 +22,7 @@ class UpdateTestCase(unittest.TestCase): self._old_package = f'{self._old_package_name}=={self._old_version}' # todo: better way to do shit required - self._new_version = '2.0.1' + self._new_version = '2.1.0' self._new_package_name = 'discord.py' self._new_package = f'{self._new_package_name}=={self._new_version}' diff --git a/unittests/unittests_core/unittests_core.json b/unittests/unittests_core/unittests_core.json index 1e875549..143b7da1 100644 --- a/unittests/unittests_core/unittests_core.json +++ b/unittests/unittests_core/unittests_core.json @@ -19,9 +19,7 @@ "cpl-core>=2022.10.0" ], "PythonVersion": ">=3.10.4", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [], "DevDependencies": [] }, diff --git a/unittests/unittests_query/unittests_query.json b/unittests/unittests_query/unittests_query.json index d125ef96..bf5c4041 100644 --- a/unittests/unittests_query/unittests_query.json +++ b/unittests/unittests_query/unittests_query.json @@ -20,9 +20,7 @@ "cpl-query>=2022.10.0" ], "PythonVersion": ">=3.10.4", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [], "DevDependencies": [] }, diff --git a/unittests/unittests_shared/unittests_shared.json b/unittests/unittests_shared/unittests_shared.json index 795691a5..881cf7b1 100644 --- a/unittests/unittests_shared/unittests_shared.json +++ b/unittests/unittests_shared/unittests_shared.json @@ -19,9 +19,7 @@ "cpl-core>=2022.10.0" ], "PythonVersion": ">=3.10.4", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [], "DevDependencies": [] }, diff --git a/unittests/unittests_translation/unittests_translation.json b/unittests/unittests_translation/unittests_translation.json index f609a6d4..28396a27 100644 --- a/unittests/unittests_translation/unittests_translation.json +++ b/unittests/unittests_translation/unittests_translation.json @@ -23,9 +23,7 @@ "cpl-cli>=2022.10.0" ], "PythonVersion": ">=3.10.4", - "PythonPath": { - "linux": "" - }, + "PythonPath": {}, "Classifiers": [] }, "BuildSettings": {