Added --dev flag to cpl run & start #124

This commit is contained in:
Sven Heidemann 2022-12-02 17:48:35 +01:00
parent 4dc7ee3314
commit 3c20ab296a
8 changed files with 84 additions and 20 deletions

View File

@ -8,6 +8,7 @@ from cpl_cli.configuration import WorkspaceSettings
from cpl_cli.configuration.build_settings import BuildSettings from cpl_cli.configuration.build_settings import BuildSettings
from cpl_cli.configuration.project_settings import ProjectSettings from cpl_cli.configuration.project_settings import ProjectSettings
from cpl_cli.live_server.start_executable import StartExecutable from cpl_cli.live_server.start_executable import StartExecutable
from cpl_cli.publish import PublisherService
from cpl_core.configuration import ConfigurationABC from cpl_core.configuration import ConfigurationABC
from cpl_core.console.console import Console from cpl_core.console.console import Console
from cpl_core.dependency_injection import ServiceProviderABC from cpl_core.dependency_injection import ServiceProviderABC
@ -22,7 +23,8 @@ class RunService(CommandABC):
services: ServiceProviderABC, services: ServiceProviderABC,
project_settings: ProjectSettings, project_settings: ProjectSettings,
build_settings: BuildSettings, build_settings: BuildSettings,
workspace: WorkspaceSettings workspace: WorkspaceSettings,
publisher: PublisherService,
): ):
""" """
Service for the CLI command start Service for the CLI command start
@ -41,8 +43,10 @@ class RunService(CommandABC):
self._project_settings = project_settings self._project_settings = project_settings
self._build_settings = build_settings self._build_settings = build_settings
self._workspace = workspace self._workspace = workspace
self._publisher = publisher
self._src_dir = os.path.join(self._env.working_directory, self._build_settings.source_path) self._src_dir = os.path.join(self._env.working_directory, self._build_settings.source_path)
self._is_dev = False
@property @property
def help_message(self) -> str: def help_message(self) -> str:
@ -80,16 +84,27 @@ class RunService(CommandABC):
self._src_dir = os.path.dirname(json_file) self._src_dir = os.path.dirname(json_file)
def _build(self):
if self._is_dev:
return
self._publisher.build()
def execute(self, args: list[str]): def execute(self, args: list[str]):
""" """
Entry point of command Entry point of command
:param args: :param args:
:return: :return:
""" """
if 'dev' in args:
self._is_dev = True
args.remove('dev')
if len(args) >= 1: if len(args) >= 1:
self._set_project_by_args(args[0]) self._set_project_by_args(args[0])
args.remove(args[0]) args.remove(args[0])
self._build()
start_service = StartExecutable(self._env, self._build_settings) start_service = StartExecutable(self._env, self._build_settings)
start_service.run(args, self._project_settings.python_executable, self._src_dir, output=False) start_service.run(args, self._project_settings.python_executable, self._src_dir, output=False)
Console.write_line() Console.write_line()

View File

@ -6,6 +6,7 @@ import psutil as psutil
from watchdog.events import FileSystemEventHandler from watchdog.events import FileSystemEventHandler
from watchdog.observers import Observer from watchdog.observers import Observer
from cpl_cli.publish import PublisherService
from cpl_core.console.console import Console from cpl_core.console.console import Console
from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC from cpl_core.environment.application_environment_abc import ApplicationEnvironmentABC
from cpl_cli.configuration.build_settings import BuildSettings from cpl_cli.configuration.build_settings import BuildSettings
@ -15,8 +16,13 @@ from cpl_cli.live_server.live_server_thread import LiveServerThread
class LiveServerService(FileSystemEventHandler): class LiveServerService(FileSystemEventHandler):
def __init__(self, env: ApplicationEnvironmentABC, project_settings: ProjectSettings, def __init__(
build_settings: BuildSettings): self,
env: ApplicationEnvironmentABC,
project_settings: ProjectSettings,
build_settings: BuildSettings,
publisher: PublisherService,
):
""" """
Service for the live development server Service for the live development server
:param env: :param env:
@ -28,12 +34,14 @@ class LiveServerService(FileSystemEventHandler):
self._env = env self._env = env
self._project_settings = project_settings self._project_settings = project_settings
self._build_settings = build_settings self._build_settings = build_settings
self._publisher = publisher
self._src_dir = os.path.join(self._env.working_directory, self._build_settings.source_path) self._src_dir = os.path.join(self._env.working_directory, self._build_settings.source_path)
self._ls_thread = None self._ls_thread = None
self._observer = None self._observer = None
self._args: list[str] = [] self._args: list[str] = []
self._is_dev = False
def _start_observer(self): def _start_observer(self):
""" """
@ -87,6 +95,11 @@ class LiveServerService(FileSystemEventHandler):
self._ls_thread.join() self._ls_thread.join()
Console.close() Console.close()
def _build(self):
if self._is_dev:
return
self._publisher.build()
def start(self, args: list[str]): def start(self, args: list[str]):
""" """
Starts the CPL live development server Starts the CPL live development server
@ -97,6 +110,12 @@ class LiveServerService(FileSystemEventHandler):
Console.error('Project has no entry point.') Console.error('Project has no entry point.')
return return
if 'dev' in args:
self._is_dev = True
args.remove('dev')
self._build()
self._args = args self._args = args
Console.write_line('** CPL live development server is running **') Console.write_line('** CPL live development server is running **')
self._start() self._start()

