diff --git a/src/main/util.ts b/src/main/util.ts index 6d1c00964de27b22c8d0b2ddcba6712c2cd62e3e..1abafac94260e4f68fbdd075f39c597bffe96067 100644 --- a/src/main/util.ts +++ b/src/main/util.ts @@ -231,21 +231,29 @@ export async function checkIfCondaBinExists() { } 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 { error, stdout, stderr } = await executeInstallStep( - 'list_installed_packages' - ); - + // This function returns an API like response with status, message and data field let response = { status: '', message: '', data: [], }; + // check if we've done an install/update of dependencies with this build + // if not, report back that we need to do an install/update! + const installedDependenciesFile = path.join( + await getTransformerLabCodeDir(), + 'INSTALLED_DEPENDENCIES' + ); + if (!fs.existsSync(installedDependenciesFile)) { + response.status = 'error'; + response.message = 'Dependencies need to be installed for new API version.'; + return response; + } + + const { error, stdout, stderr } = await executeInstallStep( + 'list_installed_packages' + ); + // if there was an error abort processing if (error) { response.status = 'error'; @@ -289,10 +297,15 @@ export async function checkDependencies() { } } - console.log('missingDependencies', missingDependencies); - - response.status = 'success'; response.data = missingDependencies; + console.log('missingDependencies', missingDependencies); + if (missingDependencies.legnth > 0) { + response.status = 'error'; + const missingList = missingDependencies.data?.join(', '); + response.message = `Missing dependencies including: ${missingList}...`; + } else { + response.status = 'success'; + } return response; } diff --git a/src/renderer/components/Connect/LocalConnection.tsx b/src/renderer/components/Connect/LocalConnection.tsx index 3f3b8966fe195d8a5b7ba74aea349a05649367d7..8f4cbeb559ccc0d0792ceb0ab00c5784da5c202f 100644 --- a/src/renderer/components/Connect/LocalConnection.tsx +++ b/src/renderer/components/Connect/LocalConnection.tsx @@ -630,7 +630,6 @@ function CheckIfCondaEnvironmentExists({ activeStep, setActiveStep }) { function CheckDependencies({ activeStep, setActiveStep }) { const [installStatus, setInstallStatus] = useState(''); // notstarted, pending, success, error - const [missingDependencies, setMissingDependencies] = useState([]); const [errorMessage, setErrorMessage] = useState(null); useEffect(() => { @@ -638,27 +637,26 @@ function CheckDependencies({ activeStep, setActiveStep }) { return; (async () => { - const missingDependencies = await window.electron.ipcRenderer.invoke( + const ipcResponse = await window.electron.ipcRenderer.invoke( 'server:checkDependencies' ); if ( - missingDependencies?.status == 'success' && - missingDependencies?.data?.length == 0 + ipcResponse?.status == 'success' && + ipcResponse?.data?.length == 0 ) { setInstallStatus('success'); setActiveStep( Steps.indexOf('CHECK_IF_PYTHON_DEPENDENCIES_INSTALLED') + 1 ); } else { - setMissingDependencies(missingDependencies); setInstallStatus('notstarted'); } - if (missingDependencies?.status == 'error') { + if (ipcResponse?.status == 'error') { setErrorMessage({ - message: missingDependencies?.message, - data: missingDependencies?.data, + message: ipcResponse?.message, + data: ipcResponse?.data, }); } else { setErrorMessage(null); @@ -678,14 +676,6 @@ function CheckDependencies({ activeStep, setActiveStep }) { </Typography> </> )} - {missingDependencies.data?.length > 0 && installStatus == 'notstarted' && ( - <Typography level="body-sm" color="warning"> - Many dependencies are missing including:{' '} - <Typography level="body-sm" color="warning"> - {missingDependencies.data?.join(', ')} ... - </Typography> - </Typography> - )} {activeStep == Steps.indexOf('CHECK_IF_PYTHON_DEPENDENCIES_INSTALLED') && installStatus == 'notstarted' && ( @@ -696,22 +686,21 @@ function CheckDependencies({ activeStep, setActiveStep }) { startDecorator={<RotateCcwIcon size="16px" />} onClick={async () => { setInstallStatus('pending'); - const installDependencies = - await window.electron.ipcRenderer.invoke( - 'server:install_install-dependencies' - ); + setErrorMessage(null); + await window.electron.ipcRenderer.invoke( + 'server:install_install-dependencies' + ); - const missingDependencies = + const ipcResponse = await window.electron.ipcRenderer.invoke( 'server:checkDependencies' ); if ( - missingDependencies?.status == 'success' && - missingDependencies?.data?.length == 0 + ipcResponse?.status == 'success' && + ipcResponse?.data?.length == 0 ) { setInstallStatus('success'); - setErrorMessage(null); setActiveStep( Steps.indexOf('CHECK_IF_PYTHON_DEPENDENCIES_INSTALLED') + 1 @@ -719,10 +708,10 @@ function CheckDependencies({ activeStep, setActiveStep }) { return; } - if (missingDependencies?.status == 'error') { + if (ipcResponse?.status == 'error') { setErrorMessage({ - message: missingDependencies?.message, - data: missingDependencies?.data, + message: ipcResponse?.message, + data: ipcResponse?.data, }); } else { setErrorMessage(null);