Skip to content

Commit 5080b06

Browse files
Fix a test by using the old listdir behavior.
1 parent 260c114 commit 5080b06

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

src/client/common/platform/fileSystem.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,18 @@ export class FileSystem implements IFileSystem {
8080
return deferred.promise;
8181
}
8282

83+
public async listdir(root: string): Promise<string[]> {
84+
return new Promise<string[]>(resolve => {
85+
// Now look for Interpreters in this directory
86+
fs.readdir(root, (err, names) => {
87+
if (err) {
88+
return resolve([]);
89+
}
90+
resolve(names.map(name => path.join(root, name)));
91+
});
92+
});
93+
}
94+
8395
public getSubDirectories(rootDir: string): Promise<string[]> {
8496
return new Promise<string[]>(resolve => {
8597
fs.readdir(rootDir, async (error, files) => {

src/client/common/platform/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ export interface IFileSystem {
4747
directoryExists(path: string): Promise<boolean>;
4848
createDirectory(path: string): Promise<void>;
4949
deleteDirectory(path: string): Promise<void>;
50+
listdir(dirname: string): Promise<string[]>;
5051
getSubDirectories(rootDir: string): Promise<string[]>;
5152
getFiles(rootDir: string): Promise<string[]>;
5253
arePathsSame(path1: string, path2: string): boolean;

src/client/interpreter/locators/helpers.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,12 @@ import { IPipEnvServiceHelper } from './types';
99
const CheckPythonInterpreterRegEx = IS_WINDOWS ? /^python(\d+(.\d+)?)?\.exe$/ : /^python(\d+(.\d+)?)?$/;
1010

1111
export function lookForInterpretersInDirectory(pathToCheck: string, fs: IFileSystem): Promise<string[]> {
12-
return fs.getFiles(pathToCheck)
12+
// Technically, we should be able to use fs.getFiles(). However,
13+
// that breaks some tests. So we stick with the broader behavior.
14+
return fs.listdir(pathToCheck)
1315
.then(subDirs => subDirs.filter(fileName => CheckPythonInterpreterRegEx.test(path.basename(fileName))))
1416
.catch(err => {
15-
traceError('Python Extension (lookForInterpretersInDirectory.fs.getFiles):', err);
17+
traceError('Python Extension (lookForInterpretersInDirectory.fs.listdir):', err);
1618
return [] as string[];
1719
});
1820
}

src/test/interpreters/locators/workspaceVirtualEnvService.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ suite('Interpreters - Workspace VirtualEnv Service', function() {
8080
this.retries(0);
8181

8282
const workspaceUri = IS_MULTI_ROOT_TEST ? Uri.file(path.join(multirootPath, 'workspace3')) : rootWorkspaceUri!;
83+
// "workspace4 does not exist.
8384
const workspace4 = Uri.file(path.join(multirootPath, 'workspace4'));
8485
const venvs = new Venvs(workspaceUri.fsPath);
8586

0 commit comments

Comments
 (0)