diff --git a/server/package-lock.json b/server/package-lock.json index 3d3244a5f..1cd9cce12 100644 --- a/server/package-lock.json +++ b/server/package-lock.json @@ -7,6 +7,7 @@ "": { "name": "@scrypted/server", "version": "0.94.10", + "hasInstallScript": true, "license": "ISC", "dependencies": { "@bjia56/portable-python-3.9": "^0.1.9", diff --git a/server/package.json b/server/package.json index 9744b03cf..6a9bffc12 100644 --- a/server/package.json +++ b/server/package.json @@ -56,6 +56,7 @@ "main": "dist/scrypted-main-exports.js", "types": "dist/scrypted-main-exports.d.ts", "scripts": { + "postinstall": "node scripts/postinstall.js", "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/python/plugin_remote.py b/server/python/plugin_remote.py index f4b375d76..e287dc94b 100644 --- a/server/python/plugin_remote.py +++ b/server/python/plugin_remote.py @@ -37,16 +37,6 @@ import multiprocessing.connection import rpc import rpc_reader - -SCRYPTED_REQUIREMENTS = """ -ptpython -wheel -""".strip() - -SCRYPTED_DEBUGPY_REQUIREMENTS = """ -debugpy -""".strip() - class ClusterObject(TypedDict): id: str port: int @@ -593,19 +583,11 @@ class PluginRemote: need_pip = True if str_requirements: need_pip = need_requirements(requirements_basename, str_requirements) - if not need_pip: - need_pip = need_requirements(scrypted_requirements_basename, SCRYPTED_REQUIREMENTS) - python_debugpy_target = os.environ['SCRYPTED_DEBUGPY_TARGET'] - if not need_pip and python_debugpy_target: - need_pip = need_requirements(debug_requirements_basename, SCRYPTED_DEBUGPY_REQUIREMENTS) if need_pip: remove_pip_dirs(plugin_volume) - install_with_pip(pip_target, packageJson, SCRYPTED_REQUIREMENTS, scrypted_requirements_basename, ignore_error=True) install_with_pip(pip_target, packageJson, str_requirements, requirements_basename, ignore_error=False) install_with_pip(pip_target, packageJson, str_optional_requirements, optional_requirements_basename, ignore_error=True) - if python_debugpy_target: - install_with_pip(python_debugpy_target, packageJson, SCRYPTED_DEBUGPY_REQUIREMENTS, debug_requirements_basename, ignore_error=True) else: print('requirements.txt (up to date)') print(str_requirements) diff --git a/server/scripts/postinstall.js b/server/scripts/postinstall.js new file mode 100644 index 000000000..343a5f1c0 --- /dev/null +++ b/server/scripts/postinstall.js @@ -0,0 +1,19 @@ +const child_process = require('child_process'); +const python = require('@bjia56/portable-python-3.9'); +const { once } = require('events'); + +async function pipInstall(pkg) { + 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() { + await pipInstall('wheel'); + await pipInstall('debugpy'); + await pipInstall('psutil'); + await pipInstall('ptpython'); +} + +installScryptedServerRequirements(); diff --git a/server/src/plugin/runtime/python-worker.ts b/server/src/plugin/runtime/python-worker.ts index 1b69bead0..e37c3ad99 100644 --- a/server/src/plugin/runtime/python-worker.ts +++ b/server/src/plugin/runtime/python-worker.ts @@ -81,11 +81,7 @@ export class PythonRuntimeWorker extends ChildProcessWorker { args.push(this.pluginId); const types = require.resolve('@scrypted/types'); - const SCRYPTED_DEBUGPY_TARGET = path.join(getPluginVolume(pluginId), 'python-debugpy'); - const PYTHONPATH = [ - types.substring(0, types.indexOf('types') + 'types'.length), - SCRYPTED_DEBUGPY_TARGET - ].join(':'); + const PYTHONPATH = types.substring(0, types.indexOf('types') + 'types'.length); this.worker = child_process.spawn(pythonPath, args, { // stdin, stdout, stderr, peer in, peer out stdio: ['pipe', 'pipe', 'pipe', 'pipe', 'pipe'], @@ -94,7 +90,6 @@ export class PythonRuntimeWorker extends ChildProcessWorker { SCRYPTED_BASE_VERSION: '20240308', PYTHONUNBUFFERED: '1', PYTHONPATH, - SCRYPTED_DEBUGPY_TARGET, }, gstEnv, process.env, env), });