From 32f3d0b31e398938a83fe297a965c5b5f808e00a Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Thu, 7 Nov 2024 15:39:04 +1100 Subject: [PATCH] Hide envs before looking for recommendations (#16206) --- .../kernelSource/localPythonKernelSelector.node.ts | 2 +- .../controllers/preferredKernelConnectionService.node.ts | 9 +++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/notebooks/controllers/kernelSource/localPythonKernelSelector.node.ts b/src/notebooks/controllers/kernelSource/localPythonKernelSelector.node.ts index a9fcb6eb17a..ce124c2ea37 100644 --- a/src/notebooks/controllers/kernelSource/localPythonKernelSelector.node.ts +++ b/src/notebooks/controllers/kernelSource/localPythonKernelSelector.node.ts @@ -103,7 +103,7 @@ export class LocalPythonKernelSelector extends DisposableBase { if (!this.pythonApi || token.isCancellationRequested) { return; } - this.pythonEnvPicker.recommended = findPreferredPythonEnvironment(this.notebook, this.pythonApi); + this.pythonEnvPicker.recommended = findPreferredPythonEnvironment(this.notebook, this.pythonApi, filter); }; const setupApi = (api?: PythonExtension) => { if (!api) { diff --git a/src/notebooks/controllers/preferredKernelConnectionService.node.ts b/src/notebooks/controllers/preferredKernelConnectionService.node.ts index 32c99725d66..9ae3281bf8a 100644 --- a/src/notebooks/controllers/preferredKernelConnectionService.node.ts +++ b/src/notebooks/controllers/preferredKernelConnectionService.node.ts @@ -7,13 +7,18 @@ import { isParentPath } from '../../platform/common/platform/fileUtils'; import { EnvironmentType } from '../../platform/pythonEnvironments/info'; import { getEnvironmentType } from '../../platform/interpreter/helpers'; import { Environment, PythonExtension } from '@vscode/python-extension'; +import type { PythonEnvironmentFilter } from '../../platform/interpreter/filter/filterService'; export function findPreferredPythonEnvironment( notebook: NotebookDocument, - pythonApi: PythonExtension + pythonApi: PythonExtension, + filter: PythonEnvironmentFilter ): Environment | undefined { // 1. Check if we have a .conda or .venv virtual env in the local workspace folder. - const localEnv = findPythonEnvironmentClosestToNotebook(notebook, pythonApi.environments.known); + const localEnv = findPythonEnvironmentClosestToNotebook( + notebook, + pythonApi.environments.known.filter((e) => !filter.isPythonEnvironmentExcluded(e)) + ); if (localEnv) { return localEnv; }