server: use plugin volume for tf install

This commit is contained in:
Koushik Dutta
2024-03-18 14:45:11 -07:00
parent c5cf8d01ea
commit 8f2e15f9df
2 changed files with 22 additions and 21 deletions

View File

@@ -7,6 +7,7 @@ import { PassThrough, Readable, Writable } from 'stream';
import { installScryptedServerRequirements, version as packagedPythonVersion } from '../../../bin/packaged-python';
import { RpcMessage, RpcPeer } from "../../rpc";
import { createRpcDuplexSerializer } from '../../rpc-serializer';
import { getPluginVolume } from '../plugin-volume';
import { ChildProcessWorker } from "./child-process-worker";
import { RuntimeWorkerOptions } from "./runtime-worker";
@@ -23,8 +24,6 @@ export class PythonRuntimeWorker extends ChildProcessWorker {
}
}
static pythonInstalls = new Map<string, Promise<string>>();
serializer: ReturnType<typeof createRpcDuplexSerializer>;
peerin: Writable;
peerout: Readable;
@@ -128,30 +127,32 @@ export class PythonRuntimeWorker extends ChildProcessWorker {
(this.worker.stdio[4] as Readable).pipe(peerout);
};
const py = new PortablePython(pluginPythonVersion);
const pyVersion = require('py/package.json').version;
const pyPath = path.join(getPluginVolume(pluginId), 'py');
const portableInstallPath = path.join(pyPath, pyVersion);
const py = new PortablePython(pluginPythonVersion, portableInstallPath);
if (fs.existsSync(py.executablePath)) {
pythonPath = py.executablePath;
finishSetup();
}
else {
this.pythonInstallationComplete = false;
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(() => {
(async () => {
try {
this.pythonInstallationComplete = false;
await fs.promises.rm(pyPath, { recursive: true, force: true }).catch(() => { });
pythonPath = await installScryptedServerRequirements(pluginPythonVersion, portableInstallPath);
finishSetup();
}
catch (e) {
process.nextTick(() => {
this.emit('error', new Error('Failed to install portable python.'));
})
})
.finally(() => this.pythonInstallationComplete = true);
});
}
finally {
this.pythonInstallationComplete = true
}
})();
}
}
else {