Skip to content

Commit f5fae81

Browse files
karthiknadigDonJayamanne
authored andcommitted
Add python.nativeLocator experimental setting (#23324)
Adds a setting to switch between `native` and `js` locators.
1 parent fefa070 commit f5fae81

File tree

3 files changed

+44
-21
lines changed

3 files changed

+44
-21
lines changed

package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,19 @@
550550
"experimental"
551551
]
552552
},
553+
"python.nativeLocator": {
554+
"default": "js",
555+
"description": "%python.nativeLocator.description%",
556+
"enum": [
557+
"js",
558+
"native"
559+
],
560+
"tags": [
561+
"experimental"
562+
],
563+
"scope": "machine",
564+
"type": "string"
565+
},
553566
"python.pipenvPath": {
554567
"default": "pipenv",
555568
"description": "%python.pipenvPath.description%",

package.nls.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
"python.logging.level.description": "The logging level the extension logs at, defaults to 'error'",
5858
"python.logging.level.deprecation": "This setting is deprecated. Please use command `Developer: Set Log Level...` to set logging level.",
5959
"python.missingPackage.severity.description": "Set severity of missing packages in requirements.txt or pyproject.toml",
60+
"python.nativeLocator.description": "[Experimental] Select implementation of environment locators. This is an experimental setting while we test native environment location.",
6061
"python.pipenvPath.description": "Path to the pipenv executable to use for activation.",
6162
"python.poetryPath.description": "Path to the poetry executable.",
6263
"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 @@
162163
"walkthrough.step.python.createNewNotebook.altText": "Creating a new Jupyter notebook",
163164
"walkthrough.step.python.openInteractiveWindow.altText": "Opening Python interactive window",
164165
"walkthrough.step.python.dataScienceLearnMore.altText": "Image representing our documentation page and mailing list resources."
165-
}
166+
}

src/client/pythonEnvironments/index.ts

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import {
1919
} from './common/externalDependencies';
2020
import { ExtensionLocators, WatchRootsArgs, WorkspaceLocators } from './base/locators/wrappers';
2121
import { CustomVirtualEnvironmentLocator } from './base/locators/lowLevel/customVirtualEnvLocator';
22-
// import { CondaEnvironmentLocator } from './base/locators/lowLevel/condaLocator';
22+
import { CondaEnvironmentLocator } from './base/locators/lowLevel/condaLocator';
2323
import { GlobalVirtualEnvironmentLocator } from './base/locators/lowLevel/globalVirtualEnvronmentLocator';
2424
import { PosixKnownPathsLocator } from './base/locators/lowLevel/posixKnownPathsLocator';
2525
import { PyenvLocator } from './base/locators/lowLevel/pyenvLocator';
@@ -40,6 +40,7 @@ import { traceError } from '../logging';
4040
import { ActiveStateLocator } from './base/locators/lowLevel/activeStateLocator';
4141
import { CustomWorkspaceLocator } from './base/locators/lowLevel/customWorkspaceLocator';
4242
import { NativeLocator } from './base/locators/lowLevel/nativeLocator';
43+
import { getConfiguration } from '../common/vscodeApis/workspaceApis';
4344

4445
const PYTHON_ENV_INFO_CACHE_KEY = 'PYTHON_ENV_INFO_CACHEv2';
4546

@@ -137,30 +138,38 @@ async function createLocator(
137138
return caching;
138139
}
139140

141+
function useNativeLocator(): boolean {
142+
const config = getConfiguration('python');
143+
return config.get<string>('nativeLocator', 'js') === 'native';
144+
}
145+
140146
function createNonWorkspaceLocators(ext: ExtensionState): ILocator<BasicEnvInfo>[] {
141147
const locators: (ILocator<BasicEnvInfo> & Partial<IDisposable>)[] = [];
142-
locators.push(
143-
// OS-independent locators go here.
144-
new PyenvLocator(),
145-
// new CondaEnvironmentLocator(),
146-
new ActiveStateLocator(),
147-
new GlobalVirtualEnvironmentLocator(),
148-
new CustomVirtualEnvironmentLocator(),
149-
new NativeLocator(),
150-
);
151-
152-
if (getOSType() === OSType.Windows) {
153-
locators.push(
154-
// Windows specific locators go here.
155-
new WindowsRegistryLocator(),
156-
new MicrosoftStoreLocator(),
157-
new WindowsPathEnvVarLocator(),
158-
);
148+
if (useNativeLocator()) {
149+
locators.push(new NativeLocator());
159150
} else {
160151
locators.push(
161-
// Linux/Mac locators go here.
162-
new PosixKnownPathsLocator(),
152+
// OS-independent locators go here.
153+
new PyenvLocator(),
154+
new CondaEnvironmentLocator(),
155+
new ActiveStateLocator(),
156+
new GlobalVirtualEnvironmentLocator(),
157+
new CustomVirtualEnvironmentLocator(),
163158
);
159+
160+
if (getOSType() === OSType.Windows) {
161+
locators.push(
162+
// Windows specific locators go here.
163+
new WindowsRegistryLocator(),
164+
new MicrosoftStoreLocator(),
165+
new WindowsPathEnvVarLocator(),
166+
);
167+
} else {
168+
locators.push(
169+
// Linux/Mac locators go here.
170+
new PosixKnownPathsLocator(),
171+
);
172+
}
164173
}
165174

166175
const disposables = locators.filter((d) => d.dispose !== undefined) as IDisposable[];

0 commit comments

Comments
 (0)