Skip to content

Commit

Permalink
no longer need to find/use jupyterExe variable
Browse files Browse the repository at this point in the history
  • Loading branch information
emlys committed Oct 17, 2024
1 parent 2431ae9 commit b5394c5
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 22 deletions.
5 changes: 2 additions & 3 deletions workbench/src/main/createPythonFlaskProcess.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down
13 changes: 2 additions & 11 deletions workbench/src/main/findBinaries.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.');
Expand All @@ -57,10 +49,9 @@ export function findInvestBinaries(isDevMode) {
ipcMain.handle(
ipcMainChannels.INVEST_VERSION, () => investVersion
);
return [investExe, jupyterExe];
return investExe;
}


/**
* Return the available mamba executable.
*
Expand Down
6 changes: 3 additions & 3 deletions workbench/src/main/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'));
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion workbench/src/main/menubar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down
7 changes: 3 additions & 4 deletions workbench/src/main/setupJupyter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down

0 comments on commit b5394c5

Please sign in to comment.