Skip to content

Commit

Permalink
Prevent posix paths locator from crashing (#21657)
Browse files Browse the repository at this point in the history
For #21310
  • Loading branch information
Kartik Raj authored Jul 19, 2023
1 parent 81ae205 commit c256678
Showing 1 changed file with 18 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,27 @@ export class PosixKnownPathsLocator extends Locator<BasicEnvInfo> {

const iterator = async function* (kind: PythonEnvKind) {
traceVerbose('Searching for interpreters in posix paths locator');
// Filter out pyenv shims. They are not actual python binaries, they are used to launch
// the binaries specified in .python-version file in the cwd. We should not be reporting
// those binaries as environments.
const knownDirs = (await commonPosixBinPaths()).filter((dirname) => !isPyenvShimDir(dirname));
let pythonBinaries = await getPythonBinFromPosixPaths(knownDirs);
try {
// Filter out pyenv shims. They are not actual python binaries, they are used to launch
// the binaries specified in .python-version file in the cwd. We should not be reporting
// those binaries as environments.
const knownDirs = (await commonPosixBinPaths()).filter((dirname) => !isPyenvShimDir(dirname));
let pythonBinaries = await getPythonBinFromPosixPaths(knownDirs);

// Filter out MacOS system installs of Python 2 if necessary.
if (isMacPython2Deprecated) {
pythonBinaries = pythonBinaries.filter((binary) => !isMacDefaultPythonPath(binary));
}
// Filter out MacOS system installs of Python 2 if necessary.
if (isMacPython2Deprecated) {
pythonBinaries = pythonBinaries.filter((binary) => !isMacDefaultPythonPath(binary));
}

for (const bin of pythonBinaries) {
try {
yield { executablePath: bin, kind, source: [PythonEnvSource.PathEnvVar] };
} catch (ex) {
traceError(`Failed to process environment: ${bin}`, ex);
for (const bin of pythonBinaries) {
try {
yield { executablePath: bin, kind, source: [PythonEnvSource.PathEnvVar] };
} catch (ex) {
traceError(`Failed to process environment: ${bin}`, ex);
}
}
} catch (ex) {
traceError('Failed to process posix paths', ex);
}
traceVerbose('Finished searching for interpreters in posix paths locator');
};
Expand Down

0 comments on commit c256678

Please sign in to comment.