From 0bc6fadb23820af66d43163ad54cd5302e08e30c Mon Sep 17 00:00:00 2001 From: Brett Jia Date: Tue, 13 Aug 2024 21:18:39 -0400 Subject: [PATCH] server: allow plugins to customize python installs (#1542) * server: allow plugins to customize python installs * move options inside pythonVersion --- server/bin/packaged-python.d.ts | 2 +- server/bin/packaged-python.js | 4 ++-- server/src/plugin/runtime/python-worker.ts | 6 ++++-- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/server/bin/packaged-python.d.ts b/server/bin/packaged-python.d.ts index 78fcd05ef..aaf487c15 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): Promise; +export declare async function installScryptedServerRequirements(version?: string, dest?: string, options?: any): Promise; diff --git a/server/bin/packaged-python.js b/server/bin/packaged-python.js index 7231d26fe..a7ee87601 100644 --- a/server/bin/packaged-python.js +++ b/server/bin/packaged-python.js @@ -13,8 +13,8 @@ async function pipInstall(python, pkg) { throw new Error('non-zero exit code: ' + exitCode); } -module.exports.installScryptedServerRequirements = async function installScryptedServerRequirements(version, dest) { - const py = new PortablePython(version || require('./packaged-python').version, dest); +module.exports.installScryptedServerRequirements = async function installScryptedServerRequirements(version, dest, options) { + const py = new PortablePython(version || require('./packaged-python').version, dest, options); await py.install(); let python = py.executablePath; diff --git a/server/src/plugin/runtime/python-worker.ts b/server/src/plugin/runtime/python-worker.ts index 507ebd9db..d74d30974 100644 --- a/server/src/plugin/runtime/python-worker.ts +++ b/server/src/plugin/runtime/python-worker.ts @@ -116,6 +116,8 @@ export class PythonRuntimeWorker extends ChildProcessWorker { if (process.env.SCRYPTED_PORTABLE_PYTHON && !pluginPythonVersion) pluginPythonVersion = packagedPythonVersion; + let portablePythonOptions = options.packageJson.scrypted.pythonVersion?.options?.[os.platform()]?.[os.arch()] || options.packageJson.scrypted.pythonVersion?.options?.default || {}; + // if the plugin requests a specific python, then install it via portable python if (!pluginPythonVersion) { setup(); @@ -148,7 +150,7 @@ export class PythonRuntimeWorker extends ChildProcessWorker { const pyPath = path.join(getPluginVolume(pluginId), 'py'); const portableInstallPath = path.join(pyPath, pyVersion); - const py = new PortablePython(pluginPythonVersion, portableInstallPath); + const py = new PortablePython(pluginPythonVersion, portableInstallPath, portablePythonOptions); if (fs.existsSync(py.executablePath)) { pythonPath = py.executablePath; finishSetup(); @@ -158,7 +160,7 @@ export class PythonRuntimeWorker extends ChildProcessWorker { try { this.pythonInstallationComplete = false; await fs.promises.rm(pyPath, { recursive: true, force: true }).catch(() => { }); - pythonPath = await installScryptedServerRequirements(pluginPythonVersion, portableInstallPath); + pythonPath = await installScryptedServerRequirements(pluginPythonVersion, portableInstallPath, portablePythonOptions); finishSetup(); } catch (e) {