From 33567770218807323cae51e6e234a05c777c8a07 Mon Sep 17 00:00:00 2001 From: Koushik Dutta Date: Mon, 18 Mar 2024 10:04:47 -0700 Subject: [PATCH] server: use fixed python3.11. install custom pythons into module path. --- server/bin/packaged-python.js | 2 +- server/package-lock.json | 12 ++++++------ server/package.json | 2 +- server/src/plugin/runtime/python-worker.ts | 20 ++++++++++++++------ 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/server/bin/packaged-python.js b/server/bin/packaged-python.js index 7231d26fe..f17e3bc4d 100644 --- a/server/bin/packaged-python.js +++ b/server/bin/packaged-python.js @@ -3,7 +3,7 @@ const { PortablePython } = require('py') const { once } = require('events'); module.exports = { - version: '3.10', + version: '3.11', } async function pipInstall(python, pkg) { diff --git a/server/package-lock.json b/server/package-lock.json index a595df884..2018fe0b6 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -1,12 +1,12 @@ { "name": "@scrypted/server", - "version": "0.94.31", + "version": "0.94.32", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@scrypted/server", - "version": "0.94.31", + "version": "0.94.32", "hasInstallScript": true, "license": "ISC", "dependencies": { @@ -27,7 +27,7 @@ "node-dijkstra": "^2.5.0", "node-forge": "^1.3.1", "node-gyp": "^10.0.1", - "py": "npm:@bjia56/portable-python@^0.1.15", + "py": "npm:@bjia56/portable-python@^0.1.18", "router": "^1.3.8", "semver": "^7.6.0", "sharp": "^0.33.2", @@ -2876,9 +2876,9 @@ }, "node_modules/py": { "name": "@bjia56/portable-python", - "version": "0.1.15", - "resolved": "https://registry.npmjs.org/@bjia56/portable-python/-/portable-python-0.1.15.tgz", - "integrity": "sha512-yJ3cwIfSkgy5S8VfleDjJY1a1fPAgwaeqP4sxUArGVnzyYNtmYu0HxSR3iL7XGm4EUE22l3vPbmHxAdr/JBiaw==", + "version": "0.1.18", + "resolved": "https://registry.npmjs.org/@bjia56/portable-python/-/portable-python-0.1.18.tgz", + "integrity": "sha512-ch92UNVHI7rA6xN5iFNHagr0sjYjJp+GfN+haVV7wYOmfjUKRkk1GBx4Z7pfZjSL/gVPWcOloWtV/aCn83Ds4w==", "dependencies": { "adm-zip": "^0.5.10" } diff --git a/server/package.json b/server/package.json index 1209df8f9..69d3191da 100644 --- a/server/package.json +++ b/server/package.json @@ -20,7 +20,7 @@ "node-dijkstra": "^2.5.0", "node-forge": "^1.3.1", "node-gyp": "^10.0.1", - "py": "npm:@bjia56/portable-python@^0.1.15", + "py": "npm:@bjia56/portable-python@^0.1.18", "router": "^1.3.8", "semver": "^7.6.0", "sharp": "^0.33.2", diff --git a/server/src/plugin/runtime/python-worker.ts b/server/src/plugin/runtime/python-worker.ts index e32dd0c2c..789a87b14 100644 --- a/server/src/plugin/runtime/python-worker.ts +++ b/server/src/plugin/runtime/python-worker.ts @@ -23,6 +23,8 @@ export class PythonRuntimeWorker extends ChildProcessWorker { } } + static pythonInstalls = new Map>(); + serializer: ReturnType; peerin: Writable; peerout: Readable; @@ -126,18 +128,24 @@ export class PythonRuntimeWorker extends ChildProcessWorker { (this.worker.stdio[4] as Readable).pipe(peerout); }; - const py = new PortablePython(pluginPythonVersion, path.dirname(options.unzippedPath)); + const py = new PortablePython(pluginPythonVersion); if (fs.existsSync(py.executablePath)) { pythonPath = py.executablePath; finishSetup(); } else { this.pythonInstallationComplete = false; - installScryptedServerRequirements(pluginPythonVersion, path.dirname(options.unzippedPath)) - .then(executablePath => { - pythonPath = executablePath; - finishSetup(); - }) + let install = PythonRuntimeWorker.pythonInstalls.get(pluginPythonVersion); + if (!install) { + install = installScryptedServerRequirements(pluginPythonVersion); + install.catch(() => { }); + PythonRuntimeWorker.pythonInstalls.set(pluginPythonVersion, install); + } + + install.then(executablePath => { + pythonPath = executablePath; + finishSetup(); + }) .catch(() => { process.nextTick(() => { this.emit('error', new Error('Failed to install portable python.'));