Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use node FS API while looking for paths.
  • Loading branch information
karthiknadig committed Apr 22, 2020
commit 888cc141db422026d8505dde76d9b79abe18837a
1 change: 1 addition & 0 deletions news/2 Fixes/10850.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Use node FS APIs when searching for python. This is a temporary change until VSC FS APIs are fixed.
13 changes: 9 additions & 4 deletions src/client/interpreter/locators/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import * as fsapi from 'fs';
import { inject, injectable } from 'inversify';
import * as path from 'path';
import { promisify } from 'util';
import { traceError } from '../../common/logger';
import { IS_WINDOWS } from '../../common/platform/constants';
import { IFileSystem } from '../../common/platform/types';
Expand All @@ -8,13 +10,16 @@ import { IPipEnvServiceHelper } from './types';

const CheckPythonInterpreterRegEx = IS_WINDOWS ? /^python(\d+(.\d+)?)?\.exe$/ : /^python(\d+(.\d+)?)?$/;

export async function lookForInterpretersInDirectory(pathToCheck: string, fs: IFileSystem): Promise<string[]> {
export async function lookForInterpretersInDirectory(pathToCheck: string, _: IFileSystem): Promise<string[]> {
// Technically, we should be able to use fs.getFiles(). However,
// that breaks some tests. So we stick with the broader behavior.
try {
const subDirs = await fs.listdir(pathToCheck);
return subDirs
.map(([filename, _ft]) => filename)
// tslint:disable-next-line: no-suspicious-comment
// TODO https://github.com/microsoft/vscode-python/issues/11338
const readdir = promisify(fsapi.readdir);
Comment thread
karthiknadig marked this conversation as resolved.
Outdated
const files = await readdir(pathToCheck);
Comment thread
karthiknadig marked this conversation as resolved.
Outdated
return files
.map((filename) => path.join(pathToCheck, filename))
.filter((fileName) => CheckPythonInterpreterRegEx.test(path.basename(fileName)));
} catch (err) {
traceError('Python Extension (lookForInterpretersInDirectory.fs.listdir):', err);
Expand Down