Updated docs
This commit is contained in:
@@ -1,26 +1,26 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
"""
|
||||
cpl-cli sh-edraft Common Python library CLI
|
||||
cpl-cli CPL CLI
|
||||
~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
sh-edraft Common Python library Command Line Interface
|
||||
CPL Command Line Interface
|
||||
|
||||
:copyright: (c) 2020 - 2023 sh-edraft.de
|
||||
:license: MIT, see LICENSE for more details.
|
||||
|
||||
"""
|
||||
|
||||
__title__ = 'cpl_cli.live_server'
|
||||
__author__ = 'Sven Heidemann'
|
||||
__license__ = 'MIT'
|
||||
__copyright__ = 'Copyright (c) 2020 - 2023 sh-edraft.de'
|
||||
__version__ = '2022.12.1'
|
||||
__title__ = "cpl_cli.live_server"
|
||||
__author__ = "Sven Heidemann"
|
||||
__license__ = "MIT"
|
||||
__copyright__ = "Copyright (c) 2020 - 2023 sh-edraft.de"
|
||||
__version__ = "2023.2.0"
|
||||
|
||||
from collections import namedtuple
|
||||
|
||||
|
||||
# imports:
|
||||
|
||||
VersionInfo = namedtuple('VersionInfo', 'major minor micro')
|
||||
version_info = VersionInfo(major='2022', minor='12', micro='1')
|
||||
VersionInfo = namedtuple("VersionInfo", "major minor micro")
|
||||
version_info = VersionInfo(major="2023", minor="2", micro="0")
|
||||
|
@@ -16,13 +16,12 @@ from cpl_core.utils import String
|
||||
|
||||
|
||||
class LiveServerService(FileSystemEventHandler):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
env: ApplicationEnvironmentABC,
|
||||
project_settings: ProjectSettings,
|
||||
build_settings: BuildSettings,
|
||||
publisher: PublisherService,
|
||||
self,
|
||||
env: ApplicationEnvironmentABC,
|
||||
project_settings: ProjectSettings,
|
||||
build_settings: BuildSettings,
|
||||
publisher: PublisherService,
|
||||
):
|
||||
"""
|
||||
Service for the live development server
|
||||
@@ -51,7 +50,7 @@ class LiveServerService(FileSystemEventHandler):
|
||||
:return:
|
||||
"""
|
||||
self._observer = Observer()
|
||||
self._observer.schedule(self, path=os.path.abspath(os.path.join(self._src_dir, '../')), recursive=True)
|
||||
self._observer.schedule(self, path=os.path.abspath(os.path.join(self._src_dir, "../")), recursive=True)
|
||||
self._observer.start()
|
||||
|
||||
def _restart(self):
|
||||
@@ -64,7 +63,7 @@ class LiveServerService(FileSystemEventHandler):
|
||||
if proc.cmdline() == self._ls_thread.command:
|
||||
proc.kill()
|
||||
|
||||
Console.write_line('Restart\n')
|
||||
Console.write_line("Restart\n")
|
||||
while self._ls_thread.is_alive():
|
||||
time.sleep(1)
|
||||
|
||||
@@ -80,7 +79,7 @@ class LiveServerService(FileSystemEventHandler):
|
||||
return None
|
||||
|
||||
# Event is modified, you can process it now
|
||||
if str(event.src_path).endswith('.py'):
|
||||
if str(event.src_path).endswith(".py"):
|
||||
self._observer.stop()
|
||||
self._restart()
|
||||
|
||||
@@ -88,11 +87,7 @@ class LiveServerService(FileSystemEventHandler):
|
||||
self._build()
|
||||
self._start_observer()
|
||||
self._ls_thread = LiveServerThread(
|
||||
self._project_settings.python_executable,
|
||||
self._wd,
|
||||
self._args,
|
||||
self._env,
|
||||
self._build_settings
|
||||
self._project_settings.python_executable, self._wd, self._args, self._env, self._build_settings
|
||||
)
|
||||
self._ls_thread.start()
|
||||
self._ls_thread.join()
|
||||
@@ -105,13 +100,15 @@ class LiveServerService(FileSystemEventHandler):
|
||||
self._env.set_working_directory(self._src_dir)
|
||||
self._publisher.build()
|
||||
self._env.set_working_directory(self._src_dir)
|
||||
self._wd = os.path.abspath(os.path.join(
|
||||
self._src_dir,
|
||||
self._build_settings.output_path,
|
||||
self._project_settings.name,
|
||||
'build',
|
||||
String.convert_to_snake_case(self._project_settings.name)
|
||||
))
|
||||
self._wd = os.path.abspath(
|
||||
os.path.join(
|
||||
self._src_dir,
|
||||
self._build_settings.output_path,
|
||||
self._project_settings.name,
|
||||
"build",
|
||||
String.convert_to_snake_case(self._project_settings.name),
|
||||
)
|
||||
)
|
||||
|
||||
def start(self, args: list[str]):
|
||||
"""
|
||||
@@ -119,14 +116,14 @@ class LiveServerService(FileSystemEventHandler):
|
||||
:param args:
|
||||
:return:
|
||||
"""
|
||||
if self._build_settings.main == '':
|
||||
Console.error('Project has no entry point.')
|
||||
if self._build_settings.main == "":
|
||||
Console.error("Project has no entry point.")
|
||||
return
|
||||
|
||||
if 'dev' in args:
|
||||
if "dev" in args:
|
||||
self._is_dev = True
|
||||
args.remove('dev')
|
||||
args.remove("dev")
|
||||
|
||||
self._args = args
|
||||
Console.write_line('** CPL live development server is running **')
|
||||
Console.write_line("** CPL live development server is running **")
|
||||
self._start()
|
||||
|
@@ -11,9 +11,9 @@ from cpl_cli.configuration import BuildSettings
|
||||
|
||||
|
||||
class LiveServerThread(threading.Thread):
|
||||
|
||||
def __init__(self, executable: str, path: str, args: list[str], env: ApplicationEnvironmentABC,
|
||||
build_settings: BuildSettings):
|
||||
def __init__(
|
||||
self, executable: str, path: str, args: list[str], env: ApplicationEnvironmentABC, build_settings: BuildSettings
|
||||
):
|
||||
"""
|
||||
Thread to start the CPL project for the live development server
|
||||
:param executable:
|
||||
@@ -31,7 +31,7 @@ class LiveServerThread(threading.Thread):
|
||||
self._env = env
|
||||
self._build_settings = build_settings
|
||||
|
||||
self._main = ''
|
||||
self._main = ""
|
||||
self._command = []
|
||||
self._env_vars = os.environ
|
||||
|
||||
@@ -49,27 +49,29 @@ class LiveServerThread(threading.Thread):
|
||||
:return:
|
||||
"""
|
||||
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]
|
||||
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(self._path, f'{main}.py')
|
||||
self._main = os.path.join(self._path, f"{main}.py")
|
||||
if not os.path.isfile(self._main):
|
||||
Console.error('Entry point main.py not found')
|
||||
Console.error("Entry point main.py not found")
|
||||
return
|
||||
|
||||
# set cwd to src/
|
||||
self._env.set_working_directory(os.path.abspath(os.path.join(self._path)))
|
||||
src_cwd = os.path.abspath(os.path.join(self._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)}'
|
||||
src_cwd = os.path.abspath(os.path.join(self._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)}'
|
||||
self._env_vars["PYTHONPATH"] = (
|
||||
f"{src_cwd}:" f"{os.path.join(self._env.working_directory, self._build_settings.source_path)}"
|
||||
)
|
||||
|
||||
Console.set_foreground_color(ForegroundColorEnum.green)
|
||||
Console.write_line('Read successfully')
|
||||
Console.write_line("Read successfully")
|
||||
Console.set_foreground_color(ForegroundColorEnum.cyan)
|
||||
now = datetime.now()
|
||||
Console.write_line(f'Started at {now.strftime("%Y-%m-%d %H:%M:%S")}\n\n')
|
||||
|
@@ -10,7 +10,6 @@ from cpl_cli.configuration.build_settings import BuildSettings
|
||||
|
||||
|
||||
class StartExecutable:
|
||||
|
||||
def __init__(self, env: ApplicationEnvironmentABC, build_settings: BuildSettings):
|
||||
"""
|
||||
Service to start the CPL project for the live development server
|
||||
@@ -23,7 +22,7 @@ class StartExecutable:
|
||||
self._env = env
|
||||
self._build_settings = build_settings
|
||||
|
||||
self._main = ''
|
||||
self._main = ""
|
||||
self._command = []
|
||||
self._env_vars = os.environ
|
||||
|
||||
@@ -34,42 +33,44 @@ class StartExecutable:
|
||||
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', '')
|
||||
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["PATH"] = f"{path}/bin" + os.pathsep + os.environ.get("PATH", "")
|
||||
|
||||
self._env_vars['VIRTUAL_ENV'] = path
|
||||
self._env_vars["VIRTUAL_ENV"] = path
|
||||
|
||||
def run(self, args: list[str], executable: str, path: str, output=True):
|
||||
self._executable = os.path.abspath(os.path.join(self._env.working_directory, executable))
|
||||
if not os.path.exists(self._executable):
|
||||
Console.error(f'Executable not found')
|
||||
Console.error(f"Executable not found")
|
||||
return
|
||||
|
||||
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]
|
||||
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')
|
||||
self._main = os.path.join(path, f"{main}.py")
|
||||
if not os.path.isfile(self._main):
|
||||
Console.error('Entry point main.py not found')
|
||||
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)}'
|
||||
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)}'
|
||||
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.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)
|
||||
|
Reference in New Issue
Block a user