Skip to content

Add python.nativeLocator experimental setting #23324

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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%",
Expand Down
3 changes: 2 additions & 1 deletion package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand Down Expand Up @@ -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."
}
}
49 changes: 29 additions & 20 deletions src/client/pythonEnvironments/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';

Expand Down Expand Up @@ -137,30 +138,38 @@ async function createLocator(
return caching;
}

function useNativeLocator(): boolean {
const config = getConfiguration('python');
return config.get<string>('nativeLocator', 'js') === 'native';
}

function createNonWorkspaceLocators(ext: ExtensionState): ILocator<BasicEnvInfo>[] {
const locators: (ILocator<BasicEnvInfo> & Partial<IDisposable>)[] = [];
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[];
Expand Down
Loading