Skip to content

Commit

Permalink
Add pythonpath setting
Browse files Browse the repository at this point in the history
  • Loading branch information
nrontsis committed Nov 2, 2024
1 parent bda00cb commit 0f8e980
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
9 changes: 9 additions & 0 deletions client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,15 @@
],
"main": "./out/extension",
"contributes": {
"configuration": {
"properties": {
"kapitan.pythonPath": {
"type": "string",
"default": "",
"description": "Custom Python path for the extension. Should point to python 3.11 or later. Defaults to the python.pythonPath setting."
}
}
},
"languages": [
{
"id": "yaml",
Expand Down
17 changes: 15 additions & 2 deletions client/src/setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,21 @@ async function createVirtualEnvironment(python: string, name: string, cwd: strin
}

export async function getPython(): Promise<string> {
let python = workspace.getConfiguration('python').get<string>('pythonPath', getPythonCrossPlatform())
const config = workspace.getConfiguration('kapitan')
let python = config.get<string>('pythonPath', '')

// If we have a saved valid path, use it
if (python && await checkPythonVersion(python)) {
return python
}

// Fall back to Python extension setting if available
python = workspace.getConfiguration('python').get<string>('pythonPath', getPythonCrossPlatform());
if (await checkPythonVersion(python)) {
return python
}

// Otherwise, prompt user for input
python = await window.showInputBox({
ignoreFocusOut: true,
placeHolder: 'Enter a path to a python v3.6+.',
Expand All @@ -45,10 +55,13 @@ export async function getPython(): Promise<string> {
})

// User canceled the input
if (python === 'undefined') {
if (python === undefined) {
throw new Error('Python 3.11+ is required!')
}

// Save the valid path to settings
await config.update('pythonPath', python, true)

if (IS_WIN) {
python = '"' + python + '"'
}
Expand Down

0 comments on commit 0f8e980

Please sign in to comment.