Add Python Path configuration and command to package.json
- Added a new configuration 'DevChat.PythonPath' in package.json. - This configuration allows users to specify the location of the Python binary. - Also added a new command 'DevChat.PythonPath' to the command palette. - Updated commandsBase.ts to use the Python Path from the configuration. - If the Python Path is not set in the configuration, it will use the default Python command. - If the DevChat status is 'Missing required dependency: Python3', the status bar item will trigger the 'devchat.PythonPath' command.
This commit is contained in:
parent
892c3638cc
commit
d474957fe8
18
package.json
18
package.json
@ -131,6 +131,19 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"description": "Where is the devchat binary located?"
|
"description": "Where is the devchat binary located?"
|
||||||
|
},
|
||||||
|
"DevChat.PythonPath": {
|
||||||
|
"type": "string",
|
||||||
|
"default": "",
|
||||||
|
"input": {
|
||||||
|
"type": "file",
|
||||||
|
"filter": {
|
||||||
|
"All files": [
|
||||||
|
"python*"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"description": "Where is the python binary located?"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
@ -196,6 +209,11 @@
|
|||||||
"title": "Input Access Key",
|
"title": "Input Access Key",
|
||||||
"category": "DevChat"
|
"category": "DevChat"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"command": "DevChat.PythonPath",
|
||||||
|
"title": "Set Python Path",
|
||||||
|
"category": "DevChat"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"command": "devchat.openChatPanel",
|
"command": "devchat.openChatPanel",
|
||||||
"title": "DevChat"
|
"title": "DevChat"
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
// src/contributes/commandsBase.ts
|
// src/contributes/commandsBase.ts
|
||||||
|
|
||||||
|
import { UiUtilWrapper } from "../util/uiUtil";
|
||||||
import { runCommand } from "../util/commonUtil";
|
import { runCommand } from "../util/commonUtil";
|
||||||
import { logger } from "../util/logger";
|
import { logger } from "../util/logger";
|
||||||
|
|
||||||
@ -29,15 +30,23 @@ export function checkDevChatDependency(pythonCommand: string): boolean {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getValidPythonCommand(): string | undefined {
|
function getDefaultPythonCommand(): string | undefined {
|
||||||
try {
|
try {
|
||||||
runCommand('python3 -V');
|
runCommand('python3 -V');
|
||||||
return 'python3';
|
try {
|
||||||
|
return runCommand('where python3').toString().trim();
|
||||||
|
} catch (error) {
|
||||||
|
return runCommand('which python3').toString().trim();
|
||||||
|
}
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
try {
|
try {
|
||||||
const version = runCommand('python -V');
|
const version = runCommand('python -V');
|
||||||
if (version.includes('Python 3')) {
|
if (version.includes('Python 3')) {
|
||||||
return 'python';
|
try {
|
||||||
|
return runCommand('where python').toString().trim();
|
||||||
|
} catch (error) {
|
||||||
|
return runCommand('which python').toString().trim();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return undefined;
|
return undefined;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -46,9 +55,27 @@ export function getValidPythonCommand(): string | undefined {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getValidPythonCommand(): string | undefined {
|
||||||
|
try {
|
||||||
|
const pythonCommand = UiUtilWrapper.getConfiguration('DevChat', 'PythonPath');
|
||||||
|
if (pythonCommand) {
|
||||||
|
return pythonCommand;
|
||||||
|
}
|
||||||
|
|
||||||
|
const defaultPythonCommand = getDefaultPythonCommand();
|
||||||
|
if (defaultPythonCommand) {
|
||||||
|
UiUtilWrapper.updateConfiguration('DevChat', 'PythonPath', defaultPythonCommand);
|
||||||
|
}
|
||||||
|
|
||||||
|
return defaultPythonCommand;
|
||||||
|
} catch (error) {
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export function getPipxEnvironmentPath(pythonCommand: string): string | null {
|
export function getPipxEnvironmentPath(pythonCommand: string): string | null {
|
||||||
// Get pipx environment
|
// Get pipx environment
|
||||||
const pipxEnvOutput = runCommand(`${pythonCommand} -m pipx environment`).toString();
|
const pipxEnvOutput = runCommand(`"${pythonCommand}" -m pipx environment`).toString();
|
||||||
const binPathRegex = /PIPX_BIN_DIR=\s*(.*)/;
|
const binPathRegex = /PIPX_BIN_DIR=\s*(.*)/;
|
||||||
|
|
||||||
// Get BIN path from pipx environment
|
// Get BIN path from pipx environment
|
||||||
@ -62,7 +89,7 @@ export function getPipxEnvironmentPath(pythonCommand: string): string | null {
|
|||||||
|
|
||||||
function updateEnvironmentPath(binPath: string): void {
|
function updateEnvironmentPath(binPath: string): void {
|
||||||
// Add BIN path to PATH
|
// Add BIN path to PATH
|
||||||
if (process.env.PATH?.indexOf(binPath) === undefined) {
|
if (process.env.PATH?.indexOf(binPath) === undefined || process.env.PATH?.indexOf(binPath) < 0) {
|
||||||
process.env.PATH = `${binPath}:${process.env.PATH}`;
|
process.env.PATH = `${binPath}:${process.env.PATH}`;
|
||||||
logger.channel()?.info(`Added ${binPath} to PATH.`);
|
logger.channel()?.info(`Added ${binPath} to PATH.`);
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,13 @@ export function createStatusBarItem(context: vscode.ExtensionContext): vscode.St
|
|||||||
if (devchatStatus !== 'ready') {
|
if (devchatStatus !== 'ready') {
|
||||||
statusBarItem.text = `$(warning)DevChat`;
|
statusBarItem.text = `$(warning)DevChat`;
|
||||||
statusBarItem.tooltip = `${devchatStatus}`;
|
statusBarItem.tooltip = `${devchatStatus}`;
|
||||||
|
|
||||||
|
if (devchatStatus === 'Missing required dependency: Python3') {
|
||||||
|
statusBarItem.command = "devchat.PythonPath";
|
||||||
|
} else {
|
||||||
statusBarItem.command = undefined;
|
statusBarItem.command = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
// set statusBarItem warning color
|
// set statusBarItem warning color
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user