From b5394c5f2ff074e01c5eadab8dbf26f07aa947de Mon Sep 17 00:00:00 2001 From: Emily Soth Date: Thu, 17 Oct 2024 16:22:40 -0700 Subject: [PATCH] no longer need to find/use jupyterExe variable --- workbench/src/main/createPythonFlaskProcess.js | 5 ++--- workbench/src/main/findBinaries.js | 13 ++----------- workbench/src/main/main.js | 6 +++--- workbench/src/main/menubar.js | 2 +- workbench/src/main/setupJupyter.js | 7 +++---- 5 files changed, 11 insertions(+), 22 deletions(-) diff --git a/workbench/src/main/createPythonFlaskProcess.js b/workbench/src/main/createPythonFlaskProcess.js index 2f5a0b3ca2..99b6c68d11 100644 --- a/workbench/src/main/createPythonFlaskProcess.js +++ b/workbench/src/main/createPythonFlaskProcess.js @@ -81,14 +81,13 @@ export function setupServerProcessHandlers(subprocess) { pidToSubprocess[subprocess.pid] = subprocess; } -export async function createJupyterProcess(jupyterExe, notebookDir, _port = undefined) { +export async function createJupyterProcess(notebookDir, _port = undefined) { let port = _port; if (port === undefined) { port = await getFreePort(); logger.debug(`PORT ${port}`); } - logger.debug('creating jupyterlab server process'); - logger.debug(jupyterExe); + logger.debug('creating voila server process'); const mamba = settingsStore.get('mamba'); const modelEnvPath = settingsStore.get('plugins.schistosomiasis.env'); diff --git a/workbench/src/main/findBinaries.js b/workbench/src/main/findBinaries.js index 7da42ff11f..2f97755ac9 100644 --- a/workbench/src/main/findBinaries.js +++ b/workbench/src/main/findBinaries.js @@ -19,31 +19,23 @@ const logger = getLogger(__filename.split('/').slice(-1)[0]); export function findInvestBinaries(isDevMode) { // Binding to the invest server binary: let investExe; - let jupyterExe; const ext = (process.platform === 'win32') ? '.exe' : ''; const investFilename = `invest${ext}`; - //const jupyterFilename = `jupyter${ext}`; - const jupyterFilename = `voila${ext}`; if (isDevMode) { investExe = investFilename; // assume an active python env w/ exe on path - jupyterExe = jupyterFilename; } else { investExe = upath.join(process.resourcesPath, 'invest', investFilename); - jupyterExe = upath.join(process.resourcesPath, 'invest', jupyterFilename); // It's likely the exe path includes spaces because it's composed of // app's Product Name, a user-facing name given to electron-builder. // Quoting depends on the shell, ('/bin/sh' or 'cmd.exe') and type of // child process. Use `spawn`` because that is how we will launch other // invest commands later. https://github.com/nodejs/node/issues/38490 investExe = `"${investExe}"`; - jupyterExe = `"${jupyterExe}"`; } // Checking that we have a functional invest exe by getting version // shell is necessary in dev mode when relying on an active conda env - const { stdout, stderr, error } = spawnSync( - investExe, ['--version'], { shell: true } - ); + const { stdout, stderr, error } = spawnSync(investExe, ['--version'], { shell: true }); if (error) { logger.error(stderr.toString()); logger.error('InVEST binaries are probably missing.'); @@ -57,10 +49,9 @@ export function findInvestBinaries(isDevMode) { ipcMain.handle( ipcMainChannels.INVEST_VERSION, () => investVersion ); - return [investExe, jupyterExe]; + return investExe; } - /** * Return the available mamba executable. * diff --git a/workbench/src/main/main.js b/workbench/src/main/main.js index cd011aee03..a293caa1b3 100644 --- a/workbench/src/main/main.js +++ b/workbench/src/main/main.js @@ -81,7 +81,7 @@ export const createWindow = async () => { }); splashScreen.loadURL(path.join(BASE_URL, 'splash.html')); - const [investExe, jupyterExe] = findInvestBinaries(ELECTRON_DEV_MODE); + const investExe = findInvestBinaries(ELECTRON_DEV_MODE); settingsStore.set('investExe', investExe); settingsStore.set('mamba', findMambaExecutable(ELECTRON_DEV_MODE)); // No plugin server processes should persist between workbench sessions @@ -120,7 +120,7 @@ export const createWindow = async () => { }); Menu.setApplicationMenu( Menu.buildFromTemplate( - menuTemplate(mainWindow, ELECTRON_DEV_MODE, i18n, jupyterExe) + menuTemplate(mainWindow, ELECTRON_DEV_MODE, i18n) ) ); mainWindow.loadURL(path.join(BASE_URL, 'index.html')); @@ -158,7 +158,7 @@ export const createWindow = async () => { // have callbacks that won't work until the invest server is ready. setupContextMenu(mainWindow); setupDownloadHandlers(mainWindow); - setupJupyter(mainWindow, ELECTRON_DEV_MODE, jupyterExe) + setupJupyter(mainWindow, ELECTRON_DEV_MODE); setupInvestRunHandlers(); setupLaunchPluginServerHandler(); setupOpenLocalHtml(mainWindow, ELECTRON_DEV_MODE); diff --git a/workbench/src/main/menubar.js b/workbench/src/main/menubar.js index 8455121d22..872e51cfe3 100644 --- a/workbench/src/main/menubar.js +++ b/workbench/src/main/menubar.js @@ -10,7 +10,7 @@ const logger = getLogger(__filename.split('/').slice(-1)[0]); const isMac = process.platform === 'darwin'; -export default function menuTemplate(parentWindow, isDevMode, i18n, jupyterExe) { +export default function menuTemplate(parentWindow, isDevMode, i18n) { // Much of this template comes straight from the docs // https://www.electronjs.org/docs/api/menu const template = [ diff --git a/workbench/src/main/setupJupyter.js b/workbench/src/main/setupJupyter.js index c3fd105d64..b36c97eb5a 100644 --- a/workbench/src/main/setupJupyter.js +++ b/workbench/src/main/setupJupyter.js @@ -44,17 +44,16 @@ function serveWorkspace(dir) { return http.createServer(app).listen(8080); } -export default function setupJupyter(parentWindow, isDevMode, jupyterExe) { +export default function setupJupyter(parentWindow, isDevMode) { ipcMain.on( ipcMainChannels.OPEN_JUPYTER, async (event, filepath) => { const httpServer = serveWorkspace(path.dirname(filepath)); - let labDir = `${process.resourcesPath}/notebooks`; if (isDevMode) { labDir = 'resources/notebooks'; } - const [subprocess, port] = await createJupyterProcess(jupyterExe, labDir); + const [subprocess, port] = await createJupyterProcess(labDir); const child = createWindow(parentWindow, isDevMode); child.loadURL(`http://localhost:${port}/?token=${process.env.JUPYTER_TOKEN}`); - child.on('close', async (event) => { + child.on('close', async () => { await shutdownPythonProcess(subprocess.pid); httpServer.close(); });