Skip to content

Commit

Permalink
Allow to select a Python2.7 interpreter (#20639)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kartik Raj authored Feb 3, 2023
1 parent 9271136 commit 1538833
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions src/client/pythonEnvironments/base/info/environmentInfoService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { createDeferred, Deferred, sleep } from '../../../common/utils/async';
import { createRunningWorkerPool, IWorkerPool, QueuePosition } from '../../../common/utils/workerPool';
import { getInterpreterInfo, InterpreterInformation } from './interpreter';
import { buildPythonExecInfo } from '../../exec';
import { traceError, traceInfo } from '../../../logging';
import { traceError, traceInfo, traceWarn } from '../../../logging';
import { Conda, CONDA_ACTIVATION_TIMEOUT, isCondaEnvironment } from '../../common/environmentManagers/conda';
import { PythonEnvInfo, PythonEnvKind } from '.';
import { normCasePath } from '../../common/externalDependencies';
Expand Down Expand Up @@ -37,8 +37,16 @@ export interface IEnvironmentInfoService {
resetInfo(searchLocation: Uri): void;
}

async function buildEnvironmentInfo(env: PythonEnvInfo): Promise<InterpreterInformation | undefined> {
const python = [env.executable.filename, '-I', OUTPUT_MARKER_SCRIPT];
async function buildEnvironmentInfo(
env: PythonEnvInfo,
useIsolated = true,
): Promise<InterpreterInformation | undefined> {
const python = [env.executable.filename];
if (useIsolated) {
python.push(...['-I', OUTPUT_MARKER_SCRIPT]);
} else {
python.push(...[OUTPUT_MARKER_SCRIPT]);
}
const interpreterInfo = await getInterpreterInfo(buildPythonExecInfo(python, undefined, env.executable.filename));
return interpreterInfo;
}
Expand Down Expand Up @@ -134,7 +142,7 @@ class EnvironmentInfoService implements IEnvironmentInfoService {
);
}

let reason: unknown;
let reason: Error | undefined;
let r = await addToQueue(this.workerPool, env, priority).catch((err) => {
reason = err;
return undefined;
Expand All @@ -161,6 +169,16 @@ class EnvironmentInfoService implements IEnvironmentInfoService {
return undefined;
});
} else if (reason) {
if (reason.message.includes('Unknown option: -I')) {
traceWarn(reason);
traceError(
'Support for Python 2.7 has been dropped by the Python extension so certain features may not work, upgrade to using Python 3.',
);
return buildEnvironmentInfo(env, false).catch((err) => {
traceError(err);
return undefined;
});
}
traceError(reason);
}
}
Expand Down

0 comments on commit 1538833

Please sign in to comment.