Skip to content

Commit 4855cd2

Browse files
committed
Remove native locator experiment and setting
1 parent 502ad70 commit 4855cd2

File tree

3 files changed

+5
-200
lines changed

3 files changed

+5
-200
lines changed

package.json

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -578,20 +578,6 @@
578578
"scope": "resource",
579579
"type": "string"
580580
},
581-
"python.locator": {
582-
"default": "js",
583-
"description": "%python.locator.description%",
584-
"enum": [
585-
"js",
586-
"native"
587-
],
588-
"tags": [
589-
"onExP",
590-
"preview"
591-
],
592-
"scope": "machine",
593-
"type": "string"
594-
},
595581
"python.pipenvPath": {
596582
"default": "pipenv",
597583
"description": "%python.pipenvPath.description%",

package.nls.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@
6363
"python.logging.level.description": "The logging level the extension logs at, defaults to 'error'",
6464
"python.logging.level.deprecation": "This setting is deprecated. Please use command `Developer: Set Log Level...` to set logging level.",
6565
"python.missingPackage.severity.description": "Set severity of missing packages in requirements.txt or pyproject.toml",
66-
"python.locator.description": "[Experimental] Select implementation of environment locators. This is an experimental setting while we test native environment location.",
6766
"python.pipenvPath.description": "Path to the pipenv executable to use for activation.",
6867
"python.poetryPath.description": "Path to the poetry executable.",
6968
"python.pixiToolPath.description": "Path to the pixi executable.",

src/client/pythonEnvironments/index.ts

Lines changed: 5 additions & 185 deletions
Original file line numberDiff line numberDiff line change
@@ -2,57 +2,22 @@
22
// Licensed under the MIT License.
33

44
import * as vscode from 'vscode';
5-
import { Uri } from 'vscode';
6-
import { cloneDeep } from 'lodash';
7-
import { getGlobalStorage, IPersistentStorage } from '../common/persistentState';
8-
import { getOSType, OSType } from '../common/utils/platform';
5+
import { getGlobalStorage } from '../common/persistentState';
96
import { ActivationResult, ExtensionState } from '../components';
107
import { PythonEnvInfo } from './base/info';
11-
import { BasicEnvInfo, IDiscoveryAPI, ILocator } from './base/locator';
12-
import { PythonEnvsReducer } from './base/locators/composite/envsReducer';
13-
import { PythonEnvsResolver } from './base/locators/composite/envsResolver';
14-
import { WindowsPathEnvVarLocator } from './base/locators/lowLevel/windowsKnownPathsLocator';
15-
import { WorkspaceVirtualEnvironmentLocator } from './base/locators/lowLevel/workspaceVirtualEnvLocator';
8+
import { IDiscoveryAPI } from './base/locator';
169
import {
1710
initializeExternalDependencies as initializeLegacyExternalDependencies,
1811
normCasePath,
1912
} from './common/externalDependencies';
20-
import { ExtensionLocators, WatchRootsArgs, WorkspaceLocators } from './base/locators/wrappers';
21-
import { CustomVirtualEnvironmentLocator } from './base/locators/lowLevel/customVirtualEnvLocator';
22-
import { CondaEnvironmentLocator } from './base/locators/lowLevel/condaLocator';
23-
import { GlobalVirtualEnvironmentLocator } from './base/locators/lowLevel/globalVirtualEnvronmentLocator';
24-
import { PosixKnownPathsLocator } from './base/locators/lowLevel/posixKnownPathsLocator';
25-
import { PyenvLocator } from './base/locators/lowLevel/pyenvLocator';
26-
import { WindowsRegistryLocator } from './base/locators/lowLevel/windowsRegistryLocator';
27-
import { MicrosoftStoreLocator } from './base/locators/lowLevel/microsoftStoreLocator';
28-
import { getEnvironmentInfoService } from './base/info/environmentInfoService';
2913
import { registerNewDiscoveryForIOC } from './legacyIOC';
30-
import { PoetryLocator } from './base/locators/lowLevel/poetryLocator';
31-
import { HatchLocator } from './base/locators/lowLevel/hatchLocator';
32-
import { createPythonEnvironments } from './api';
33-
import {
34-
createCollectionCache as createCache,
35-
IEnvsCollectionCache,
36-
} from './base/locators/composite/envsCollectionCache';
37-
import { EnvsCollectionService } from './base/locators/composite/envsCollectionService';
38-
import { IDisposable } from '../common/types';
39-
import { traceError } from '../logging';
40-
import { ActiveStateLocator } from './base/locators/lowLevel/activeStateLocator';
41-
import { CustomWorkspaceLocator } from './base/locators/lowLevel/customWorkspaceLocator';
42-
import { PixiLocator } from './base/locators/lowLevel/pixiLocator';
43-
import { getConfiguration } from '../common/vscodeApis/workspaceApis';
4414
import { getNativePythonFinder } from './base/locators/common/nativePythonFinder';
4515
import { createNativeEnvironmentsApi } from './nativeAPI';
4616
import { useEnvExtension } from '../envExt/api.internal';
4717
import { createEnvExtApi } from '../envExt/envExtApi';
4818

4919
const PYTHON_ENV_INFO_CACHE_KEY = 'PYTHON_ENV_INFO_CACHEv2';
5020

51-
export function shouldUseNativeLocator(): boolean {
52-
const config = getConfiguration('python');
53-
return config.get<string>('locator', 'js') === 'native';
54-
}
55-
5621
/**
5722
* Set up the Python environments component (during extension activation).'
5823
*/
@@ -70,19 +35,9 @@ export async function initialize(ext: ExtensionState): Promise<IDiscoveryAPI> {
7035
return api;
7136
}
7237

73-
if (shouldUseNativeLocator()) {
74-
const finder = getNativePythonFinder(ext.context);
75-
const api = createNativeEnvironmentsApi(finder);
76-
ext.disposables.push(api);
77-
registerNewDiscoveryForIOC(
78-
// These are what get wrapped in the legacy adapter.
79-
ext.legacyIOC.serviceManager,
80-
api,
81-
);
82-
return api;
83-
}
84-
85-
const api = await createPythonEnvironments(() => createLocator(ext));
38+
const finder = getNativePythonFinder(ext.context);
39+
const api = createNativeEnvironmentsApi(finder);
40+
ext.disposables.push(api);
8641
registerNewDiscoveryForIOC(
8742
// These are what get wrapped in the legacy adapter.
8843
ext.legacyIOC.serviceManager,
@@ -136,138 +91,3 @@ export async function activate(api: IDiscoveryAPI, ext: ExtensionState): Promise
13691
fullyReady: Promise.resolve(),
13792
};
13893
}
139-
140-
/**
141-
* Get the locator to use in the component.
142-
*/
143-
async function createLocator(
144-
ext: ExtensionState,
145-
// This is shared.
146-
): Promise<IDiscoveryAPI> {
147-
// Create the low-level locators.
148-
const locators: ILocator<BasicEnvInfo> = new ExtensionLocators<BasicEnvInfo>(
149-
// Here we pull the locators together.
150-
createNonWorkspaceLocators(ext),
151-
createWorkspaceLocator(ext),
152-
);
153-
154-
// Create the env info service used by ResolvingLocator and CachingLocator.
155-
const envInfoService = getEnvironmentInfoService(ext.disposables);
156-
157-
// Build the stack of composite locators.
158-
const reducer = new PythonEnvsReducer(locators);
159-
const resolvingLocator = new PythonEnvsResolver(
160-
reducer,
161-
// These are shared.
162-
envInfoService,
163-
);
164-
const caching = new EnvsCollectionService(
165-
await createCollectionCache(ext),
166-
// This is shared.
167-
resolvingLocator,
168-
shouldUseNativeLocator(),
169-
);
170-
return caching;
171-
}
172-
173-
function createNonWorkspaceLocators(ext: ExtensionState): ILocator<BasicEnvInfo>[] {
174-
const locators: (ILocator<BasicEnvInfo> & Partial<IDisposable>)[] = [];
175-
locators.push(
176-
// OS-independent locators go here.
177-
new PyenvLocator(),
178-
new CondaEnvironmentLocator(),
179-
new ActiveStateLocator(),
180-
new GlobalVirtualEnvironmentLocator(),
181-
new CustomVirtualEnvironmentLocator(),
182-
);
183-
184-
if (getOSType() === OSType.Windows) {
185-
locators.push(
186-
// Windows specific locators go here.
187-
new WindowsRegistryLocator(),
188-
new MicrosoftStoreLocator(),
189-
new WindowsPathEnvVarLocator(),
190-
);
191-
} else {
192-
locators.push(
193-
// Linux/Mac locators go here.
194-
new PosixKnownPathsLocator(),
195-
);
196-
}
197-
198-
const disposables = locators.filter((d) => d.dispose !== undefined) as IDisposable[];
199-
ext.disposables.push(...disposables);
200-
return locators;
201-
}
202-
203-
function watchRoots(args: WatchRootsArgs): IDisposable {
204-
const { initRoot, addRoot, removeRoot } = args;
205-
206-
const folders = vscode.workspace.workspaceFolders;
207-
if (folders) {
208-
folders.map((f) => f.uri).forEach(initRoot);
209-
}
210-
211-
return vscode.workspace.onDidChangeWorkspaceFolders((event) => {
212-
for (const root of event.removed) {
213-
removeRoot(root.uri);
214-
}
215-
for (const root of event.added) {
216-
addRoot(root.uri);
217-
}
218-
});
219-
}
220-
221-
function createWorkspaceLocator(ext: ExtensionState): WorkspaceLocators {
222-
const locators = new WorkspaceLocators(watchRoots, [
223-
(root: vscode.Uri) => [
224-
new WorkspaceVirtualEnvironmentLocator(root.fsPath),
225-
new PoetryLocator(root.fsPath),
226-
new HatchLocator(root.fsPath),
227-
new PixiLocator(root.fsPath),
228-
new CustomWorkspaceLocator(root.fsPath),
229-
],
230-
// Add an ILocator factory func here for each kind of workspace-rooted locator.
231-
]);
232-
ext.disposables.push(locators);
233-
return locators;
234-
}
235-
236-
function getFromStorage(storage: IPersistentStorage<PythonEnvInfo[]>): PythonEnvInfo[] {
237-
return storage.get().map((e) => {
238-
if (e.searchLocation) {
239-
if (typeof e.searchLocation === 'string') {
240-
e.searchLocation = Uri.parse(e.searchLocation);
241-
} else if ('scheme' in e.searchLocation && 'path' in e.searchLocation) {
242-
e.searchLocation = Uri.parse(`${e.searchLocation.scheme}://${e.searchLocation.path}`);
243-
} else {
244-
traceError('Unexpected search location', JSON.stringify(e.searchLocation));
245-
}
246-
}
247-
return e;
248-
});
249-
}
250-
251-
function putIntoStorage(storage: IPersistentStorage<PythonEnvInfo[]>, envs: PythonEnvInfo[]): Promise<void> {
252-
storage.set(
253-
// We have to `cloneDeep()` here so that we don't overwrite the original `PythonEnvInfo` objects.
254-
cloneDeep(envs).map((e) => {
255-
if (e.searchLocation) {
256-
// Make TS believe it is string. This is temporary. We need to serialize this in
257-
// a custom way.
258-
e.searchLocation = (e.searchLocation.toString() as unknown) as Uri;
259-
}
260-
return e;
261-
}),
262-
);
263-
return Promise.resolve();
264-
}
265-
266-
async function createCollectionCache(ext: ExtensionState): Promise<IEnvsCollectionCache> {
267-
const storage = getGlobalStorage<PythonEnvInfo[]>(ext.context, PYTHON_ENV_INFO_CACHE_KEY, []);
268-
const cache = await createCache({
269-
get: () => getFromStorage(storage),
270-
store: async (e) => putIntoStorage(storage, e),
271-
});
272-
return cache;
273-
}

0 commit comments

Comments
 (0)