refactor: Remove installation check process from devchat-commands
- Remove unnecessary installation check codes from devchat-commands - Streamline setup process for new users - Maintain application functionality and stability
This commit is contained in:
parent
63ae50a819
commit
13eaac2953
@ -224,79 +224,6 @@ export function registerInstallCommandsCommand(
|
||||
}
|
||||
|
||||
|
||||
export function registerInstallCommandsPython(context: vscode.ExtensionContext) {
|
||||
let disposable = vscode.commands.registerCommand('DevChat.InstallCommandPython', async () => {
|
||||
// steps of install command python
|
||||
// 1. install python >= 3.11
|
||||
// 2. check requirements.txt in ~/.chat dir
|
||||
// 3. install requirements.txt
|
||||
|
||||
// 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("devchat-commands", "", "3.11.4");
|
||||
|
||||
if (!pythonCommand || pythonCommand === "") {
|
||||
logger.channel()?.info(`create env by mamba failed, try to create env by conda ...`);
|
||||
pythonCommand = await createEnvByConda("devchat-commands", "", "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 ;
|
||||
}
|
||||
|
||||
// 2. check requirements.txt in ~/.chat dir
|
||||
// ~/.chat/requirements.txt
|
||||
const usrRequirementsFile = path.join(os.homedir(), '.chat', 'workflows', 'usr', 'requirements.txt');
|
||||
const orgRequirementsFile = path.join(os.homedir(), '.chat', 'workflows', 'org', 'requirements.txt');
|
||||
const sysRequirementsFile = path.join(os.homedir(), '.chat', 'workflows', 'sys', 'requirements.txt');
|
||||
let requirementsFile = sysRequirementsFile;
|
||||
if (fs.existsSync(orgRequirementsFile)) {
|
||||
requirementsFile = orgRequirementsFile;
|
||||
}
|
||||
if (fs.existsSync(usrRequirementsFile)) {
|
||||
requirementsFile = usrRequirementsFile;
|
||||
}
|
||||
|
||||
if (!fs.existsSync(requirementsFile)) {
|
||||
// logger.channel()?.warn(`requirements.txt not found in ~/.chat/workflows dir.`);
|
||||
// logger.channel()?.show();
|
||||
// vscode.window.showErrorMessage(`Error: see OUTPUT for more detail!`);
|
||||
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, requirementsFile, 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 ~/.chat/requirements.txt"`);
|
||||
logger.channel()?.show();
|
||||
vscode.window.showErrorMessage(`Error: see OUTPUT for more detail!`);
|
||||
return '';
|
||||
}
|
||||
|
||||
DevChatConfig.getInstance().set("python_for_commands", pythonCommand.trim());
|
||||
// vscode.window.showInformationMessage(`All slash Commands are ready to use! Please input / to try workflow commands!`);
|
||||
});
|
||||
|
||||
context.subscriptions.push(disposable);
|
||||
}
|
||||
|
||||
export function registerDevChatChatCommand(context: vscode.ExtensionContext) {
|
||||
let disposable = vscode.commands.registerCommand(
|
||||
"DevChat.Chat",
|
||||
|
@ -9,7 +9,6 @@ import {
|
||||
registerStatusBarItemClickCommand,
|
||||
regPythonPathCommand,
|
||||
registerInstallCommandsCommand,
|
||||
registerInstallCommandsPython,
|
||||
registerDevChatChatCommand,
|
||||
registerHandleUri,
|
||||
registerCodeLensRangeCommand,
|
||||
@ -150,7 +149,6 @@ async function activate(context: vscode.ExtensionContext) {
|
||||
registerStatusBarItemClickCommand(context);
|
||||
|
||||
registerInstallCommandsCommand(context);
|
||||
registerInstallCommandsPython(context);
|
||||
|
||||
createStatusBarItem(context);
|
||||
|
||||
|
@ -22,27 +22,6 @@ export function createStatusBarItem(context: vscode.ExtensionContext): vscode.St
|
||||
progressBar.update("Checking dependencies", 0);
|
||||
let hasInstallCommands = false;
|
||||
|
||||
function checkDevChatCommandsStatus() {
|
||||
const timerDevchatCommands = setInterval(async () => {
|
||||
try {
|
||||
const pythonCommand = DevChatConfig.getInstance().get('python_for_commands');
|
||||
if (!pythonCommand) {
|
||||
statusBarItem.text = `$(pass)DevChat$(warning)`;
|
||||
statusBarItem.tooltip = `ready to chat, command functionality limited`;
|
||||
statusBarItem.command = 'devcaht.onStatusBarClick';
|
||||
} else {
|
||||
statusBarItem.text = `$(pass)DevChat$(pass)`;
|
||||
statusBarItem.tooltip = `chat and all commands fully operational`;
|
||||
statusBarItem.command = 'devcaht.onStatusBarClick';
|
||||
clearInterval(timerDevchatCommands);
|
||||
}
|
||||
} catch (error) {
|
||||
logger.channel()?.error(`Error: ${error}`);
|
||||
logger.channel()?.show();
|
||||
}
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
const timer = setInterval(async () => {
|
||||
try {
|
||||
progressBar.update("Checking dependencies", 0);
|
||||
@ -77,7 +56,6 @@ export function createStatusBarItem(context: vscode.ExtensionContext): vscode.St
|
||||
}
|
||||
|
||||
clearInterval(timer);
|
||||
checkDevChatCommandsStatus();
|
||||
} catch (error) {
|
||||
statusBarItem.text = `$(warning)DevChat`;
|
||||
statusBarItem.tooltip = `Error: ${error}`;
|
||||
|
Loading…
x
Reference in New Issue
Block a user