From 4f2ad2a81bfaa7464f2080145f0447056da94766 Mon Sep 17 00:00:00 2001 From: ali asaria <ali.asaria@gmail.com> Date: Thu, 7 Mar 2024 15:27:39 -0500 Subject: [PATCH] Update app to use hard-coded conda in ~/miniconda3 only --- src/main/main.ts | 7 ++--- src/main/util.ts | 29 +++++++++++-------- .../components/Connect/LocalConnection.tsx | 2 +- 3 files changed, 20 insertions(+), 18 deletions(-) diff --git a/src/main/main.ts b/src/main/main.ts index f15c7b78..3dd73fe8 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -26,6 +26,7 @@ import { checkIfShellCommandExists, checkIfCondaEnvironmentExists, checkDependencies, + checkIfCondaBinExists, } from './util'; // //////////// @@ -90,7 +91,7 @@ ipcMain.handle('server:install_install-dependencies', async (event) => { }); ipcMain.handle('server:checkIfCondaExists', async (event) => { - const r = checkIfShellCommandExists('conda'); + const r = checkIfCondaBinExists(); console.log('conda exists', r); return r; }); @@ -101,10 +102,6 @@ ipcMain.handle('server:checkIfCondaEnvironmentExists', async (event) => { return envList; }); -ipcMain.handle('server:checkIfUvicornExists', async (event) => { - return checkIfShellCommandExists('uvicorn'); -}); - ipcMain.handle('server:checkDependencies', async (event) => { return await checkDependencies(); }); diff --git a/src/main/util.ts b/src/main/util.ts index 08320840..371eff19 100644 --- a/src/main/util.ts +++ b/src/main/util.ts @@ -46,13 +46,11 @@ export function startLocalServer() { const options = { cwd: transformerLabDir, - // The following two options allow it to keep running after parent is closed - detached: true, stdio: ['ignore', out, err], shell: '/bin/bash', }; console.log('Starting local server at', mainFile); - localServer = spawn('bash', [mainFile], options); + localServer = spawn('bash', ['-l', mainFile], options); console.log('Local server started with pid', localServer.pid); @@ -140,16 +138,23 @@ export function checkIfShellCommandExists(command: string) { } } +export function checkIfCondaBinExists() { + // Look for the file ~/miniconda3/bin/conda + const condaBin = path.join(homeDir, 'miniconda3/bin/conda'); + if (fs.existsSync(condaBin)) { + return true; + } else { + return false; + } +} + export async function checkDependencies() { // First activate the transformerlab environment // Then run pip list // Then compare the output to the list of dependencies // If any are missing, return the missing ones // If all are present, manually check if the uvicorn command is present - const uvicornExists = checkIfShellCommandExists('uvicorn'); - - const command = - 'eval "$(conda shell.bash hook)" && conda activate transformerlab && pip list --format json'; + const command = '~/.transformerlab/src/install.sh list_installed_packages'; const options = { shell: '/bin/bash' }; const { stdout, stderr } = await awaitExec(command, options).catch((err) => { console.log('Error running pip list', err); @@ -187,11 +192,11 @@ export async function checkDependencies() { export async function checkIfCondaEnvironmentExists() { const options = { shell: '/bin/bash' }; console.log('Checking if Conda environment "transformerlab" exists'); - const { stdout, stderr } = await awaitExec(`conda env list`, options).catch( - (err) => { - console.log('Error running conda env list', err); - } - ); + const command = '~/.transformerlab/src/install.sh list_environments'; + + const { stdout, stderr } = await awaitExec(command, options).catch((err) => { + console.log('Error running conda env list', err); + }); if (stdout) console.log('stdout:', stdout); if (stderr) console.error('stderr:', stderr); diff --git a/src/renderer/components/Connect/LocalConnection.tsx b/src/renderer/components/Connect/LocalConnection.tsx index 999ba816..98991d20 100644 --- a/src/renderer/components/Connect/LocalConnection.tsx +++ b/src/renderer/components/Connect/LocalConnection.tsx @@ -745,7 +745,7 @@ function InstallStepper({ setServer }) { </InstallStep> <InstallStep thisStep={Steps.indexOf('CHECK_IF_CONDA_INSTALLED')} - title="Check if Conda is Installed" + title="Check if Conda is Installed at ~/miniconda3/" activeStep={activeStep} setActiveStep={setActiveStep} > -- GitLab