diff --git a/package.json b/package.json index 4e1dfea5e14e..a2fc9bd93004 100644 --- a/package.json +++ b/package.json @@ -550,6 +550,19 @@ "experimental" ] }, + "python.nativeLocator": { + "default": "js", + "description": "%python.nativeLocator.description%", + "enum": [ + "js", + "native" + ], + "tags": [ + "experimental" + ], + "scope": "machine", + "type": "string" + }, "python.pipenvPath": { "default": "pipenv", "description": "%python.pipenvPath.description%", diff --git a/package.nls.json b/package.nls.json index b88b04ab241f..536eab3e800d 100644 --- a/package.nls.json +++ b/package.nls.json @@ -57,6 +57,7 @@ "python.logging.level.description": "The logging level the extension logs at, defaults to 'error'", "python.logging.level.deprecation": "This setting is deprecated. Please use command `Developer: Set Log Level...` to set logging level.", "python.missingPackage.severity.description": "Set severity of missing packages in requirements.txt or pyproject.toml", + "python.nativeLocator.description": "[Experimental] Select implementation of environment locators. This is an experimental setting while we test native environment location.", "python.pipenvPath.description": "Path to the pipenv executable to use for activation.", "python.poetryPath.description": "Path to the poetry executable.", "python.EnableREPLSmartSend.description": "Toggle Smart Send for the Python REPL. Smart Send enables sending the smallest runnable block of code to the REPL on Shift+Enter and moves the cursor accordingly.", @@ -162,4 +163,4 @@ "walkthrough.step.python.createNewNotebook.altText": "Creating a new Jupyter notebook", "walkthrough.step.python.openInteractiveWindow.altText": "Opening Python interactive window", "walkthrough.step.python.dataScienceLearnMore.altText": "Image representing our documentation page and mailing list resources." -} \ No newline at end of file +} diff --git a/src/client/pythonEnvironments/index.ts b/src/client/pythonEnvironments/index.ts index b33425905a15..2b341dab0e9c 100644 --- a/src/client/pythonEnvironments/index.ts +++ b/src/client/pythonEnvironments/index.ts @@ -19,7 +19,7 @@ import { } from './common/externalDependencies'; import { ExtensionLocators, WatchRootsArgs, WorkspaceLocators } from './base/locators/wrappers'; import { CustomVirtualEnvironmentLocator } from './base/locators/lowLevel/customVirtualEnvLocator'; -// import { CondaEnvironmentLocator } from './base/locators/lowLevel/condaLocator'; +import { CondaEnvironmentLocator } from './base/locators/lowLevel/condaLocator'; import { GlobalVirtualEnvironmentLocator } from './base/locators/lowLevel/globalVirtualEnvronmentLocator'; import { PosixKnownPathsLocator } from './base/locators/lowLevel/posixKnownPathsLocator'; import { PyenvLocator } from './base/locators/lowLevel/pyenvLocator'; @@ -40,6 +40,7 @@ import { traceError } from '../logging'; import { ActiveStateLocator } from './base/locators/lowLevel/activeStateLocator'; import { CustomWorkspaceLocator } from './base/locators/lowLevel/customWorkspaceLocator'; import { NativeLocator } from './base/locators/lowLevel/nativeLocator'; +import { getConfiguration } from '../common/vscodeApis/workspaceApis'; const PYTHON_ENV_INFO_CACHE_KEY = 'PYTHON_ENV_INFO_CACHEv2'; @@ -137,30 +138,38 @@ async function createLocator( return caching; } +function useNativeLocator(): boolean { + const config = getConfiguration('python'); + return config.get('nativeLocator', 'js') === 'native'; +} + function createNonWorkspaceLocators(ext: ExtensionState): ILocator[] { const locators: (ILocator & Partial)[] = []; - locators.push( - // OS-independent locators go here. - new PyenvLocator(), - // new CondaEnvironmentLocator(), - new ActiveStateLocator(), - new GlobalVirtualEnvironmentLocator(), - new CustomVirtualEnvironmentLocator(), - new NativeLocator(), - ); - - if (getOSType() === OSType.Windows) { - locators.push( - // Windows specific locators go here. - new WindowsRegistryLocator(), - new MicrosoftStoreLocator(), - new WindowsPathEnvVarLocator(), - ); + if (useNativeLocator()) { + locators.push(new NativeLocator()); } else { locators.push( - // Linux/Mac locators go here. - new PosixKnownPathsLocator(), + // OS-independent locators go here. + new PyenvLocator(), + new CondaEnvironmentLocator(), + new ActiveStateLocator(), + new GlobalVirtualEnvironmentLocator(), + new CustomVirtualEnvironmentLocator(), ); + + if (getOSType() === OSType.Windows) { + locators.push( + // Windows specific locators go here. + new WindowsRegistryLocator(), + new MicrosoftStoreLocator(), + new WindowsPathEnvVarLocator(), + ); + } else { + locators.push( + // Linux/Mac locators go here. + new PosixKnownPathsLocator(), + ); + } } const disposables = locators.filter((d) => d.dispose !== undefined) as IDisposable[];