Skip to content

Commit 226a1f8

Browse files
committed
fix #692
1 parent 72a7fa5 commit 226a1f8

File tree

3 files changed

+27
-5
lines changed

3 files changed

+27
-5
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@
5959
"onCommand:jupyter.execCurrentCellAndAdvance",
6060
"onCommand:python.displayHelp",
6161
"onCommand:python.buildWorkspaceSymbols",
62-
"onCommand:python.updateSparkLibrary"
62+
"onCommand:python.updateSparkLibrary",
63+
"onCommand:python.startREPL"
6364
],
6465
"main": "./out/client/extension",
6566
"contributes": {

src/client/common/utils.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,17 @@ export function getPythonInterpreterDirectory(): Promise<string> {
8181
return pythonInterpretterDirectory = '';
8282
});
8383
}
84+
export function getPathFromPythonCommand(args: string[]): Promise<string> {
85+
return execPythonFile(settings.PythonSettings.getInstance().pythonPath, args, __dirname).then(stdout => {
86+
if (stdout.length === 0) {
87+
return "";
88+
}
89+
let lines = stdout.split(/\r?\n/g).filter(line => line.length > 0);
90+
return validatePath(lines[0]);
91+
}).catch(() => {
92+
return "";
93+
});
94+
}
8495

8596
export function execPythonFile(file: string, args: string[], cwd: string, includeErrorAsResponse: boolean = false, stdOut: (line: string) => void = null, token?: CancellationToken): Promise<string> {
8697
// If running the python file, then always revert to execFileInternal

src/client/extension.ts

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { BlockFormatProviders } from './typeFormatters/blockFormatProvider';
2828
import * as os from 'os';
2929
import * as fs from 'fs';
3030
import { activateSingleFileDebug } from './singleFileDebug';
31+
import { getPathFromPythonCommand } from './common/utils';
3132

3233
const PYTHON: vscode.DocumentFilter = { language: 'python', scheme: 'file' };
3334
let unitTestOutChannel: vscode.OutputChannel;
@@ -63,9 +64,13 @@ export function activate(context: vscode.ExtensionContext) {
6364
context.subscriptions.push(activateFormatOnSaveProvider(PYTHON, settings.PythonSettings.getInstance(), formatOutChannel));
6465

6566
context.subscriptions.push(vscode.commands.registerCommand(Commands.Start_REPL, () => {
66-
let term = vscode.window.createTerminal('Python', pythonSettings.pythonPath);
67-
term.show();
68-
context.subscriptions.push(term);
67+
getPathFromPythonCommand(["-c", "import sys;print(sys.executable)"]).catch(()=>{
68+
return pythonSettings.pythonPath;
69+
}).then(pythonExecutablePath => {
70+
let term = vscode.window.createTerminal('Python', pythonExecutablePath);
71+
term.show();
72+
context.subscriptions.push(term);
73+
});
6974
}));
7075

7176
// Enable indentAction
@@ -136,7 +141,12 @@ class PythonExt {
136141

137142
private _ensureState(): void {
138143
// context: python.isDjangoProject
139-
this._isDjangoProject.set(fs.existsSync(vscode.workspace.rootPath.concat("/manage.py")));
144+
if (typeof vscode.workspace.rootPath === 'string'){
145+
this._isDjangoProject.set(fs.existsSync(vscode.workspace.rootPath.concat("/manage.py")));
146+
}
147+
else {
148+
this._isDjangoProject.set(false);
149+
}
140150
}
141151
}
142152

0 commit comments

Comments
 (0)