Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 3 additions & 3 deletions src/client/pythonEnvironments/common/commonUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import { comparePythonVersionSpecificity } from '../base/info/env';
import { parseVersion } from '../base/info/pythonVersion';
import { getPythonVersionFromConda } from '../discovery/locators/services/conda';
import { getPythonVersionFromPyvenvCfg } from '../discovery/locators/services/virtualEnvironmentIdentifier';
import { isPosixPythonBin } from './posixUtils';
import { isPosixPythonBinPattern } from './posixUtils';
import { isWindowsPythonExe } from './windowsUtils';

const matchPythonExecutable = getOSType() === OSType.Windows ? isWindowsPythonExe : isPosixPythonBin;
const matchPythonExecutable = getOSType() === OSType.Windows ? isWindowsPythonExe : isPosixPythonBinPattern;

type FileFilterFunc = (filename: string) => boolean;

Expand All @@ -33,7 +33,7 @@ export async function* findInterpretersInDir(
): AsyncIterableIterator<string> {
// "checkBin" is a local variable rather than global
// so we can stub it out during unit testing.
const checkBin = getOSType() === OSType.Windows ? isWindowsPythonExe : isPosixPythonBin;
const checkBin = getOSType() === OSType.Windows ? isWindowsPythonExe : isPosixPythonBinPattern;
const cfg = {
ignoreErrors,
filterSubDir,
Expand Down
2 changes: 1 addition & 1 deletion src/client/pythonEnvironments/common/posixUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { getSearchPathEntries } from '../../common/utils/exec';
* @param {string} interpreterPath : Path to python interpreter.
* @returns {boolean} : Returns true if the path matches pattern for windows python executable.
*/
export function isPosixPythonBin(interpreterPath: string): boolean {
export function isPosixPythonBinPattern(interpreterPath: string): boolean {
/**
* This Reg-ex matches following file names:
* python
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

import * as fsapi from 'fs-extra';
import * as fs from 'fs';
import * as path from 'path';
import { traceError, traceInfo } from '../../../../common/logger';

Expand All @@ -11,23 +11,24 @@ import { buildEnvInfo } from '../../../base/info/env';
import { parseVersion } from '../../../base/info/pythonVersion';
import { IPythonEnvsIterator, Locator } from '../../../base/locator';
import { getFileInfo, resolveSymbolicLink } from '../../../common/externalDependencies';
import { commonPosixBinPaths, isPosixPythonBin } from '../../../common/posixUtils';
import { commonPosixBinPaths, isPosixPythonBinPattern } from '../../../common/posixUtils';

async function getPythonBinFromKnownPaths(): Promise<string[]> {
const knownPaths = await commonPosixBinPaths();
const knownDirs = await commonPosixBinPaths();
const pythonBins: Set<string> = new Set();
for (const knownPath of knownPaths) {
const files = (await fsapi.readdir(knownPath))
.map((filename: string) => path.join(knownPath, filename))
.filter(isPosixPythonBin);
for (const dirname of knownDirs) {
const paths = (await fs.promises.readdir(dirname, { withFileTypes: true }))
.filter((dirent: fs.Dirent) => !dirent.isDirectory())
.map((dirent: fs.Dirent) => path.join(dirname, dirent.name))
.filter(isPosixPythonBinPattern);

for (const file of files) {
for (const filepath of paths) {
// Ensure that we have a collection of unique global binaries by
// resolving all symlinks to the target binaries.
try {
const resolvedBin = await resolveSymbolicLink(file);
const resolvedBin = await resolveSymbolicLink(filepath);
pythonBins.add(resolvedBin);
traceInfo(`Found: ${file} --> ${resolvedBin}`);
traceInfo(`Found: ${filepath} --> ${resolvedBin}`);
} catch (ex) {
traceError('Failed to resolve symbolic link: ', ex);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
this is intentionally empty