Skip to content

Commit

Permalink
fix #692
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne committed Feb 2, 2017
1 parent 72a7fa5 commit 226a1f8
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@
"onCommand:jupyter.execCurrentCellAndAdvance",
"onCommand:python.displayHelp",
"onCommand:python.buildWorkspaceSymbols",
"onCommand:python.updateSparkLibrary"
"onCommand:python.updateSparkLibrary",
"onCommand:python.startREPL"
],
"main": "./out/client/extension",
"contributes": {
Expand Down
11 changes: 11 additions & 0 deletions src/client/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,17 @@ export function getPythonInterpreterDirectory(): Promise<string> {
return pythonInterpretterDirectory = '';
});
}
export function getPathFromPythonCommand(args: string[]): Promise<string> {
return execPythonFile(settings.PythonSettings.getInstance().pythonPath, args, __dirname).then(stdout => {
if (stdout.length === 0) {
return "";
}
let lines = stdout.split(/\r?\n/g).filter(line => line.length > 0);
return validatePath(lines[0]);
}).catch(() => {
return "";
});
}

export function execPythonFile(file: string, args: string[], cwd: string, includeErrorAsResponse: boolean = false, stdOut: (line: string) => void = null, token?: CancellationToken): Promise<string> {
// If running the python file, then always revert to execFileInternal
Expand Down
18 changes: 14 additions & 4 deletions src/client/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { BlockFormatProviders } from './typeFormatters/blockFormatProvider';
import * as os from 'os';
import * as fs from 'fs';
import { activateSingleFileDebug } from './singleFileDebug';
import { getPathFromPythonCommand } from './common/utils';

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

context.subscriptions.push(vscode.commands.registerCommand(Commands.Start_REPL, () => {
let term = vscode.window.createTerminal('Python', pythonSettings.pythonPath);
term.show();
context.subscriptions.push(term);
getPathFromPythonCommand(["-c", "import sys;print(sys.executable)"]).catch(()=>{
return pythonSettings.pythonPath;
}).then(pythonExecutablePath => {
let term = vscode.window.createTerminal('Python', pythonExecutablePath);
term.show();
context.subscriptions.push(term);
});
}));

// Enable indentAction
Expand Down Expand Up @@ -136,7 +141,12 @@ class PythonExt {

private _ensureState(): void {
// context: python.isDjangoProject
this._isDjangoProject.set(fs.existsSync(vscode.workspace.rootPath.concat("/manage.py")));
if (typeof vscode.workspace.rootPath === 'string'){
this._isDjangoProject.set(fs.existsSync(vscode.workspace.rootPath.concat("/manage.py")));
}
else {
this._isDjangoProject.set(false);
}
}
}

Expand Down

0 comments on commit 226a1f8

Please sign in to comment.