View File

@ -60,8 +60,10 @@ class StartupArgumentExtension(StartupExtensionABC):
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'publish', ['p', 'P'], PublishService, True, validators=[ProjectValidator]) 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]) \ config.create_console_argument(ArgumentTypeEnum.Executable, '', 'remove', ['r', 'R'], RemoveService, True, validators=[WorkspaceValidator]) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S']) .add_console_argument(ArgumentTypeEnum.Flag, '--', 'simulate', ['s', 'S'])
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'run', [], RunService, True, validators=[ProjectValidator]) config.create_console_argument(ArgumentTypeEnum.Executable, '', 'run', [], RunService, True, validators=[ProjectValidator]) \
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'start', ['s', 'S'], StartService, True, validators=[ProjectValidator]) .add_console_argument(ArgumentTypeEnum.Flag, '--', 'dev', ['d', 'D'])
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'start', ['s', 'S'], StartService, True, validators=[ProjectValidator]) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'dev', ['d', 'D'])
config.create_console_argument(ArgumentTypeEnum.Executable, '', 'uninstall', ['ui', 'UI'], UninstallService, 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, '--', 'dev', ['d', 'D']) \
.add_console_argument(ArgumentTypeEnum.Flag, '--', 'virtual', ['v', 'V']) \ .add_console_argument(ArgumentTypeEnum.Flag, '--', 'virtual', ['v', 'V']) \

View File

@ -0,0 +1,26 @@
# -*- coding: utf-8 -*-
"""
general 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__ = 'general.arguments'
__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='04', micro='01')

View File

@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
""" """
sh_cpl sh-edraft Common Python library general sh-edraft Common Python library
~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~
sh-edraft Common Python library sh-edraft Common Python library
@ -11,7 +11,7 @@ sh-edraft Common Python library
""" """
__title__ = 'tests.db' __title__ = 'general.db'
__author__ = 'Sven Heidemann' __author__ = 'Sven Heidemann'
__license__ = 'MIT' __license__ = 'MIT'
__copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de' __copyright__ = 'Copyright (c) 2020 - 2021 sh-edraft.de'
@ -19,7 +19,8 @@ __version__ = '2021.4.1'
from collections import namedtuple from collections import namedtuple
# imports: # imports:
VersionInfo = namedtuple('VersionInfo', 'major minor micro') VersionInfo = namedtuple('VersionInfo', 'major minor micro')
version_info = VersionInfo(major=2021, minor=4, micro=1) version_info = VersionInfo(major='2021', minor='04', micro='01')

View File

@ -16,12 +16,12 @@
"LicenseName": "MIT", "LicenseName": "MIT",
"LicenseDescription": "MIT, see LICENSE for more details.", "LicenseDescription": "MIT, see LICENSE for more details.",
"Dependencies": [ "Dependencies": [
"cpl-core==2022.10rc2", "cpl-core==2022.10.0.post9",
"cpl-translation==2022.10rc2", "cpl-translation==2022.10.0.post2",
"cpl-query==2022.10rc2" "cpl-query==2022.10.0.post2"
], ],
"DevDependencies": [ "DevDependencies": [
"cpl-cli==2022.10.rc2" "cpl-cli==2022.10"
], ],
"PythonVersion": ">=3.10", "PythonVersion": ">=3.10",
"PythonPath": { "PythonPath": {

View File

@ -46,9 +46,6 @@ class RunTestCase(CommandTestCase):
project_file.close() project_file.close()
def setUp(self): def setUp(self):
if not os.path.exists(PLAYGROUND_PATH):
os.makedirs(PLAYGROUND_PATH)
os.chdir(PLAYGROUND_PATH) os.chdir(PLAYGROUND_PATH)
# create projects # create projects
CLICommands.new('console', self._source, '--ab', '--s') CLICommands.new('console', self._source, '--ab', '--s')
@ -60,7 +57,7 @@ class RunTestCase(CommandTestCase):
file.close() file.close()
def test_run(self): def test_run(self):
CLICommands.run() CLICommands.run(is_dev=True, output=True)
settings = self._get_appsettings() settings = self._get_appsettings()
self.assertNotEqual(settings, {}) self.assertNotEqual(settings, {})
self.assertIn('RunTest', settings) self.assertIn('RunTest', settings)
@ -72,7 +69,7 @@ class RunTestCase(CommandTestCase):
def test_run_by_project(self): def test_run_by_project(self):
os.chdir(os.path.join(os.getcwd())) os.chdir(os.path.join(os.getcwd()))
CLICommands.run(self._source) CLICommands.run(self._source, is_dev=True)
settings = self._get_appsettings() settings = self._get_appsettings()
self.assertNotEqual(settings, {}) self.assertNotEqual(settings, {})
self.assertIn('RunTest', settings) self.assertIn('RunTest', settings)

View File

@ -65,11 +65,15 @@ class CLICommands:
cls._run('remove', project, output=output) cls._run('remove', project, output=output)
@classmethod @classmethod
def run(cls, project: str = None, output=False): def run(cls, project: str = None, is_dev=False, output=False):
dev = ''
if is_dev:
dev = '--dev'
if project is None: if project is None:
cls._run('run', output=output) cls._run('run', dev, output=output)
return return
cls._run('run', project, output=output) cls._run('run', project, dev, output=output)
@classmethod @classmethod
def start(cls, output=False): def start(cls, output=False):