install devchat by conda
This commit is contained in:
parent
46a70a15ac
commit
90126a9d48
@ -14,21 +14,10 @@ export function createStatusBarItem(context: vscode.ExtensionContext): vscode.St
|
|||||||
statusBarItem.command = undefined;
|
statusBarItem.command = undefined;
|
||||||
|
|
||||||
// add a timer to update the status bar item
|
// add a timer to update the status bar item
|
||||||
let runStatus = 0;
|
|
||||||
let continueTimes = 0
|
|
||||||
|
|
||||||
setInterval(async () => {
|
setInterval(async () => {
|
||||||
if (runStatus > 0 && continueTimes < 60) {
|
|
||||||
continueTimes += 1;
|
|
||||||
return ;
|
|
||||||
}
|
|
||||||
|
|
||||||
runStatus = 1;
|
|
||||||
continueTimes = 0;
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const [devchatStatus, apiKeyStatus] = await dependencyCheck();
|
const [devchatStatus, apiKeyStatus] = await dependencyCheck();
|
||||||
if (devchatStatus !== 'ready') {
|
if (devchatStatus !== 'has statisfied the dependency' && devchatStatus !== 'DevChat has been installed') {
|
||||||
statusBarItem.text = `$(warning)DevChat`;
|
statusBarItem.text = `$(warning)DevChat`;
|
||||||
statusBarItem.tooltip = `${devchatStatus}`;
|
statusBarItem.tooltip = `${devchatStatus}`;
|
||||||
|
|
||||||
@ -42,7 +31,7 @@ export function createStatusBarItem(context: vscode.ExtensionContext): vscode.St
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (apiKeyStatus !== 'ready') {
|
if (apiKeyStatus !== 'has valid access key') {
|
||||||
statusBarItem.text = `$(warning)DevChat`;
|
statusBarItem.text = `$(warning)DevChat`;
|
||||||
statusBarItem.tooltip = `${apiKeyStatus}`;
|
statusBarItem.tooltip = `${apiKeyStatus}`;
|
||||||
statusBarItem.command = 'DevChat.Access_Key_DevChat';
|
statusBarItem.command = 'DevChat.Access_Key_DevChat';
|
||||||
@ -56,8 +45,6 @@ export function createStatusBarItem(context: vscode.ExtensionContext): vscode.St
|
|||||||
statusBarItem.text = `$(warning)DevChat`;
|
statusBarItem.text = `$(warning)DevChat`;
|
||||||
statusBarItem.tooltip = `Error: ${error}`;
|
statusBarItem.tooltip = `Error: ${error}`;
|
||||||
statusBarItem.command = undefined;
|
statusBarItem.command = undefined;
|
||||||
} finally {
|
|
||||||
runStatus = 0;
|
|
||||||
}
|
}
|
||||||
}, 3000);
|
}, 3000);
|
||||||
|
|
||||||
|
@ -4,9 +4,10 @@ import { logger } from "../util/logger";
|
|||||||
|
|
||||||
import { UiUtilWrapper } from "../util/uiUtil";
|
import { UiUtilWrapper } from "../util/uiUtil";
|
||||||
import { TopicManager } from "../topic/topicManager";
|
import { TopicManager } from "../topic/topicManager";
|
||||||
import { checkDevChatDependency, getPipxEnvironmentPath, getValidPythonCommand } from "../contributes/commandsBase";
|
import { checkDevChatDependency } from "../contributes/commandsBase";
|
||||||
import { ApiKeyManager } from '../util/apiKey';
|
import { ApiKeyManager } from '../util/apiKey';
|
||||||
import { CommandRun } from '../util/commonUtil';
|
import { CommandRun } from '../util/commonUtil';
|
||||||
|
import { installDevchat } from '../util/python_installer/install_devchat';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -20,100 +21,90 @@ function getExtensionVersion(): string {
|
|||||||
|
|
||||||
let devchatStatus = '';
|
let devchatStatus = '';
|
||||||
let apiKeyStatus = '';
|
let apiKeyStatus = '';
|
||||||
let isVersionChangeCompare: boolean|undefined = undefined;
|
|
||||||
|
let preDevchatStatus = '';
|
||||||
|
let preApiKeyStatus = '';
|
||||||
|
|
||||||
export async function dependencyCheck(): Promise<[string, string]> {
|
export async function dependencyCheck(): Promise<[string, string]> {
|
||||||
let versionChanged = false;
|
// there are some different status of devchat:
|
||||||
if (isVersionChangeCompare === undefined) {
|
// 0. not checked
|
||||||
try {
|
// 1. has statisfied the dependency
|
||||||
const versionOld = await UiUtilWrapper.secretStorageGet("DevChatVersionOld");
|
// 2. is installing
|
||||||
const versionNew = getExtensionVersion();
|
// 3. install failed
|
||||||
versionChanged = versionOld !== versionNew;
|
// 4. install success
|
||||||
UiUtilWrapper.storeSecret("DevChatVersionOld", versionNew!);
|
|
||||||
|
|
||||||
isVersionChangeCompare = true;
|
// key status:
|
||||||
logger.channel()?.info(`versionOld: ${versionOld}, versionNew: ${versionNew}, versionChanged: ${versionChanged}`);
|
// 0. not checked
|
||||||
} catch (error) {
|
// 1. invalid or not set
|
||||||
isVersionChangeCompare = false;
|
// 2. valid key
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const pythonCommand = getValidPythonCommand();
|
// define subfunction to check devchat dependency
|
||||||
if (!pythonCommand) {
|
const getDevChatStatus = async (): Promise<string> => {
|
||||||
if (devchatStatus === '') {
|
if (devchatStatus === '') {
|
||||||
UiUtilWrapper.showErrorMessage('Missing required dependency: Python3');
|
const bOk = checkDevChatDependency(false);
|
||||||
logger.channel()?.error('Missing required dependency: Python3');
|
if (bOk) {
|
||||||
logger.channel()?.show();
|
devchatStatus = 'has statisfied the dependency';
|
||||||
}
|
return devchatStatus;
|
||||||
|
|
||||||
devchatStatus = 'Missing required dependency: Python3';
|
|
||||||
} else if (devchatStatus === 'Missing required dependency: Python3') {
|
|
||||||
devchatStatus = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
// status item has three status type
|
|
||||||
// 1. not in a folder
|
|
||||||
// 2. dependence is invalid
|
|
||||||
// 3. ready
|
|
||||||
if (devchatStatus === '' ||
|
|
||||||
devchatStatus === 'An error occurred during the installation of DevChat' ||
|
|
||||||
devchatStatus === 'DevChat has been installed') {
|
|
||||||
let bOk = false;
|
|
||||||
if (!bOk) {
|
|
||||||
const showError = devchatStatus == ''? false : true;
|
|
||||||
bOk = checkDevChatDependency(pythonCommand!, showError);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (bOk) {
|
|
||||||
devchatStatus = 'ready';
|
|
||||||
TopicManager.getInstance().loadTopics();
|
|
||||||
} else {
|
|
||||||
if (devchatStatus === '') {
|
|
||||||
devchatStatus = 'not ready';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
devchatStatus = 'installing devchat';
|
||||||
|
const devchatCommandEnv = await installDevchat();
|
||||||
|
if (devchatCommandEnv) {
|
||||||
|
logger.channel()?.info(`devchatCommandEnv: ${devchatCommandEnv}`);
|
||||||
|
await UiUtilWrapper.updateConfiguration('DevChat', 'DevChatPath', devchatCommandEnv);
|
||||||
|
|
||||||
|
devchatStatus = 'DevChat has been installed';
|
||||||
|
return devchatStatus;
|
||||||
|
} else {
|
||||||
|
logger.channel()?.info(`devchatCommandEnv: undefined`);
|
||||||
|
|
||||||
|
devchatStatus = 'An error occurred during the installation of DevChat';
|
||||||
|
return devchatStatus;
|
||||||
|
}
|
||||||
|
} else if (devchatStatus === 'has statisfied the dependency') {
|
||||||
|
return devchatStatus;
|
||||||
|
} else if (devchatStatus === 'installing devchat') {
|
||||||
|
return devchatStatus;
|
||||||
|
} else if (devchatStatus === 'DevChat has been installed') {
|
||||||
|
return devchatStatus;
|
||||||
|
} else if (devchatStatus === 'An error occurred during the installation of DevChat') {
|
||||||
|
const bOk = checkDevChatDependency(false);
|
||||||
|
if (bOk) {
|
||||||
|
devchatStatus = 'has statisfied the dependency';
|
||||||
|
return devchatStatus;
|
||||||
|
}
|
||||||
|
return devchatStatus;
|
||||||
}
|
}
|
||||||
}
|
return "";
|
||||||
if (devchatStatus === 'not ready') {
|
};
|
||||||
// auto install devchat
|
|
||||||
const run = new CommandRun();
|
|
||||||
const options = {
|
|
||||||
cwd: UiUtilWrapper.workspaceFoldersFirstPath() || '.',
|
|
||||||
};
|
|
||||||
|
|
||||||
let errorInstall = false;
|
// define subfunction to check api key
|
||||||
let installLogs = '';
|
const getApiKeyStatus = async (): Promise<string> => {
|
||||||
await run.spawnAsync(pythonCommand!, [UiUtilWrapper.extensionPath() + "/tools/install.py"], options,
|
if (apiKeyStatus === '' || apiKeyStatus === 'Please set the API key') {
|
||||||
(data) => {
|
const accessKey = await ApiKeyManager.getApiKey();
|
||||||
installLogs += data;
|
if (accessKey) {
|
||||||
logger.channel()?.info(data.trim());
|
apiKeyStatus = 'has valid access key';
|
||||||
},
|
return apiKeyStatus;
|
||||||
(data) => {
|
} else {
|
||||||
errorInstall = true;
|
apiKeyStatus = 'Please set the API key';
|
||||||
logger.channel()?.info(data.trim());
|
return apiKeyStatus;
|
||||||
}, undefined, undefined);
|
}
|
||||||
|
|
||||||
// UiUtilWrapper.runTerminal('DevChat Install', `${pythonCommand} "${UiUtilWrapper.extensionPath() + "/tools/install.py"}"`);
|
|
||||||
const devchatCommandEnv = installLogs.match(/devchatCommandEnv: (.*)/)?.[1];
|
|
||||||
if (devchatCommandEnv) {
|
|
||||||
logger.channel()?.info(`devchatCommandEnv: ${devchatCommandEnv}`);
|
|
||||||
await UiUtilWrapper.updateConfiguration('DevChat', 'DevChatPath', devchatCommandEnv);
|
|
||||||
devchatStatus = 'DevChat has been installed';
|
|
||||||
} else {
|
} else {
|
||||||
logger.channel()?.info(`devchatCommandEnv: undefined`);
|
return apiKeyStatus;
|
||||||
devchatStatus = 'An error occurred during the installation of DevChat';
|
|
||||||
}
|
}
|
||||||
|
};
|
||||||
|
|
||||||
isVersionChangeCompare = true;
|
const devchatPackageStatus = await getDevChatStatus();
|
||||||
|
const apiAccessKeyStatus = await getApiKeyStatus();
|
||||||
|
|
||||||
|
if (devchatPackageStatus !== preDevchatStatus) {
|
||||||
|
logger.channel()?.info(`devchat status: ${devchatPackageStatus}`);
|
||||||
|
preDevchatStatus = devchatPackageStatus;
|
||||||
|
}
|
||||||
|
if (apiAccessKeyStatus !== preApiKeyStatus) {
|
||||||
|
logger.channel()?.info(`api key status: ${apiAccessKeyStatus}`);
|
||||||
|
preApiKeyStatus = apiAccessKeyStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check api key
|
return [devchatPackageStatus, apiAccessKeyStatus];
|
||||||
if (apiKeyStatus === '' || apiKeyStatus === 'Please set the API key') {
|
|
||||||
const bOk = await ApiKeyManager.getApiKey();
|
|
||||||
if (bOk) {
|
|
||||||
apiKeyStatus = 'ready';
|
|
||||||
} else {
|
|
||||||
apiKeyStatus = 'Please set the API key';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return [devchatStatus, apiKeyStatus];
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user