Add workflow base into default PYTHONPATH for win32

This commit is contained in:
kagami 2024-04-22 15:46:57 +08:00 committed by kagami
parent bbc6c1e4e6
commit 4549fadd98

View File

@ -36,11 +36,18 @@ export async function installDevchat(): Promise<string> {
const pythonApp = path.join(pythonTargetPath, "python.exe"); const pythonApp = path.join(pythonTargetPath, "python.exe");
const pythonPathFile = path.join(pythonTargetPath, "python311._pth"); const pythonPathFile = path.join(pythonTargetPath, "python311._pth");
const sitepackagesPath = path.join(UiUtilWrapper.extensionPath(), "tools", "site-packages"); const sitepackagesPath = path.join(UiUtilWrapper.extensionPath(), "tools", "site-packages");
const userHomeDir = os.homedir();
// TODO: temperary workflow base dir name, need to change
const WORKFLOWS_BASE_NAME = "new_wf";
const workflow_base_path = path.join(userHomeDir, ".chat", WORKFLOWS_BASE_NAME);
const new_python_path = [workflow_base_path, sitepackagesPath].join("\n");
// read content in pythonPathFile // read content in pythonPathFile
let content = fs.readFileSync(pythonPathFile, { encoding: 'utf-8' }); let content = fs.readFileSync(pythonPathFile, { encoding: 'utf-8' });
// replace %PYTHONPATH% with sitepackagesPath // replace %PYTHONPATH% with sitepackagesPath
content = content.replace(/%PYTHONPATH%/g, sitepackagesPath); content = content.replace(/%PYTHONPATH%/g, new_python_path);
// write content to pythonPathFile // write content to pythonPathFile
fs.writeFileSync(pythonPathFile, content); fs.writeFileSync(pythonPathFile, content);