diff --git a/server/bin/packaged-python.d.ts b/server/bin/packaged-python.d.ts index 9c3b13fa1..78fcd05ef 100644 --- a/server/bin/packaged-python.d.ts +++ b/server/bin/packaged-python.d.ts @@ -1,2 +1,2 @@ export declare declare const version: string; -export declare async function installScryptedServerRequirements(version?: string, dest?: string); +export declare async function installScryptedServerRequirements(version?: string, dest?: string): Promise; diff --git a/server/bin/packaged-python.js b/server/bin/packaged-python.js index e58c92034..f17e3bc4d 100644 --- a/server/bin/packaged-python.js +++ b/server/bin/packaged-python.js @@ -20,4 +20,5 @@ module.exports.installScryptedServerRequirements = async function installScrypte await pipInstall(python, 'debugpy'); await pipInstall(python, 'psutil').catch(() => { }); + return python; } diff --git a/server/package-lock.json b/server/package-lock.json index 93b83c02f..f12c7ae2b 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/server", - "version": "0.94.29", + "version": "0.94.30", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@scrypted/server", - "version": "0.94.29", + "version": "0.94.30", "hasInstallScript": true, "license": "ISC", "dependencies": { diff --git a/server/src/plugin/runtime/python-worker.ts b/server/src/plugin/runtime/python-worker.ts index 9d8ffeea6..c96054e80 100644 --- a/server/src/plugin/runtime/python-worker.ts +++ b/server/src/plugin/runtime/python-worker.ts @@ -4,7 +4,7 @@ import os from "os"; import path from 'path'; import { PortablePython } from 'py'; import { Readable, Writable, PassThrough } from 'stream'; -import { version as packagedPythonVersion } from '../../../bin/packaged-python'; +import { installScryptedServerRequirements, version as packagedPythonVersion } from '../../../bin/packaged-python'; import { RpcMessage, RpcPeer } from "../../rpc"; import { createRpcDuplexSerializer } from '../../rpc-serializer'; import { ChildProcessWorker } from "./child-process-worker"; @@ -119,25 +119,32 @@ export class PythonRuntimeWorker extends ChildProcessWorker { const peerin = this.peerin = new PassThrough(); const peerout = this.peerout = new PassThrough(); - const py = new PortablePython(pluginPythonVersion, path.dirname(options.unzippedPath)); - this.pythonInstallationComplete = false; - py.install() - .then(() => { - pythonPath = py.executablePath; - // is this possible? - if (!fs.existsSync(pythonPath)) - throw new Error('Installation failed. Portable python not found.'); - setup(); + const finishSetup = () => { + setup(); - peerin.pipe(this.worker.stdio[3] as Writable); - (this.worker.stdio[4] as Readable).pipe(peerout); - }) - .catch(() => { - process.nextTick(() => { - this.emit('error', new Error('Failed to install portable python.')); + peerin.pipe(this.worker.stdio[3] as Writable); + (this.worker.stdio[4] as Readable).pipe(peerout); + }; + + const py = new PortablePython(pluginPythonVersion, path.dirname(options.unzippedPath)); + if (fs.existsSync(py.executablePath)) { + pythonPath = py.executablePath; + finishSetup(); + } + else { + this.pythonInstallationComplete = false; + installScryptedServerRequirements(pluginPythonVersion, path.dirname(options.unzippedPath)) + .then(executablePath => { + pythonPath = executablePath; + finishSetup(); }) - }) - .finally(() => this.pythonInstallationComplete = true); + .catch(() => { + process.nextTick(() => { + this.emit('error', new Error('Failed to install portable python.')); + }) + }) + .finally(() => this.pythonInstallationComplete = true); + } } else { setup();