diff --git a/src/client/pythonEnvironments/base/locators/common/nativePythonFinder.ts b/src/client/pythonEnvironments/base/locators/common/nativePythonFinder.ts index d0c258971f7b..256ea54b62ac 100644 --- a/src/client/pythonEnvironments/base/locators/common/nativePythonFinder.ts +++ b/src/client/pythonEnvironments/base/locators/common/nativePythonFinder.ts @@ -10,13 +10,8 @@ import { isWindows } from '../../../../common/platform/platformService'; import { EXTENSION_ROOT_DIR } from '../../../../constants'; import { createDeferred, createDeferredFrom } from '../../../../common/utils/async'; import { DisposableBase, DisposableStore } from '../../../../common/utils/resourceLifecycle'; -import { DEFAULT_INTERPRETER_PATH_SETTING_KEY } from '../lowLevel/customWorkspaceLocator'; import { noop } from '../../../../common/utils/misc'; -import { - getConfiguration, - getWorkspaceFolderPaths, - getWorkspaceFolders, -} from '../../../../common/vscodeApis/workspaceApis'; +import { getConfiguration, getWorkspaceFolderPaths } from '../../../../common/vscodeApis/workspaceApis'; import { CONDAPATH_SETTING_KEY } from '../../../common/environmentManagers/conda'; import { VENVFOLDERS_SETTING_KEY, VENVPATH_SETTING_KEY } from '../lowLevel/customVirtualEnvLocator'; import { getUserHomeDir } from '../../../../common/utils/platform'; @@ -76,14 +71,11 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba } public async resolve(executable: string): Promise { - const { environment, duration } = await this.connection.sendRequest<{ - duration: number; - environment: NativeEnvInfo; - }>('resolve', { + const environment = await this.connection.sendRequest('resolve', { executable, }); - this.outputChannel.info(`Resolved Python Environment ${environment.executable} in ${duration}ms`); + this.outputChannel.info(`Resolved Python Environment ${environment.executable}`); return environment; } @@ -93,22 +85,21 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba return PythonEnvKind.Conda; case 'system': case 'homebrew': - case 'mac-python-org': - case 'mac-command-line-tools': - case 'mac-xcode': - case 'windows-registry': - case 'linux-global': + case 'macpythonorg': + case 'maccommandlinetools': + case 'macxcode': + case 'windowsregistry': + case 'linuxglobal': return PythonEnvKind.System; - case 'global-paths': + case 'globalpaths': return PythonEnvKind.OtherGlobal; case 'pyenv': - case 'pyenv-other': return PythonEnvKind.Pyenv; case 'poetry': return PythonEnvKind.Poetry; case 'pipenv': return PythonEnvKind.Pipenv; - case 'pyenv-virtualenv': + case 'pyenvvirtualenv': return PythonEnvKind.VirtualEnv; case 'venv': return PythonEnvKind.Venv; @@ -116,7 +107,7 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba return PythonEnvKind.VirtualEnv; case 'virtualenvwrapper': return PythonEnvKind.VirtualEnvWrapper; - case 'windows-store': + case 'windowsstore': return PythonEnvKind.MicrosoftStore; case 'unknown': return PythonEnvKind.Unknown; @@ -309,11 +300,11 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba // HACK = TEMPORARY WORK AROUND, TO GET STUFF WORKING // HACK = TEMPORARY WORK AROUND, TO GET STUFF WORKING const promise = this.connection - .sendRequest<{ duration: number; environment: NativeEnvInfo }>('resolve', { + .sendRequest('resolve', { executable: data.executable, }) - .then(({ environment, duration }) => { - this.outputChannel.info(`Resolved ${environment.executable} in ${duration}ms`); + .then((environment) => { + this.outputChannel.info(`Resolved ${environment.executable}`); this.outputChannel.trace(`Environment resolved:\n ${JSON.stringify(data, undefined, 4)}`); discovered.fire(environment); }) @@ -326,7 +317,20 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba ); trackPromiseAndNotifyOnCompletion( - this.sendRefreshRequest() + this.connection + .sendRequest<{ duration: number }>( + 'refresh', + // Send configuration information to the Python finder. + { + // This has a special meaning in locator, its lot a low priority + // as we treat this as workspace folders that can contain a large number of files. + project_directories: getWorkspaceFolderPaths(), + // We do not want to mix this with `search_paths` + environment_directories: getCustomVirtualEnvDirs(), + conda_executable: getPythonSettingAndUntildify(CONDAPATH_SETTING_KEY), + poetry_executable: getPythonSettingAndUntildify('poetryPath'), + }, + ) .then(({ duration }) => this.outputChannel.info(`Refresh completed in ${duration}ms`)) .catch((ex) => this.outputChannel.error('Refresh error', ex)), ); @@ -337,47 +341,12 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba discovered: discovered.event, }; } - - private sendRefreshRequest() { - const pythonPathSettings = (getWorkspaceFolders() || []).map((w) => - getPythonSettingAndUntildify(DEFAULT_INTERPRETER_PATH_SETTING_KEY, w.uri), - ); - pythonPathSettings.push(getPythonSettingAndUntildify(DEFAULT_INTERPRETER_PATH_SETTING_KEY)); - // We can have multiple workspaces, each with its own setting. - const pythonSettings = Array.from( - new Set( - pythonPathSettings - .filter((item) => !!item) - // We only want the parent directories. - .map((p) => path.dirname(p!)) - /// If setting value is 'python', then `path.dirname('python')` will yield `.` - .filter((item) => item !== '.'), - ), - ); - - return this.connection.sendRequest<{ duration: number }>( - 'refresh', - // Send configuration information to the Python finder. - { - // This has a special meaning in locator, its lot a low priority - // as we treat this as workspace folders that can contain a large number of files. - search_paths: getWorkspaceFolderPaths(), - // Also send the python paths that are configured in the settings. - python_interpreter_paths: pythonSettings, - // We do not want to mix this with `search_paths` - virtual_env_paths: getCustomVirtualEnvDirs(), - conda_executable: getPythonSettingAndUntildify(CONDAPATH_SETTING_KEY), - poetry_executable: getPythonSettingAndUntildify('poetryPath'), - pipenv_executable: getPythonSettingAndUntildify('pipenvPath'), - }, - ); - } } /** * Gets all custom virtual environment locations to look for environments. */ -async function getCustomVirtualEnvDirs(): Promise { +function getCustomVirtualEnvDirs(): string[] { const venvDirs: string[] = []; const venvPath = getPythonSettingAndUntildify(VENVPATH_SETTING_KEY); if (venvPath) {