From 10786470dd71e352822b954ed551d9e307db35ae Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Thu, 2 Feb 2023 15:14:32 +0530 Subject: [PATCH 1/3] Do not recommend Python2 as an interpreter --- .../interpreter/configuration/environmentTypeComparer.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/client/interpreter/configuration/environmentTypeComparer.ts b/src/client/interpreter/configuration/environmentTypeComparer.ts index e3c77a6b2d6d..992e910d8fc5 100644 --- a/src/client/interpreter/configuration/environmentTypeComparer.ts +++ b/src/client/interpreter/configuration/environmentTypeComparer.ts @@ -100,6 +100,9 @@ export class EnvironmentTypeComparer implements IInterpreterComparer { // We're not sure if these envs were created for the workspace, so do not recommend them. return false; } + if (i.version?.major === 2) { + return false; + } return true; }); filteredInterpreters.sort(this.compare.bind(this)); From bc5a0db1072ed92b763828f1e7df05f192fdd9b4 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 3 Feb 2023 12:57:49 +0530 Subject: [PATCH 2/3] Do not use `-I` flag for Python 2.7 --- .../base/info/environmentInfoService.ts | 23 ++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/src/client/pythonEnvironments/base/info/environmentInfoService.ts b/src/client/pythonEnvironments/base/info/environmentInfoService.ts index 565be30acf94..9dfc88bb745d 100644 --- a/src/client/pythonEnvironments/base/info/environmentInfoService.ts +++ b/src/client/pythonEnvironments/base/info/environmentInfoService.ts @@ -37,8 +37,16 @@ export interface IEnvironmentInfoService { resetInfo(searchLocation: Uri): void; } -async function buildEnvironmentInfo(env: PythonEnvInfo): Promise { - const python = [env.executable.filename, '-I', OUTPUT_MARKER_SCRIPT]; +async function buildEnvironmentInfo( + env: PythonEnvInfo, + useIsolated = true, +): Promise { + 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; } @@ -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; @@ -161,6 +169,15 @@ class EnvironmentInfoService implements IEnvironmentInfoService { return undefined; }); } else if (reason) { + if (reason.message.includes('Unknown option: -I')) { + 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); } } From 61ebf02831ce8eb0c43d216cfd8d2c14e8f53ad8 Mon Sep 17 00:00:00 2001 From: Kartik Raj Date: Fri, 3 Feb 2023 12:59:46 +0530 Subject: [PATCH 3/3] Revert "Do not recommend Python2 as an interpreter" This reverts commit 10786470dd71e352822b954ed551d9e307db35ae. --- .../interpreter/configuration/environmentTypeComparer.ts | 3 --- .../pythonEnvironments/base/info/environmentInfoService.ts | 3 ++- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/client/interpreter/configuration/environmentTypeComparer.ts b/src/client/interpreter/configuration/environmentTypeComparer.ts index 992e910d8fc5..e3c77a6b2d6d 100644 --- a/src/client/interpreter/configuration/environmentTypeComparer.ts +++ b/src/client/interpreter/configuration/environmentTypeComparer.ts @@ -100,9 +100,6 @@ export class EnvironmentTypeComparer implements IInterpreterComparer { // We're not sure if these envs were created for the workspace, so do not recommend them. return false; } - if (i.version?.major === 2) { - return false; - } return true; }); filteredInterpreters.sort(this.compare.bind(this)); diff --git a/src/client/pythonEnvironments/base/info/environmentInfoService.ts b/src/client/pythonEnvironments/base/info/environmentInfoService.ts index 9dfc88bb745d..180e243ae710 100644 --- a/src/client/pythonEnvironments/base/info/environmentInfoService.ts +++ b/src/client/pythonEnvironments/base/info/environmentInfoService.ts @@ -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'; @@ -170,6 +170,7 @@ class EnvironmentInfoService implements IEnvironmentInfoService { }); } 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.', );