Add version check for devchat-ask package
- Added a version check for the devchat-ask package in commands.ts. - Updated appInstall function in app_install.ts to accept package version. - Modified installAskCode function in install_askcode.ts to pass package version to appInstall. - Updated installDevchat function in install_devchat.ts to pass empty string as package version to appInstall. - Added a new utility function getPackageVersion in pip_package_version.ts to get the installed version of a package.
This commit is contained in:
parent
6d75c0d853
commit
48a9f0cb28
@ -393,11 +393,26 @@ export function registerAskCodeSummaryIndexStartCommand(context: vscode.Extensio
|
||||
progressBar.update("Index source code files for ask codebase summary...", 0);
|
||||
|
||||
const config = getConfig();
|
||||
const pythonVirtualEnv = config.pythonVirtualEnv;
|
||||
let pythonVirtualEnv: any = config.pythonVirtualEnv;
|
||||
const supportedFileTypes = config.supportedFileTypes;
|
||||
|
||||
updateIndexingStatus("started");
|
||||
|
||||
if (pythonVirtualEnv) {
|
||||
// check whether pythonVirtualEnv is stisfy the requirement version
|
||||
const devchatAskVersion = getPackageVersion(pythonVirtualEnv, "devchat-ask");
|
||||
|
||||
let requireAskVersion = "0.0.8";
|
||||
if (FT("ask-code-summary")) {
|
||||
requireAskVersion = "0.0.10";
|
||||
}
|
||||
|
||||
if (!devchatAskVersion || devchatAskVersion < requireAskVersion) {
|
||||
logger.channel()?.info(`The version of devchat-ask is ${devchatAskVersion}`);
|
||||
pythonVirtualEnv = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
if (!pythonVirtualEnv) {
|
||||
progressBar.update("Install devchat-ask package ...", 0);
|
||||
await installAskCode(supportedFileTypes, progressBar, indexCodeSummary);
|
||||
|
@ -11,7 +11,7 @@ import { installPython } from "./python_install";
|
||||
// step 2. create env with python 3.11.4
|
||||
// step 3. install devchat in the env
|
||||
|
||||
export async function appInstall(pkgName: string, pythonVersion: string) : Promise<string> {
|
||||
export async function appInstall(pkgName: string, pkgVersion: string, pythonVersion: string) : Promise<string> {
|
||||
// install conda
|
||||
logger.channel()?.info('Install conda ...')
|
||||
const condaCommand = await installConda();
|
||||
@ -44,7 +44,7 @@ export async function appInstall(pkgName: string, pythonVersion: string) : Promi
|
||||
let isInstalled = false;
|
||||
// try 3 times
|
||||
for (let i = 0; i < 3; i++) {
|
||||
isInstalled = await installPackage(pythonCommand, pkgName);
|
||||
isInstalled = await installPackage(pythonCommand, pkgName + pkgVersion);
|
||||
if (isInstalled) {
|
||||
break;
|
||||
}
|
||||
|
@ -13,11 +13,11 @@ import { logger } from "../logger";
|
||||
export async function installAskCode(): Promise<string> {
|
||||
try {
|
||||
logger.channel()?.info(`start installing AskCode with python=3.11.4 ...`);
|
||||
let devchatAskVersion = 'devchat-ask>=0.0.8';
|
||||
let devchatAskVersion = '>=0.0.8';
|
||||
if (FT("ask-code-summary")) {
|
||||
devchatAskVersion = 'devchat-ask>=0.0.10';
|
||||
devchatAskVersion = '>=0.0.10';
|
||||
}
|
||||
const pythonCommand = await appInstall(devchatAskVersion, '3.11.4');
|
||||
const pythonCommand = await appInstall("devchat-ask", devchatAskVersion, '3.11.4');
|
||||
if (!pythonCommand) {
|
||||
logger.channel()?.error(`failed to install devchat-ask with python=3.11.4`);
|
||||
logger.channel()?.show();
|
||||
|
@ -25,7 +25,7 @@ export async function installDevchat(): Promise<string> {
|
||||
try {
|
||||
logger.channel()?.info(`start installing devchat with python=3.11.4 ...`);
|
||||
isDevChatInstalling = true;
|
||||
const pythonCommand = await appInstall('devchat', '3.11.4');
|
||||
const pythonCommand = await appInstall('devchat', "", '3.11.4');
|
||||
if (!pythonCommand) {
|
||||
logger.channel()?.error(`failed to install devchat with python=3.11.4`);
|
||||
logger.channel()?.show();
|
||||
|
12
src/util/python_installer/pip_package_version.ts
Normal file
12
src/util/python_installer/pip_package_version.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import { execSync } from 'child_process';
|
||||
|
||||
export function getPackageVersion(pythonPath: string, packageName: string): string | undefined {
|
||||
try {
|
||||
const stdout = execSync(`${pythonPath} -m pip show ${packageName}`).toString();
|
||||
const versionLine = stdout.split('\n').find(line => line.startsWith('Version'));
|
||||
return versionLine ? versionLine.split(': ')[1] : undefined;
|
||||
} catch (error) {
|
||||
console.error(`exec error: ${error}`);
|
||||
return undefined;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user