Skip to content

Commit 0f351a7

Browse files
author
himanoa
committed
Added support for virtualenv
1 parent 769b3b8 commit 0f351a7

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/client/common/configSettings.ts

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22

33
import * as vscode from 'vscode';
4+
import * as path from 'path';
5+
import * as fs from 'fs';
46

57
export interface IPythonSettings {
68
pythonPath: string;
@@ -49,12 +51,23 @@ export class PythonSettings implements IPythonSettings {
4951

5052
this.initializeSettings();
5153
}
52-
54+
private getVirtualenvPath() {
55+
var currentPath: string = vscode.workspace.rootPath;
56+
if (process.platform == 'win32') {
57+
var bin: string = "Scripts";
58+
var _path: string = path.join(currentPath, bin, "python.exe");
59+
}
60+
else {
61+
var bin: string = "bin";
62+
var _path: string = path.join(currentPath, bin, "python");
63+
}
64+
return fs.existsSync(_path)
65+
? _path
66+
: this.pythonPath;
67+
}
5368
private initializeSettings() {
5469
var pythonSettings = vscode.workspace.getConfiguration("python");
55-
56-
this.pythonPath = pythonSettings.get<string>("pythonPath");
57-
70+
this.pythonPath = this.getVirtualenvPath()
5871
var lintingSettings = pythonSettings.get<ILintingSettings>("linting");
5972
if (this.linting) {
6073
Object.assign<ILintingSettings, ILintingSettings>(this.linting, lintingSettings);

src/client/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@
144144
"dependencies": {
145145
"named-js-regexp": "^1.3.1",
146146
"tmp": "0.0.28",
147+
"path": "0.12.7",
147148
"uint64be": "^1.0.1",
148149
"vscode-debugadapter": "^1.0.1",
149150
"vscode-debugprotocol": "^1.0.1",

0 commit comments

Comments
 (0)