add new ide services for workflow
This commit is contained in:
parent
0376860ccd
commit
627374dc90
@ -1,9 +1,17 @@
|
||||
import * as http from 'http';
|
||||
import * as url from 'url';
|
||||
import * as vscode from 'vscode';
|
||||
import * as path from 'path';
|
||||
import { exec } from 'child_process';
|
||||
|
||||
import * as querystring from 'querystring';
|
||||
import { logger } from '../util/logger';
|
||||
import { UiUtilWrapper } from '../util/uiUtil';
|
||||
|
||||
import { createEnvByConda, createEnvByMamba } from '../util/python_installer/app_install';
|
||||
import { installRequirements } from '../util/python_installer/package_install';
|
||||
|
||||
|
||||
|
||||
|
||||
const functionRegistry: any = {
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
@ -12,6 +20,72 @@ const functionRegistry: any = {
|
||||
"handler": async () => {
|
||||
return await UiUtilWrapper.getLSPBrigePort();
|
||||
}
|
||||
},
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
"/update_slash_commands": {
|
||||
"keys": [],
|
||||
"handler": async () => {
|
||||
vscode.commands.executeCommand('DevChat.InstallCommands');
|
||||
return true;
|
||||
}
|
||||
},
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
"/open_folder": {
|
||||
"keys": ["folder"],
|
||||
"handler": async (folder: string) => {
|
||||
// open folder by vscode
|
||||
const folderPathParsed = folder.replace('\\', '/');
|
||||
// Updated Uri.parse to Uri.file
|
||||
const folderUri = vscode.Uri.file(folderPathParsed);
|
||||
vscode.commands.executeCommand(`vscode.openFolder`, folderUri);
|
||||
return true;
|
||||
}
|
||||
},
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
"/install_python_env": {
|
||||
"keys": ["command_name", "requirements_file"],
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
"handler": async (command_name: string, requirements_file: string) => {
|
||||
// 1. install python >= 3.11
|
||||
logger.channel()?.info(`create env for python ...`);
|
||||
logger.channel()?.info(`try to create env by mamba ...`);
|
||||
let pythonCommand = await createEnvByMamba(command_name, "", "3.11.4");
|
||||
|
||||
if (!pythonCommand || pythonCommand === "") {
|
||||
logger.channel()?.info(`create env by mamba failed, try to create env by conda ...`);
|
||||
pythonCommand = await createEnvByConda(command_name, "", "3.11.4");
|
||||
}
|
||||
|
||||
if (!pythonCommand || pythonCommand === "") {
|
||||
logger.channel()?.error(`create virtual python env failed, you need create it by yourself with command: "conda create -n devchat-commands python=3.11.4"`);
|
||||
logger.channel()?.show();
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
// 3. install requirements.txt
|
||||
// run command: pip install -r {requirementsFile}
|
||||
let isInstalled = false;
|
||||
// try 3 times
|
||||
for (let i = 0; i < 4; i++) {
|
||||
let otherSource: string | undefined = undefined;
|
||||
if (i>1) {
|
||||
otherSource = 'https://pypi.tuna.tsinghua.edu.cn/simple/';
|
||||
}
|
||||
isInstalled = await installRequirements(pythonCommand, requirements_file, otherSource);
|
||||
if (isInstalled) {
|
||||
break;
|
||||
}
|
||||
logger.channel()?.info(`Install packages failed, try again: ${i + 1}`);
|
||||
}
|
||||
if (!isInstalled) {
|
||||
logger.channel()?.error(`Install packages failed, you can install it with command: "${pythonCommand} -m pip install -r ${requirements_file}"`);
|
||||
logger.channel()?.show();
|
||||
return '';
|
||||
}
|
||||
|
||||
return pythonCommand.trim();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
2
tools
2
tools
@ -1 +1 @@
|
||||
Subproject commit d157dfc834ebd5e40be62a32c0406999374bbff6
|
||||
Subproject commit fb4d4565e8346020d4a42064db79068e2912f38c
|
Loading…
x
Reference in New Issue
Block a user