Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent posix paths locator from crashing #21657

Merged
merged 1 commit into from
Jul 19, 2023
Merged
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
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