Skip to content

Commit fbf641a

Browse files
committed
Use configured Python interpreter for Metaflow commands (Issue #3)
- Read python.defaultInterpreterPath from Python extension config - Fallback to 'python' from PATH when no interpreter is set - Quote paths with spaces for Windows compatibility Made-with: Cursor
1 parent a56e92a commit fbf641a

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

extension.js

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@ const path = require('path');
33

44
let sharedTerminal = null;
55

6+
/**
7+
* Get the Python executable path from VS Code's configured interpreter.
8+
* Uses the Python extension's defaultInterpreterPath when available,
9+
* otherwise falls back to 'python' from PATH.
10+
*/
11+
function getPythonExecutable() {
12+
const config = vscode.workspace.getConfiguration('python');
13+
const interpreterPath = config.get('defaultInterpreterPath');
14+
if (interpreterPath && typeof interpreterPath === 'string') {
15+
const trimmed = interpreterPath.trim();
16+
if (trimmed.length > 0) {
17+
return trimmed;
18+
}
19+
}
20+
return 'python';
21+
}
22+
623
/**
724
* Core function to detect the current Python function name and run a script.
825
*/
@@ -33,12 +50,17 @@ async function runPythonCommand(scriptName) {
3350

3451
const filePath = doc.fileName;
3552
const fileDir = path.dirname(filePath);
53+
const pythonExecutable = getPythonExecutable();
54+
55+
// Quote paths that may contain spaces (e.g. "C:\Program Files\Python\python.exe")
56+
const quotedPython = pythonExecutable.includes(' ') ? `"${pythonExecutable}"` : pythonExecutable;
57+
const quotedFilePath = filePath.includes(' ') ? `"${filePath}"` : filePath;
3658

3759
let command = '';
3860
if (scriptName == 'spin_func')
39-
command = `python ${filePath} spin ${funcName}`;
61+
command = `${quotedPython} ${quotedFilePath} spin ${funcName}`;
4062
else
41-
command = `python ${filePath} run`;
63+
command = `${quotedPython} ${quotedFilePath} run`;
4264

4365
// Reuse or create a single shared terminal
4466
if (!sharedTerminal || sharedTerminal.exitStatus !== undefined) {

0 commit comments

Comments
 (0)