Skip to content

Commit 3811be1

Browse files
committed
fix #569
1 parent 0eeaf0b commit 3811be1

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -854,6 +854,11 @@
854854
"default": "python",
855855
"description": "Path to Python, you can use a custom version of Python by modifying this setting to include the full path."
856856
},
857+
"python.venvPath": {
858+
"type": "string",
859+
"default": "",
860+
"description": "Path to folder with a list of Virtual Environments (e.g. ~/.pyenv, ~/Envs, ~/.virtualenvs)."
861+
},
857862
"python.envFile": {
858863
"type": "string",
859864
"description": "Absolute path to a file containing environment variable definitions.",

src/client/common/configSettings.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export const IS_WINDOWS = /^win/.test(process.platform);
1010

1111
export interface IPythonSettings {
1212
pythonPath: string;
13+
venvPath: string;
1314
jediPath: string;
1415
devOptions: string[];
1516
linting: ILintingSettings;
@@ -134,6 +135,7 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
134135
let pythonSettings = vscode.workspace.getConfiguration('python');
135136
this.pythonPath = systemVariables.resolveAny(pythonSettings.get<string>('pythonPath'));
136137
this.pythonPath = getAbsolutePath(this.pythonPath, IS_TEST_EXECUTION ? __dirname : workspaceRoot);
138+
this.venvPath = systemVariables.resolveAny(pythonSettings.get<string>('venvPath'));
137139
this.jediPath = systemVariables.resolveAny(pythonSettings.get<string>('jediPath'));
138140
if (typeof this.jediPath === 'string' && this.jediPath.length > 0) {
139141
this.jediPath = getAbsolutePath(this.jediPath, IS_TEST_EXECUTION ? __dirname : workspaceRoot);
@@ -308,6 +310,7 @@ export class PythonSettings extends EventEmitter implements IPythonSettings {
308310
}
309311
public jediPath: string;
310312
public envFile: string;
313+
public venvPath: string;
311314
public devOptions: string[];
312315
public linting: ILintingSettings;
313316
public formatting: IFormattingSettings;

src/client/providers/setInterpreterProvider.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ function getSearchPaths(): Promise<string[]> {
2929
localAppData, appData,
3030
process.env['SystemDrive']];
3131
if (appData) {
32-
lookupParentDirectories.push(path.join(localAppData, 'Programs'))
32+
lookupParentDirectories.push(path.join(localAppData, 'Programs'));
3333
}
3434
if (localAppData) {
35-
lookupParentDirectories.push(path.join(appData, 'Programs'))
35+
lookupParentDirectories.push(path.join(appData, 'Programs'));
36+
}
37+
if (settings.PythonSettings.getInstance().venvPath) {
38+
lookupParentDirectories.push(settings.PythonSettings.getInstance().venvPath);
3639
}
3740
const dirPromises = lookupParentDirectories.map(rootDir => {
3841
if (!rootDir) {
@@ -64,12 +67,15 @@ function getSearchPaths(): Promise<string[]> {
6467
return validPathsCollection.reduce((previousValue, currentValue) => previousValue.concat(currentValue), []);
6568
});
6669
} else {
67-
const paths = ['/usr/local/bin', '/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/sbin'];
70+
const paths = ['/usr/local/bin', '/usr/bin', '/bin', '/usr/sbin', '/sbin', '/usr/local/sbin', '/Envs', '/.virtualenvs', '/.pyenv'];
6871
// Add support for paths such as /Users/xxx/anaconda/bin
6972
if (process.env['HOME']) {
7073
paths.push(path.join(process.env['HOME'], 'anaconda', 'bin'));
7174
paths.push(path.join(process.env['HOME'], 'python', 'bin'));
7275
}
76+
if (settings.PythonSettings.getInstance().venvPath) {
77+
paths.push(settings.PythonSettings.getInstance().venvPath);
78+
}
7379
return Promise.resolve(paths);
7480
}
7581
}
@@ -241,7 +247,7 @@ function presentQuickPickOfSuggestedPythonPaths() {
241247
}
242248

243249
function setInterpreter() {
244-
if (typeof vscode.workspace.rootPath !== 'string'){
250+
if (typeof vscode.workspace.rootPath !== 'string') {
245251
return vscode.window.showErrorMessage('Please open a workspace to select the Python Interpreter');
246252
}
247253
presentQuickPickOfSuggestedPythonPaths();

0 commit comments

Comments
 (0)