From 2fad93dc40597ef7ed71ba48009dacc4dd2e059a Mon Sep 17 00:00:00 2001 From: Peter Willendrup Date: Thu, 15 Aug 2024 13:51:03 +0200 Subject: [PATCH 01/15] Makeshift "timeout" solution for mcdisplay-webgl - will shut down background "vite" server after --timeout seconds --- tools/Python/mcdisplay/webgl/mcdisplay.py | 32 ++++++++++++++++++----- 1 file changed, 26 insertions(+), 6 deletions(-) diff --git a/tools/Python/mcdisplay/webgl/mcdisplay.py b/tools/Python/mcdisplay/webgl/mcdisplay.py index 4a2546c1a..d4be9d687 100755 --- a/tools/Python/mcdisplay/webgl/mcdisplay.py +++ b/tools/Python/mcdisplay/webgl/mcdisplay.py @@ -5,6 +5,8 @@ ''' import os import sys +import signal +import time import logging import json import subprocess @@ -94,9 +96,9 @@ def _write_html(instrument, html_filepath, first=None, last=None, invcanvas=Fals writer = SimpleWriter(templatefile, html_filepath, invcanvas) writer.write() -def write_browse(instrument, raybundle, dirname, instrname, nobrowse=None, first=None, last=None, invcanvas=None, **kwds): +def write_browse(instrument, raybundle, dirname, instrname, timeout, nobrowse=None, first=None, last=None, invcanvas=None, **kwds): ''' writes instrument definitions to html/ js ''' - print("Launching WebGL...") + print("Launching WebGL... - timeout is " + str(timeout)) def copy(a, b): shutil_copy(str(a), str(b)) @@ -164,13 +166,21 @@ def run_npm_and_capture_port(port_container): if part.startswith('http://localhost:'): port = part.split(':')[-1].rstrip('/') port_container['port'] = port + port_container['process'] = proc return except subprocess.CalledProcessError as e: print(f"npm run dev failed: {e}") return None + def signal_handler(sig, frame): + global port_container + print('Received signal ' + str(sig)) + port_container['process'].send_signal(signal.SIGTERM) + sys.exit(0) + # Container to hold the port information - port_container = {'port': None} + global port_container + port_container = {'port': None, 'process': None} # Start npm and capture the port in a separate thread npm_thread = Thread(target=lambda: run_npm_and_capture_port(port_container)) @@ -183,13 +193,23 @@ def run_npm_and_capture_port(port_container): webbrowser.open(f"http://localhost:{port_container['port']}/") else: print("Failed to determine the localhost port") + if port_container['process']: + signal.signal(signal.SIGTERM, signal_handler) + signal.signal(signal.SIGINT, signal_handler) + signal.signal(signal.SIGUSR1, signal_handler) + signal.signal(signal.SIGUSR2, signal_handler) + print('Press Ctrl+C to exit - otherwise visualisation vill terminate server after ' + str(timeout) + ' s') + time.sleep(timeout) + print("Sending SIGTERM to npm/vite server") + port_container['process'].send_signal(signal.SIGTERM) + sys.exit(0) def file_save(data, filename): ''' saves data for debug purposes ''' with open(filename, 'w') as f: f.write(data) -def main(instr=None, dirname=None, debug=None, n=None, **kwds): +def main(instr=None, dirname=None, debug=None, n=None, timeout=None, **kwds): logging.basicConfig(level=logging.INFO) # output directory @@ -204,7 +224,7 @@ def main(instr=None, dirname=None, debug=None, n=None, **kwds): raybundle = reader.read_particles() # write output files - write_browse(instrument, raybundle, dirname, instr, **kwds) + write_browse(instrument, raybundle, dirname, instr, timeout, **kwds) if debug: # this should enable template.html to load directly @@ -223,7 +243,7 @@ def main(instr=None, dirname=None, debug=None, n=None, **kwds): parser.add_argument('--last', help='zoom range last component') parser.add_argument('-n', '--ncount', dest='n', type=float, default=300, help='Number of particles to simulate') parser.add_argument('-t', '--trace', dest='trace', type=int, default=2, help='Select visualization mode') - + parser.add_argument('--timeout', dest='timeout', type=int, default=300, help='Shutdown time of npm/vite server') args, unknown = parser.parse_known_args() # Convert the defined arguments in the args Namespace structure to a dict args = {k: args.__getattribute__(k) for k in dir(args) if k[0] != '_'} From c0e491480607d3dafc9507288817369bd263b197 Mon Sep 17 00:00:00 2001 From: Peter Willendrup Date: Thu, 15 Aug 2024 14:56:06 +0200 Subject: [PATCH 02/15] Don't run npminstall script during installation -> user 1st time tool instead --- tools/Python/mcdisplay/webgl/CMakeLists.txt | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/Python/mcdisplay/webgl/CMakeLists.txt b/tools/Python/mcdisplay/webgl/CMakeLists.txt index e30c7aae6..056d53f17 100644 --- a/tools/Python/mcdisplay/webgl/CMakeLists.txt +++ b/tools/Python/mcdisplay/webgl/CMakeLists.txt @@ -157,7 +157,6 @@ if (NOT WINDOWS) PROGRAMS "${WORK}/npminstall" DESTINATION ${DEST_TOOLDIR}/${TOOLS_NAME} ) - install(CODE "execute_process(COMMAND \"${CMAKE_INSTALL_PREFIX}/${DEST_TOOLDIR}/${TOOLS_NAME}/npminstall\")") else() # Configure fallback script configure_file("${CMAKE_CURRENT_SOURCE_DIR}/npminstall.bat.in" "${WORK}/npminstall.bat" @ONLY) @@ -165,5 +164,4 @@ else() PROGRAMS "${WORK}/npminstall.bat" DESTINATION ${DEST_TOOLDIR}/${TOOLS_NAME} ) - install(CODE "execute_process(COMMAND \"${CMAKE_INSTALL_PREFIX}/${DEST_TOOLDIR}/${TOOLS_NAME}/npminstall.bat\")") endif() From 4d7808235bd4d55657f065b6235aec345050c3d7 Mon Sep 17 00:00:00 2001 From: Peter Willendrup Date: Thu, 15 Aug 2024 14:56:51 +0200 Subject: [PATCH 03/15] Adapt unix version of script to install js code in .mcstas/.mcxtrace --- tools/Python/mcdisplay/webgl/npminstall.in | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tools/Python/mcdisplay/webgl/npminstall.in b/tools/Python/mcdisplay/webgl/npminstall.in index b048b4cff..18afd246c 100755 --- a/tools/Python/mcdisplay/webgl/npminstall.in +++ b/tools/Python/mcdisplay/webgl/npminstall.in @@ -1,7 +1,13 @@ #!/usr/bin/env bash set -e +cd ${HOME} && mkdir -p .@FLAVOR@ && cd .@FLAVOR@ && mkdir -p @MCCODE_VERSION@ && cd @MCCODE_VERSION@ && mkdir -p webgl && cd webgl + FILE=${0} -cd `dirname $FILE` +TOOLDIR=`dirname $FILE` +cp ${TOOLDIR}/*.tsx . +cp ${TOOLDIR}/index.html . +cp ${TOOLDIR}/*.js . +cp ${TOOLDIR}/package.json . npm install npm run build From d84f8ba8571a4e1ed8bd75c2e02bc99f2942f828 Mon Sep 17 00:00:00 2001 From: Peter Willendrup Date: Thu, 15 Aug 2024 15:29:08 +0200 Subject: [PATCH 04/15] More fixes to allow npm install in user local dir --- tools/Python/mcdisplay/webgl/npminstall.in | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tools/Python/mcdisplay/webgl/npminstall.in b/tools/Python/mcdisplay/webgl/npminstall.in index 18afd246c..31bb5e059 100755 --- a/tools/Python/mcdisplay/webgl/npminstall.in +++ b/tools/Python/mcdisplay/webgl/npminstall.in @@ -1,4 +1,5 @@ #!/usr/bin/env bash +@MCCODE_BASH_STANDARD_PREAMBLE@ set -e cd ${HOME} && mkdir -p .@FLAVOR@ && cd .@FLAVOR@ && mkdir -p @MCCODE_VERSION@ && cd @MCCODE_VERSION@ && mkdir -p webgl && cd webgl @@ -6,8 +7,13 @@ cd ${HOME} && mkdir -p .@FLAVOR@ && cd .@FLAVOR@ && mkdir -p @MCCODE_VERSION@ && FILE=${0} TOOLDIR=`dirname $FILE` cp ${TOOLDIR}/*.tsx . +cp ${TOOLDIR}/*.css . cp ${TOOLDIR}/index.html . cp ${TOOLDIR}/*.js . cp ${TOOLDIR}/package.json . +rsync -avz ${TOOLDIR}/Contexts/ Contexts +rsync -avz ${TOOLDIR}/utils/ utils +rsync -avz ${TOOLDIR}/data-utils/ data-utils +rsync -avz ${TOOLDIR}/components/ components npm install npm run build From 44b3fcf628b0278d02a1a6cd13d2a7076ea3d2d6 Mon Sep 17 00:00:00 2001 From: Peter Willendrup Date: Thu, 15 Aug 2024 15:56:50 +0200 Subject: [PATCH 05/15] Run off of 'dist' in local user folder --- tools/Python/mcdisplay/webgl/mcdisplay.py | 34 ++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/tools/Python/mcdisplay/webgl/mcdisplay.py b/tools/Python/mcdisplay/webgl/mcdisplay.py index d4be9d687..cd4dbb45f 100755 --- a/tools/Python/mcdisplay/webgl/mcdisplay.py +++ b/tools/Python/mcdisplay/webgl/mcdisplay.py @@ -102,7 +102,11 @@ def write_browse(instrument, raybundle, dirname, instrname, timeout, nobrowse=No def copy(a, b): shutil_copy(str(a), str(b)) - source = Path(__file__).absolute().parent + if os.name == 'nt': + source = os.path.join(os.path.expandvars("$USERPROFILE"),"AppData",configuration['MCCODE'],configuration['MCCODE_VERSION'],'webgl') + else: + source = os.path.join(os.path.expandvars("$HOME"),"." + configuration['MCCODE'],configuration['MCCODE_VERSION'],'webgl') + dest = Path(dirname) if dest.exists(): raise RuntimeError(f"The specified destination {dirname} already exists!") @@ -211,7 +215,35 @@ def file_save(data, filename): def main(instr=None, dirname=None, debug=None, n=None, timeout=None, **kwds): logging.basicConfig(level=logging.INFO) + + # Function to run npm commands and capture port + def run_npminstall(): + if not os.name == 'nt': + npminst = "npminstall" + else: + npminst = "npminstall.bat" + npminst = Path(__file__).absolute().parent.joinpath(npminst) + try: + proc = subprocess.Popen(npinst, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + for line in proc.stdout: + print(line) + except subprocess.CalledProcessError as e: + print(f"npminstall failed: {e}") + return None + # 1st run setup: Check if the user has a "webgl" folder or not + if os.name == 'nt': + userdir = os.path.join(os.path.expandvars("$USERPROFILE"),"AppData",configuration['MCCODE'],configuration['MCCODE_VERSION'],'webgl') + else: + userdir = os.path.join(os.path.expandvars("$HOME"),"." + configuration['MCCODE'],configuration['MCCODE_VERSION'],'webgl') + + if not os.path.isdir(userdir): + try: + os.mkdir(userdir) + except Exception as e: + print("Local WebGL Directory %s could not be created: %s " % (userdir, e.__str__())) + + # output directory if dirname is None: from datetime import datetime as dt From 040ad1d0207a4deadc2b3b7c395176deea3cf888 Mon Sep 17 00:00:00 2001 From: Peter Willendrup Date: Thu, 15 Aug 2024 16:21:40 +0200 Subject: [PATCH 06/15] Run npminstall scriptlet if user WebGL files do not exist --- tools/Python/mcdisplay/webgl/mcdisplay.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/tools/Python/mcdisplay/webgl/mcdisplay.py b/tools/Python/mcdisplay/webgl/mcdisplay.py index cd4dbb45f..a86d226f9 100755 --- a/tools/Python/mcdisplay/webgl/mcdisplay.py +++ b/tools/Python/mcdisplay/webgl/mcdisplay.py @@ -103,9 +103,9 @@ def copy(a, b): shutil_copy(str(a), str(b)) if os.name == 'nt': - source = os.path.join(os.path.expandvars("$USERPROFILE"),"AppData",configuration['MCCODE'],configuration['MCCODE_VERSION'],'webgl') + source = Path(os.path.join(os.path.expandvars("$USERPROFILE"),"AppData",mccode_config.configuration['MCCODE'],mccode_config.configuration['MCCODE_VERSION'],'webgl')) else: - source = os.path.join(os.path.expandvars("$HOME"),"." + configuration['MCCODE'],configuration['MCCODE_VERSION'],'webgl') + source = Path(os.path.join(os.path.expandvars("$HOME"),"." + mccode_config.configuration['MCCODE'],mccode_config.configuration['MCCODE_VERSION'],'webgl')) dest = Path(dirname) if dest.exists(): @@ -224,22 +224,21 @@ def run_npminstall(): npminst = "npminstall.bat" npminst = Path(__file__).absolute().parent.joinpath(npminst) try: - proc = subprocess.Popen(npinst, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) - for line in proc.stdout: - print(line) + proc = subprocess.Popen(npminst, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + print("Installing npm / vite modules") except subprocess.CalledProcessError as e: print(f"npminstall failed: {e}") return None # 1st run setup: Check if the user has a "webgl" folder or not if os.name == 'nt': - userdir = os.path.join(os.path.expandvars("$USERPROFILE"),"AppData",configuration['MCCODE'],configuration['MCCODE_VERSION'],'webgl') + userdir = os.path.join(os.path.expandvars("$USERPROFILE"),"AppData",mccode_config.configuration['MCCODE'],mccode_config.configuration['MCCODE_VERSION'],'webgl') else: - userdir = os.path.join(os.path.expandvars("$HOME"),"." + configuration['MCCODE'],configuration['MCCODE_VERSION'],'webgl') + userdir = os.path.join(os.path.expandvars("$HOME"),"." + mccode_config.configuration['MCCODE'],mccode_config.configuration['MCCODE_VERSION'],'webgl') if not os.path.isdir(userdir): try: - os.mkdir(userdir) + run_npminstall() except Exception as e: print("Local WebGL Directory %s could not be created: %s " % (userdir, e.__str__())) From 27b5a3ef99bdd68e131a68ba5936adecb7303557 Mon Sep 17 00:00:00 2001 From: Peter Willendrup Date: Thu, 15 Aug 2024 18:55:26 +0200 Subject: [PATCH 07/15] First draft of batch npm install script --- .../Python/mcdisplay/webgl/npminstall.bat.in | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/tools/Python/mcdisplay/webgl/npminstall.bat.in b/tools/Python/mcdisplay/webgl/npminstall.bat.in index 884a8d49b..3ed91b6c6 100644 --- a/tools/Python/mcdisplay/webgl/npminstall.bat.in +++ b/tools/Python/mcdisplay/webgl/npminstall.bat.in @@ -1,5 +1,22 @@ -@set PATH=c:\\@FLAVOR@-@VERSION@\\bin;c:\\@FLAVOR@-@VERSION@\\miniconda3;%PATH% -@cd %~dp0 +@REM Isn't windows a lovely place??? +@CALL @CPACK_NSIS_INSTALL_ROOT@\bin\@FLAVOR@env.bat +@set TOOLDIR=%~dp0 +@cd %USERPROFILE%\AppData +@if not exist "@FLAVOR@\" mkdir @FLAVOR@ +@cd @FLAVOR@ +@if not exist "@MCCODE_VERSION@\" mkdir @MCCODE_VERSION@ +@cd @MCCODE_VERSION@ +@if not exist "webgl\" mkdir webgl +@cd webgl +@copy /Y %TOOLDIR%\*.tsx . +@copy /Y %TOOLDIR%\*.css . +@copy /Y %TOOLDIR%\index.html . +@copy /Y %TOOLDIR%\*.js . +@copy /Y %TOOLDIR%\package.json . +@rsync -avz %TOOLDIR%\Contexts\ Contexts +@rsync -avz %TOOLDIR%\utils\ utils +@rsync -avz %TOOLDIR%\data-utils\ data-utils +@rsync -avz %TOOLDIR%\components\ components @call npm.cmd install @call npm.cmd run build From cc4d8df8b2e6a2497faefc1b7870d86c216fde61 Mon Sep 17 00:00:00 2001 From: Peter Willendrup Date: Thu, 15 Aug 2024 18:57:33 +0200 Subject: [PATCH 08/15] Include rsync --- meta-pkgs/windows/environment.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/meta-pkgs/windows/environment.yml b/meta-pkgs/windows/environment.yml index ef58f5168..ad37c335b 100644 --- a/meta-pkgs/windows/environment.yml +++ b/meta-pkgs/windows/environment.yml @@ -32,6 +32,7 @@ dependencies: - typish - jsons - nodejs + - rsync - pip - pip: - guide_bot From 10b03b91324966a016876e20db2f5afbb0b026e8 Mon Sep 17 00:00:00 2001 From: Peter Willendrup Date: Thu, 15 Aug 2024 18:58:22 +0200 Subject: [PATCH 09/15] Add rsync --- tools/Python/mcdisplay/webgl/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/Python/mcdisplay/webgl/CMakeLists.txt b/tools/Python/mcdisplay/webgl/CMakeLists.txt index 056d53f17..0ad276bbf 100644 --- a/tools/Python/mcdisplay/webgl/CMakeLists.txt +++ b/tools/Python/mcdisplay/webgl/CMakeLists.txt @@ -51,7 +51,7 @@ set(CPACK_NSIS_DISPLAY_NAME "${NSIS_NAME}") set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${NSIS_NAME}") # Debian -set(CPACK_DEBIAN_PACKAGE_DEPENDS "${FLAVOR}-${MCCODE_VERSION}, python3, python3-ply, python3-numpy, nodejs") +set(CPACK_DEBIAN_PACKAGE_DEPENDS "${FLAVOR}-${MCCODE_VERSION}, python3, python3-ply, python3-numpy, nodejs, rsync") # RPM if (RPMPROFILE) From ea6b909035e80cdbbfa33c1bdba0f6a1a4437138 Mon Sep 17 00:00:00 2001 From: Peter Willendrup Date: Thu, 15 Aug 2024 19:47:36 +0200 Subject: [PATCH 10/15] No rsync on Windows --- meta-pkgs/windows/environment.yml | 1 - tools/Python/mcdisplay/webgl/npminstall.bat.in | 8 ++++---- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/meta-pkgs/windows/environment.yml b/meta-pkgs/windows/environment.yml index ad37c335b..ef58f5168 100644 --- a/meta-pkgs/windows/environment.yml +++ b/meta-pkgs/windows/environment.yml @@ -32,7 +32,6 @@ dependencies: - typish - jsons - nodejs - - rsync - pip - pip: - guide_bot diff --git a/tools/Python/mcdisplay/webgl/npminstall.bat.in b/tools/Python/mcdisplay/webgl/npminstall.bat.in index 3ed91b6c6..ae6f340e7 100644 --- a/tools/Python/mcdisplay/webgl/npminstall.bat.in +++ b/tools/Python/mcdisplay/webgl/npminstall.bat.in @@ -13,10 +13,10 @@ @copy /Y %TOOLDIR%\index.html . @copy /Y %TOOLDIR%\*.js . @copy /Y %TOOLDIR%\package.json . -@rsync -avz %TOOLDIR%\Contexts\ Contexts -@rsync -avz %TOOLDIR%\utils\ utils -@rsync -avz %TOOLDIR%\data-utils\ data-utils -@rsync -avz %TOOLDIR%\components\ components +@Xcopy %TOOLDIR%\Contexts\ Contexts /c /i /e /h /y +@xcopy %TOOLDIR%\utils\ utils /c /i /e /h /y +@xcopy %TOOLDIR%\data-utils\ data-utils /c /i /e /h /y +@xcopy %TOOLDIR%\components\ components /c /i /e /h /y @call npm.cmd install @call npm.cmd run build From e1d6c75090e2dc4b1af26a5e61282124fb129706 Mon Sep 17 00:00:00 2001 From: Peter Willendrup Date: Fri, 16 Aug 2024 06:09:54 +0200 Subject: [PATCH 11/15] Further updated integration of npm stuff on Windows --- meta-pkgs/windows/docupdate.bat.in | 3 +-- tools/Python/mcdisplay/webgl/npminstall.bat.in | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/meta-pkgs/windows/docupdate.bat.in b/meta-pkgs/windows/docupdate.bat.in index e00c57fa0..c463ffd77 100644 --- a/meta-pkgs/windows/docupdate.bat.in +++ b/meta-pkgs/windows/docupdate.bat.in @@ -2,5 +2,4 @@ @REM Script for calling mcdoc -i after installation of McStas/McXtrace @set PATH=c:\\@FLAVOR@-@VERSION@\\bin;c:\\@FLAVOR@-@VERSION@\\miniconda3;%PATH% @call @P@doc.bat -i -@cd c:\\@FLAVOR@-@VERSION@\\lib\\tools\\Python\\@P@display\\webgl -@npm.cmd install + diff --git a/tools/Python/mcdisplay/webgl/npminstall.bat.in b/tools/Python/mcdisplay/webgl/npminstall.bat.in index ae6f340e7..ebf6f3b9f 100644 --- a/tools/Python/mcdisplay/webgl/npminstall.bat.in +++ b/tools/Python/mcdisplay/webgl/npminstall.bat.in @@ -1,5 +1,4 @@ @REM Isn't windows a lovely place??? -@CALL @CPACK_NSIS_INSTALL_ROOT@\bin\@FLAVOR@env.bat @set TOOLDIR=%~dp0 @cd %USERPROFILE%\AppData @if not exist "@FLAVOR@\" mkdir @FLAVOR@ From 0cf9d97fb4f5a372a5980ba0558693b8d31ca9c0 Mon Sep 17 00:00:00 2001 From: Peter Willendrup Date: Fri, 16 Aug 2024 11:03:35 +0200 Subject: [PATCH 12/15] Further stability improvements on windows --- tools/Python/mcdisplay/webgl/mcdisplay.py | 17 +++++++++++++---- tools/Python/mcdisplay/webgl/npminstall.bat.in | 2 ++ 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/tools/Python/mcdisplay/webgl/mcdisplay.py b/tools/Python/mcdisplay/webgl/mcdisplay.py index a86d226f9..7ea68ab97 100755 --- a/tools/Python/mcdisplay/webgl/mcdisplay.py +++ b/tools/Python/mcdisplay/webgl/mcdisplay.py @@ -98,7 +98,7 @@ def _write_html(instrument, html_filepath, first=None, last=None, invcanvas=Fals def write_browse(instrument, raybundle, dirname, instrname, timeout, nobrowse=None, first=None, last=None, invcanvas=None, **kwds): ''' writes instrument definitions to html/ js ''' - print("Launching WebGL... - timeout is " + str(timeout)) + print("Launching WebGL... Once launched, server will run for " + str(timeout) + " s") def copy(a, b): shutil_copy(str(a), str(b)) @@ -218,14 +218,23 @@ def main(instr=None, dirname=None, debug=None, n=None, timeout=None, **kwds): # Function to run npm commands and capture port def run_npminstall(): + toolpath=str(Path(__file__).absolute().parent) + print(toolpath) if not os.name == 'nt': - npminst = "npminstall" + npminst = Path(toolpath + "/npminstall") else: - npminst = "npminstall.bat" - npminst = Path(__file__).absolute().parent.joinpath(npminst) + npminst = Path(toolpath + "/npminstall.bat") + + print("Executing " + str(npminst)) try: proc = subprocess.Popen(npminst, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) print("Installing npm / vite modules") + for line in proc.stdout: + print(line.rstrip()) + print("Installing npm / vite modules - stderr:") + for line in proc.stderr: + print(line.rstrip()) + print("Done installing npm / vite modules") except subprocess.CalledProcessError as e: print(f"npminstall failed: {e}") return None diff --git a/tools/Python/mcdisplay/webgl/npminstall.bat.in b/tools/Python/mcdisplay/webgl/npminstall.bat.in index ebf6f3b9f..2b5ce5356 100644 --- a/tools/Python/mcdisplay/webgl/npminstall.bat.in +++ b/tools/Python/mcdisplay/webgl/npminstall.bat.in @@ -1,4 +1,5 @@ @REM Isn't windows a lovely place??? +@set WORKDIR=%cd% @set TOOLDIR=%~dp0 @cd %USERPROFILE%\AppData @if not exist "@FLAVOR@\" mkdir @FLAVOR@ @@ -18,4 +19,5 @@ @xcopy %TOOLDIR%\components\ components /c /i /e /h /y @call npm.cmd install @call npm.cmd run build +@cd %WORKDIR%\ From 5789d32f4daa1f4f9fd4e534523d73f6c6f80c72 Mon Sep 17 00:00:00 2001 From: Peter Willendrup Date: Fri, 16 Aug 2024 11:18:21 +0200 Subject: [PATCH 13/15] Avoid copytree --- tools/Python/mcdisplay/webgl/mcdisplay.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/Python/mcdisplay/webgl/mcdisplay.py b/tools/Python/mcdisplay/webgl/mcdisplay.py index 7ea68ab97..089e27e1d 100755 --- a/tools/Python/mcdisplay/webgl/mcdisplay.py +++ b/tools/Python/mcdisplay/webgl/mcdisplay.py @@ -112,7 +112,10 @@ def copy(a, b): raise RuntimeError(f"The specified destination {dirname} already exists!") # Copy the app files - i.e. creating dest - copytree(source.joinpath('dist'), dest) + if not os.name=='nt': + os.symlink(source.joinpath('dist'), dest) + else: + _winapi.CreateJunction(str(source.joinpath('dist')), str(dest)) # Copy package.json from source to dest package_json_source = source.joinpath('package.json') @@ -122,13 +125,10 @@ def copy(a, b): # Copy node_modules from source to destination node_modules_source = source.joinpath('node_modules') node_modules_dest = dest.joinpath('node_modules') - try: - if not os.name=='nt': - os.symlink(node_modules_source, node_modules_dest) - else: - _winapi.CreateJunction(node_modules_source, node_modules_dest) - except: - copytree(node_modules_source, node_modules_dest, dirs_exist_ok=True, ignore=ignore_patterns('*.log', '*.cache')) + if not os.name=='nt': + os.symlink(node_modules_source, node_modules_dest) + else: + _winapi.CreateJunction(str(node_modules_source), str(node_modules_dest)) # Ensure execute permissions for vite binary vite_bin = node_modules_dest.joinpath('.bin/vite') From 5a02f879f62cd86a3367d73e298a7a4b0fb33e5c Mon Sep 17 00:00:00 2001 From: Peter Willendrup Date: Fri, 16 Aug 2024 11:22:48 +0200 Subject: [PATCH 14/15] Different wording for Unix and Windows --- tools/Python/mcdisplay/webgl/mcdisplay.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/tools/Python/mcdisplay/webgl/mcdisplay.py b/tools/Python/mcdisplay/webgl/mcdisplay.py index 089e27e1d..e3a26f275 100755 --- a/tools/Python/mcdisplay/webgl/mcdisplay.py +++ b/tools/Python/mcdisplay/webgl/mcdisplay.py @@ -202,11 +202,16 @@ def signal_handler(sig, frame): signal.signal(signal.SIGINT, signal_handler) signal.signal(signal.SIGUSR1, signal_handler) signal.signal(signal.SIGUSR2, signal_handler) - print('Press Ctrl+C to exit - otherwise visualisation vill terminate server after ' + str(timeout) + ' s') - time.sleep(timeout) - print("Sending SIGTERM to npm/vite server") - port_container['process'].send_signal(signal.SIGTERM) - sys.exit(0) + if not os.name == 'nt': + print('Press Ctrl+C to exit\n(visualisation server willterminate server after ' + str(timeout) + ' s)') + time.sleep(timeout) + print("Sending SIGTERM to npm/vite server") + port_container['process'].send_signal(signal.SIGTERM) + sys.exit(0) + else: + print('Press Ctrl+C to exit visualisation server') + port_container['process'].wait() + sys.exit(0) def file_save(data, filename): ''' saves data for debug purposes ''' From a3fb7e35195bc7c720def7a4ad3a29207795682b Mon Sep 17 00:00:00 2001 From: Peter Willendrup Date: Fri, 16 Aug 2024 11:54:47 +0200 Subject: [PATCH 15/15] Back to copytree for dist -> dest --- tools/Python/mcdisplay/webgl/mcdisplay.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tools/Python/mcdisplay/webgl/mcdisplay.py b/tools/Python/mcdisplay/webgl/mcdisplay.py index e3a26f275..15635d7fa 100755 --- a/tools/Python/mcdisplay/webgl/mcdisplay.py +++ b/tools/Python/mcdisplay/webgl/mcdisplay.py @@ -112,10 +112,7 @@ def copy(a, b): raise RuntimeError(f"The specified destination {dirname} already exists!") # Copy the app files - i.e. creating dest - if not os.name=='nt': - os.symlink(source.joinpath('dist'), dest) - else: - _winapi.CreateJunction(str(source.joinpath('dist')), str(dest)) + copytree(source.joinpath('dist'), dest) # Copy package.json from source to dest package_json_source = source.joinpath('package.json')