Refactor checkDevChatDependency to accept pythonCommand
- Update checkDevChatDependency to take pythonCommand as an argument. - Modify getPipxEnvironmentPath to use pythonCommand. - Adjust statusBarViewBase.ts to pass pythonCommand. - Update test cases in commandsBase.test.ts accordingly.
This commit is contained in:
parent
8ccf73b9bb
commit
5fc21c1982
@ -4,9 +4,9 @@ import { runCommand } from "../util/commonUtil";
|
||||
import { logger } from "../util/logger";
|
||||
|
||||
|
||||
export function checkDevChatDependency(): boolean {
|
||||
export function checkDevChatDependency(pythonCommand: string): boolean {
|
||||
try {
|
||||
const binPath = getPipxEnvironmentPath();
|
||||
const binPath = getPipxEnvironmentPath(pythonCommand);
|
||||
|
||||
if (binPath) {
|
||||
updateEnvironmentPath(binPath);
|
||||
@ -43,9 +43,9 @@ export function getValidPythonCommand(): string | undefined {
|
||||
}
|
||||
}
|
||||
|
||||
export function getPipxEnvironmentPath(): string | null {
|
||||
export function getPipxEnvironmentPath(pythonCommand: string): string | null {
|
||||
// Get pipx environment
|
||||
const pipxEnvOutput = runCommand('python3 -m pipx environment').toString();
|
||||
const pipxEnvOutput = runCommand(`${pythonCommand} -m pipx environment`).toString();
|
||||
const binPathRegex = /PIPX_BIN_DIR=\s*(.*)/;
|
||||
|
||||
// Get BIN path from pipx environment
|
||||
|
@ -32,6 +32,18 @@ export async function dependencyCheck(): Promise<[string, string]> {
|
||||
logger.channel()?.info(`versionOld: ${versionOld}, versionNew: ${versionNew}, versionChanged: ${versionChanged}`);
|
||||
}
|
||||
|
||||
const pythonCommand = getValidPythonCommand();
|
||||
if (!pythonCommand) {
|
||||
if (devchatStatus === '') {
|
||||
UiUtilWrapper.showErrorMessage('Missing required dependency: Python3');
|
||||
logger.channel()?.error('Missing required dependency: Python3');
|
||||
logger.channel()?.show();
|
||||
}
|
||||
|
||||
devchatStatus = 'Missing required dependency: Python3';
|
||||
} else {
|
||||
devchatStatus = '';
|
||||
}
|
||||
|
||||
// status item has three status type
|
||||
// 1. not in a folder
|
||||
@ -45,7 +57,7 @@ export async function dependencyCheck(): Promise<[string, string]> {
|
||||
}
|
||||
|
||||
if (!bOk) {
|
||||
bOk = checkDevChatDependency();
|
||||
bOk = checkDevChatDependency(pythonCommand!);
|
||||
}
|
||||
if (bOk && versionChanged) {
|
||||
bOk = false;
|
||||
@ -60,21 +72,11 @@ export async function dependencyCheck(): Promise<[string, string]> {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (devchatStatus === 'not ready' || devchatStatus === 'Waiting for Python3 installation to complete') {
|
||||
if (devchatStatus === 'not ready') {
|
||||
// auto install devchat
|
||||
// check whether python3 exist
|
||||
const pythonCommand = getValidPythonCommand();
|
||||
if (!pythonCommand && devchatStatus === 'not ready') {
|
||||
UiUtilWrapper.showErrorMessage('Python3 not found.');
|
||||
devchatStatus = 'Waiting for Python3 installation to complete';
|
||||
isVersionChangeCompare = true;
|
||||
} else if (!pythonCommand) {
|
||||
// Waiting for Python3 installation to complete
|
||||
} else {
|
||||
UiUtilWrapper.runTerminal('DevChat Install', `${pythonCommand} ${UiUtilWrapper.extensionPath() + "/tools/install.py"}`);
|
||||
devchatStatus = 'Waiting for devchat installation to complete';
|
||||
isVersionChangeCompare = true;
|
||||
}
|
||||
UiUtilWrapper.runTerminal('DevChat Install', `${pythonCommand} ${UiUtilWrapper.extensionPath() + "/tools/install.py"}`);
|
||||
devchatStatus = 'Waiting for devchat installation to complete';
|
||||
isVersionChangeCompare = true;
|
||||
}
|
||||
|
||||
// check api key
|
||||
|
@ -21,7 +21,7 @@ describe('commandsBase', () => {
|
||||
return '';
|
||||
});
|
||||
|
||||
const result = commandsBase.checkDevChatDependency();
|
||||
const result = commandsBase.checkDevChatDependency("python3");
|
||||
expect(result).to.be.true;
|
||||
});
|
||||
|
||||
@ -35,7 +35,7 @@ describe('commandsBase', () => {
|
||||
return '';
|
||||
});
|
||||
|
||||
const result = commandsBase.checkDevChatDependency();
|
||||
const result = commandsBase.checkDevChatDependency("python3");
|
||||
expect(result).to.be.false;
|
||||
});
|
||||
|
||||
@ -47,7 +47,7 @@ describe('commandsBase', () => {
|
||||
return '';
|
||||
});
|
||||
|
||||
const result = commandsBase.checkDevChatDependency();
|
||||
const result = commandsBase.checkDevChatDependency("python3");
|
||||
expect(result).to.be.false;
|
||||
});
|
||||
});
|
||||
@ -65,7 +65,7 @@ describe('commandsBase', () => {
|
||||
return '';
|
||||
});
|
||||
|
||||
const result = commandsBase.getPipxEnvironmentPath();
|
||||
const result = commandsBase.getPipxEnvironmentPath("python3");
|
||||
expect(result).to.equal('/path/to/bin');
|
||||
});
|
||||
|
||||
@ -77,7 +77,7 @@ describe('commandsBase', () => {
|
||||
return '';
|
||||
});
|
||||
|
||||
const result = commandsBase.getPipxEnvironmentPath();
|
||||
const result = commandsBase.getPipxEnvironmentPath("python3");
|
||||
expect(result).to.be.null;
|
||||
});
|
||||
});
|
||||
|
Loading…
x
Reference in New Issue
Block a user