2022.12 #133

Merged
edraft merged 85 commits from 2022.12 into master 2022-12-25 11:58:35 +01:00
3 changed files with 33 additions and 5 deletions
Showing only changes of commit 703a2c91b5 - Show all commits

View File

@ -54,6 +54,7 @@ class NewService(CommandABC):
self._use_service_providing: bool = False
self._use_async: bool = False
self._use_venv: bool = False
self._use_base: bool = False
@property
def help_message(self) -> str:
@ -159,7 +160,8 @@ class NewService(CommandABC):
if self._workspace is None:
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', self._rel_path, String.convert_to_snake_case(self._project.name))
base = '' if self._use_base else 'src'
project_path = os.path.join(self._env.working_directory, base, 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)
@ -292,6 +294,9 @@ class NewService(CommandABC):
if self._env.working_directory.endswith(project):
project = ''
if self._workspace is None and self._use_base:
project = f'{self._rel_path}/{project}'
VenvHelper.init_venv(
False,
self._env,
@ -335,6 +340,9 @@ class NewService(CommandABC):
if 'venv' in args:
self._use_venv = True
args.remove('venv')
if 'base' in args:
self._use_base = True
args.remove('base')
console = self._config.get_configuration(ProjectTypeEnum.console.value)
library = self._config.get_configuration(ProjectTypeEnum.library.value)

View File

@ -55,7 +55,8 @@ class StartupArgumentExtension(StartupExtensionABC):
.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'])
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'venv', ['v', 'V']) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'base', ['b', 'B'])
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'])

View File

@ -12,7 +12,7 @@ class NewTestCase(unittest.TestCase):
def setUp(self):
os.chdir(os.path.abspath(PLAYGROUND_PATH))
def _test_project(self, project_type: str, name: str, *args, test_venv=False):
def _test_project(self, project_type: str, name: str, *args, test_venv=False, without_ws=False):
CLICommands.new(project_type, name, *args)
workspace_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, name))
self.assertTrue(os.path.exists(workspace_path))
@ -22,7 +22,15 @@ class NewTestCase(unittest.TestCase):
self.assertTrue(os.path.exists(os.path.join(workspace_path, 'venv/bin/python')))
self.assertTrue(os.path.islink(os.path.join(workspace_path, 'venv/bin/python')))
project_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, name, 'src', String.convert_to_snake_case(name)))
base = 'src'
if '--base' in args and '/' in name:
base = name.split('/')[0]
name = name.replace(f'{name.split("/")[0]}/', '')
project_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, name, base, String.convert_to_snake_case(name)))
if without_ws:
project_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, base, name, 'src/', String.convert_to_snake_case(name)))
self.assertTrue(os.path.exists(project_path))
self.assertTrue(os.path.join(project_path, f'{name}.json'))
self.assertTrue(os.path.join(project_path, f'main.py'))
@ -54,7 +62,12 @@ class NewTestCase(unittest.TestCase):
self.assertTrue(os.path.exists(os.path.join(workspace_path, 'venv/bin/python')))
self.assertTrue(os.path.islink(os.path.join(workspace_path, 'venv/bin/python')))
project_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, workspace_name, 'src', String.convert_to_snake_case(name)))
base = 'src'
if '--base' in args and '/' in name:
base = name.split('/')[0]
name = name.replace(f'{name.split("/")[0]}/', '')
project_path = os.path.abspath(os.path.join(PLAYGROUND_PATH, workspace_name, base, String.convert_to_snake_case(name)))
self.assertTrue(os.path.exists(project_path))
self.assertTrue(os.path.join(project_path, f'{name}.json'))
os.chdir(os.path.abspath(os.path.join(os.getcwd(), '../')))
@ -88,6 +101,9 @@ class NewTestCase(unittest.TestCase):
def test_console(self):
self._test_project('console', 'test-console', '--ab', '--s', '--venv', test_venv=True)
def test_console_with_other_base(self):
self._test_project('console', 'tools/test-console', '--ab', '--s', '--venv', '--base', test_venv=True, without_ws=True)
def test_console_without_s(self):
self._test_project('console', 'test-console-without-s', '--ab')
@ -100,6 +116,9 @@ class NewTestCase(unittest.TestCase):
def test_sub_console(self):
self._test_sub_project('console', 'test-sub-console', 'test-console', '--ab', '--s', '--sp', '--venv', test_venv=True)
def test_sub_console_with_other_base(self):
self._test_sub_project('console', 'tools/test-sub-console', 'test-console', '--ab', '--s', '--sp', '--venv', '--base', test_venv=True)
def test_library(self):
self._test_project('library', 'test-library', '--ab', '--s', '--sp')