Skip to content

Commit

Permalink
Fixes #56 list all environments (#219)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne authored Nov 15, 2017
1 parent a48959d commit 7b0838b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 14 deletions.
15 changes: 7 additions & 8 deletions src/client/common/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,16 +413,15 @@ export function getWindowsLineEndingCount(document: TextDocument, offset: Number
}

export function arePathsSame(path1: string, path2: string) {
path1 = IS_WINDOWS ? path1.replace(/\//g, "\\") : path1;
path2 = IS_WINDOWS ? path2.replace(/\//g, "\\") : path2;
return path1.toUpperCase() === path2.toUpperCase();
path1 = path.normalize(path1);
path2 = path.normalize(path2);
if (IS_WINDOWS) {
return path1.toUpperCase() === path2.toUpperCase();
} else {
return path1 === path2;
}
}

export function areBasePathsSame(path1: string, path2: string) {
path1 = IS_WINDOWS ? path1.replace(/\//g, "\\") : path1;
path2 = IS_WINDOWS ? path2.replace(/\//g, "\\") : path2;
return path.dirname(path1).toUpperCase() === path.dirname(path2).toUpperCase();
}
export async function getInterpreterVersion(pythonPath: string) {
return await new Promise<string>((resolve, reject) => {
child_process.execFile(pythonPath, ['--version'], (error, stdout, stdErr) => {
Expand Down
9 changes: 4 additions & 5 deletions src/client/interpreter/locators/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
import * as _ from 'lodash';
import { Disposable, Uri, workspace } from 'vscode';
import { RegistryImplementation } from '../../common/registry';
import { areBasePathsSame, arePathsSame, Is_64Bit, IS_WINDOWS } from '../../common/utils';
import { arePathsSame, Is_64Bit, IS_WINDOWS } from '../../common/utils';
import { IInterpreterLocatorService, PythonInterpreter } from '../contracts';
import { IInterpreterVersionService, InterpreterVersionService } from '../interpreterVersion';
import { InterpreterVersionService } from '../interpreterVersion';
import { VirtualEnvironmentManager } from '../virtualEnvs';
import { fixInterpreterDisplayName, fixInterpreterPath } from './helpers';
import { CondaEnvFileService, getEnvironmentsFile as getCondaEnvFile } from './services/condaEnvFileService';
Expand Down Expand Up @@ -46,16 +46,15 @@ export class PythonInterpreterLocatorService implements IInterpreterLocatorServi
}
private async getInterpretersPerResource(resource?: Uri) {
const locators = this.getLocators(resource);
const promises = locators.map(provider => provider.getInterpreters(resource));
const promises = locators.map(async provider => provider.getInterpreters(resource));
const listOfInterpreters = await Promise.all(promises);

// tslint:disable-next-line:underscore-consistent-invocation
return _.flatten(listOfInterpreters)
.map(fixInterpreterDisplayName)
.map(fixInterpreterPath)
.reduce<PythonInterpreter[]>((accumulator, current) => {
if (accumulator.findIndex(item => arePathsSame(item.path, current.path)) === -1 &&
accumulator.findIndex(item => areBasePathsSame(item.path, current.path)) === -1) {
if (accumulator.findIndex(item => arePathsSame(item.path, current.path)) === -1) {
accumulator.push(current);
}
return accumulator;
Expand Down
3 changes: 2 additions & 1 deletion tslint.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"Thenable",
"PromiseLike"
],
"completed-docs": false
"completed-docs": false,
"no-unsafe-any": false
}
}

0 comments on commit 7b0838b

Please sign in to comment.