From c47f3f1d8ddd335e3c2702d6f4f36965c24fd7b4 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sun, 8 Aug 2021 00:14:18 +0200 Subject: [PATCH 1/3] Fallback to path for environmentTypeComparer --- .../configuration/environmentTypeComparer.ts | 6 +++++- .../environmentTypeComparer.unit.test.ts | 12 ++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/client/interpreter/configuration/environmentTypeComparer.ts b/src/client/interpreter/configuration/environmentTypeComparer.ts index ac0eaae0cd9a..df7a46fd576f 100644 --- a/src/client/interpreter/configuration/environmentTypeComparer.ts +++ b/src/client/interpreter/configuration/environmentTypeComparer.ts @@ -168,7 +168,11 @@ function compareEnvironmentType(a: PythonEnvironment, b: PythonEnvironment, work export function getEnvTypeHeuristic(environment: PythonEnvironment, workspacePath: string): EnvTypeHeuristic { const { envType } = environment; - if (workspacePath.length > 0 && environment.envPath && isParentPath(environment.envPath, workspacePath)) { + if ( + workspacePath.length > 0 && + ((environment.envPath && isParentPath(environment.envPath, workspacePath)) || + (environment.path && isParentPath(environment.path, workspacePath))) + ) { return EnvTypeHeuristic.Local; } diff --git a/src/test/configuration/environmentTypeComparer.unit.test.ts b/src/test/configuration/environmentTypeComparer.unit.test.ts index ef4fc630e5f6..c52a2aea584d 100644 --- a/src/test/configuration/environmentTypeComparer.unit.test.ts +++ b/src/test/configuration/environmentTypeComparer.unit.test.ts @@ -266,6 +266,18 @@ suite('getEnvTypeHeuristic tests', () => { assert.strictEqual(envTypeHeuristic, EnvTypeHeuristic.Global); }); + + test('If envPath is not set, fallback to path', () => { + const environment = { + envType, + path: path.join(workspacePath, 'my-environment'), + version: { major: 3, minor: 10, patch: 2 }, + } as PythonEnvironment; + + const envTypeHeuristic = getEnvTypeHeuristic(environment, workspacePath); + + assert.strictEqual(envTypeHeuristic, EnvTypeHeuristic.Local); + }); }); const globalInterpretersEnvTypes = [ From 1226229359e2089454c891856c495cdb6faa5ad1 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Sun, 8 Aug 2021 00:44:14 +0200 Subject: [PATCH 2/3] Add news entry --- news/2 Fixes/16893.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/2 Fixes/16893.md diff --git a/news/2 Fixes/16893.md b/news/2 Fixes/16893.md new file mode 100644 index 000000000000..cb6d57d7899f --- /dev/null +++ b/news/2 Fixes/16893.md @@ -0,0 +1 @@ +Fix environment sorting for the `Python: Select Interpreter` command. From 39439e294f7cae4a431d4a3922a67fe4f7e58f55 Mon Sep 17 00:00:00 2001 From: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Date: Mon, 9 Aug 2021 06:35:24 +0200 Subject: [PATCH 3/3] Update news/2 Fixes/16893.md Co-authored-by: Karthik Nadig --- news/2 Fixes/16893.md | 1 + 1 file changed, 1 insertion(+) diff --git a/news/2 Fixes/16893.md b/news/2 Fixes/16893.md index cb6d57d7899f..39878f4ba792 100644 --- a/news/2 Fixes/16893.md +++ b/news/2 Fixes/16893.md @@ -1 +1,2 @@ Fix environment sorting for the `Python: Select Interpreter` command. +(thanks [Marc Mueller](https://github.com/cdce8p))