diff --git a/server/bin/dependencies b/server/bin/dependencies index 0265656cf..9aff158bc 100644 --- a/server/bin/dependencies +++ b/server/bin/dependencies @@ -1,22 +1,28 @@ #!/usr/bin/env node const child_process = require('child_process'); -const python = require('@bjia56/portable-python-3.9'); +const { PortablePython } = require('@bjia56/portable-python') const { once } = require('events'); +let python; async function pipInstall(pkg) { - const cp = child_process.spawn(python, ['-m', 'pip', 'install', pkg], {stdio: 'inherit'}); + const cp = child_process.spawn(python, ['-m', 'pip', 'install', pkg], { stdio: 'inherit' }); const [exitCode] = await once(cp, 'exit'); if (exitCode) throw new Error('non-zero exit code: ' + exitCode); } async function installScryptedServerRequirements() { + const py = new PortablePython("3.9"); + await py.install(); + python = py.executablePath; + await pipInstall('wheel'); await pipInstall('debugpy'); await pipInstall('psutil'); await pipInstall('prompt_toolkit'); await pipInstall('ptpython'); + console.log('DONEZO', python) } installScryptedServerRequirements(); diff --git a/server/package-lock.json b/server/package-lock.json index 93aa6c1aa..c76df684e 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -1,15 +1,15 @@ { "name": "@scrypted/server", - "version": "0.94.16", + "version": "0.94.17", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@scrypted/server", - "version": "0.94.16", + "version": "0.94.17", "license": "ISC", "dependencies": { - "@bjia56/portable-python-3.9": "^0.1.10", + "@bjia56/portable-python": "^0.1.3", "@mapbox/node-pre-gyp": "^1.0.11", "@scrypted/types": "^0.3.13", "adm-zip": "^0.5.10", @@ -60,11 +60,13 @@ "@homebridge/node-pty-prebuilt-multiarch": "^0.11.12" } }, - "node_modules/@bjia56/portable-python-3.9": { - "version": "0.1.10", - "resolved": "https://registry.npmjs.org/@bjia56/portable-python-3.9/-/portable-python-3.9-0.1.10.tgz", - "integrity": "sha512-Ml/SqIy/EF3PIH69Ftat70ujyV8uj65fr4gAPWdLkt0wpHZCrgsNREgSpLJohc87FisfEwdkEMKNF5VSX3tN2A==", - "hasInstallScript": true + "node_modules/@bjia56/portable-python": { + "version": "0.1.3", + "resolved": "https://registry.npmjs.org/@bjia56/portable-python/-/portable-python-0.1.3.tgz", + "integrity": "sha512-LCevOAfR3EcpHxhn2HmJPYMKwlx6gFak1L5yT+HDZTpCZCJso5Fs55z04dZ3XHJGOP/nYSwcpVmcdPArJzfeFQ==", + "dependencies": { + "adm-zip": "^0.5.10" + } }, "node_modules/@derhuerst/http-basic": { "version": "8.2.4", diff --git a/server/package.json b/server/package.json index 3994c94a3..582b31ccf 100644 --- a/server/package.json +++ b/server/package.json @@ -1,9 +1,9 @@ { "name": "@scrypted/server", - "version": "0.94.17", + "version": "0.94.18", "description": "", "dependencies": { - "@bjia56/portable-python-3.9": "^0.1.10", + "@bjia56/portable-python": "^0.1.3", "@mapbox/node-pre-gyp": "^1.0.11", "@scrypted/types": "^0.3.13", "adm-zip": "^0.5.10", @@ -56,7 +56,6 @@ "main": "dist/scrypted-main-exports.js", "types": "dist/scrypted-main-exports.d.ts", "scripts": { - "dependencies": "node bin/dependencies", "preserve": "npm run build", "serve": "node --expose-gc dist/scrypted-main.js", "serve-no-build": "node --expose-gc dist/scrypted-main.js", diff --git a/server/src/plugin/runtime/python-worker.ts b/server/src/plugin/runtime/python-worker.ts index c0b600804..c5f2628fd 100644 --- a/server/src/plugin/runtime/python-worker.ts +++ b/server/src/plugin/runtime/python-worker.ts @@ -7,13 +7,15 @@ import { RpcMessage, RpcPeer } from "../../rpc"; import { createRpcDuplexSerializer } from '../../rpc-serializer'; import { ChildProcessWorker } from "./child-process-worker"; import { RuntimeWorkerOptions } from "./runtime-worker"; -import { getPluginVolume } from '../plugin-volume'; +import type {PortablePython as PortablePythonType} from '@bjia56/portable-python' export class PythonRuntimeWorker extends ChildProcessWorker { static { try { - const portablePython = require('@bjia56/portable-python-3.9') as string; - if (portablePython && typeof portablePython === 'string') + const PortablePython = require('@bjia56/portable-python').PortablePython as typeof PortablePythonType; + const py = new PortablePython("3.9"); + const portablePython = py.executablePath; + if (fs.existsSync(portablePython)) process.env.SCRYPTED_PYTHON_PATH = portablePython; } catch (e) { @@ -87,7 +89,7 @@ export class PythonRuntimeWorker extends ChildProcessWorker { stdio: ['pipe', 'pipe', 'pipe', 'pipe', 'pipe'], env: Object.assign({ // rev this if the base python version or server characterstics change. - SCRYPTED_PYTHON_VERSION: '20240308', + SCRYPTED_PYTHON_VERSION: '20240308.1', PYTHONUNBUFFERED: '1', PYTHONPATH, }, gstEnv, process.env, env),