Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2d66ae9

Browse filesBrowse files
authored
Updates to categories and request object (#23742)
1 parent 3410b38 commit 2d66ae9
Copy full SHA for 2d66ae9

File tree

Expand file treeCollapse file tree

1 file changed

+29
-60
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+29
-60
lines changed

‎src/client/pythonEnvironments/base/locators/common/nativePythonFinder.ts

Copy file name to clipboardExpand all lines: src/client/pythonEnvironments/base/locators/common/nativePythonFinder.ts
+29-60Lines changed: 29 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,8 @@ import { isWindows } from '../../../../common/platform/platformService';
1010
import { EXTENSION_ROOT_DIR } from '../../../../constants';
1111
import { createDeferred, createDeferredFrom } from '../../../../common/utils/async';
1212
import { DisposableBase, DisposableStore } from '../../../../common/utils/resourceLifecycle';
13-
import { DEFAULT_INTERPRETER_PATH_SETTING_KEY } from '../lowLevel/customWorkspaceLocator';
1413
import { noop } from '../../../../common/utils/misc';
15-
import {
16-
getConfiguration,
17-
getWorkspaceFolderPaths,
18-
getWorkspaceFolders,
19-
} from '../../../../common/vscodeApis/workspaceApis';
14+
import { getConfiguration, getWorkspaceFolderPaths } from '../../../../common/vscodeApis/workspaceApis';
2015
import { CONDAPATH_SETTING_KEY } from '../../../common/environmentManagers/conda';
2116
import { VENVFOLDERS_SETTING_KEY, VENVPATH_SETTING_KEY } from '../lowLevel/customVirtualEnvLocator';
2217
import { getUserHomeDir } from '../../../../common/utils/platform';
@@ -76,14 +71,11 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba
7671
}
7772

7873
public async resolve(executable: string): Promise<NativeEnvInfo> {
79-
const { environment, duration } = await this.connection.sendRequest<{
80-
duration: number;
81-
environment: NativeEnvInfo;
82-
}>('resolve', {
74+
const environment = await this.connection.sendRequest<NativeEnvInfo>('resolve', {
8375
executable,
8476
});
8577

86-
this.outputChannel.info(`Resolved Python Environment ${environment.executable} in ${duration}ms`);
78+
this.outputChannel.info(`Resolved Python Environment ${environment.executable}`);
8779
return environment;
8880
}
8981

@@ -93,30 +85,29 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba
9385
return PythonEnvKind.Conda;
9486
case 'system':
9587
case 'homebrew':
96-
case 'mac-python-org':
97-
case 'mac-command-line-tools':
98-
case 'mac-xcode':
99-
case 'windows-registry':
100-
case 'linux-global':
88+
case 'macpythonorg':
89+
case 'maccommandlinetools':
90+
case 'macxcode':
91+
case 'windowsregistry':
92+
case 'linuxglobal':
10193
return PythonEnvKind.System;
102-
case 'global-paths':
94+
case 'globalpaths':
10395
return PythonEnvKind.OtherGlobal;
10496
case 'pyenv':
105-
case 'pyenv-other':
10697
return PythonEnvKind.Pyenv;
10798
case 'poetry':
10899
return PythonEnvKind.Poetry;
109100
case 'pipenv':
110101
return PythonEnvKind.Pipenv;
111-
case 'pyenv-virtualenv':
102+
case 'pyenvvirtualenv':
112103
return PythonEnvKind.VirtualEnv;
113104
case 'venv':
114105
return PythonEnvKind.Venv;
115106
case 'virtualenv':
116107
return PythonEnvKind.VirtualEnv;
117108
case 'virtualenvwrapper':
118109
return PythonEnvKind.VirtualEnvWrapper;
119-
case 'windows-store':
110+
case 'windowsstore':
120111
return PythonEnvKind.MicrosoftStore;
121112
case 'unknown':
122113
return PythonEnvKind.Unknown;
@@ -309,11 +300,11 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba
309300
// HACK = TEMPORARY WORK AROUND, TO GET STUFF WORKING
310301
// HACK = TEMPORARY WORK AROUND, TO GET STUFF WORKING
311302
const promise = this.connection
312-
.sendRequest<{ duration: number; environment: NativeEnvInfo }>('resolve', {
303+
.sendRequest<NativeEnvInfo>('resolve', {
313304
executable: data.executable,
314305
})
315-
.then(({ environment, duration }) => {
316-
this.outputChannel.info(`Resolved ${environment.executable} in ${duration}ms`);
306+
.then((environment) => {
307+
this.outputChannel.info(`Resolved ${environment.executable}`);
317308
this.outputChannel.trace(`Environment resolved:\n ${JSON.stringify(data, undefined, 4)}`);
318309
discovered.fire(environment);
319310
})
@@ -326,7 +317,20 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba
326317
);
327318

328319
trackPromiseAndNotifyOnCompletion(
329-
this.sendRefreshRequest()
320+
this.connection
321+
.sendRequest<{ duration: number }>(
322+
'refresh',
323+
// Send configuration information to the Python finder.
324+
{
325+
// This has a special meaning in locator, its lot a low priority
326+
// as we treat this as workspace folders that can contain a large number of files.
327+
project_directories: getWorkspaceFolderPaths(),
328+
// We do not want to mix this with `search_paths`
329+
environment_directories: getCustomVirtualEnvDirs(),
330+
conda_executable: getPythonSettingAndUntildify<string>(CONDAPATH_SETTING_KEY),
331+
poetry_executable: getPythonSettingAndUntildify<string>('poetryPath'),
332+
},
333+
)
330334
.then(({ duration }) => this.outputChannel.info(`Refresh completed in ${duration}ms`))
331335
.catch((ex) => this.outputChannel.error('Refresh error', ex)),
332336
);
@@ -337,47 +341,12 @@ class NativeGlobalPythonFinderImpl extends DisposableBase implements NativeGloba
337341
discovered: discovered.event,
338342
};
339343
}
340-
341-
private sendRefreshRequest() {
342-
const pythonPathSettings = (getWorkspaceFolders() || []).map((w) =>
343-
getPythonSettingAndUntildify<string>(DEFAULT_INTERPRETER_PATH_SETTING_KEY, w.uri),
344-
);
345-
pythonPathSettings.push(getPythonSettingAndUntildify<string>(DEFAULT_INTERPRETER_PATH_SETTING_KEY));
346-
// We can have multiple workspaces, each with its own setting.
347-
const pythonSettings = Array.from(
348-
new Set(
349-
pythonPathSettings
350-
.filter((item) => !!item)
351-
// We only want the parent directories.
352-
.map((p) => path.dirname(p!))
353-
/// If setting value is 'python', then `path.dirname('python')` will yield `.`
354-
.filter((item) => item !== '.'),
355-
),
356-
);
357-
358-
return this.connection.sendRequest<{ duration: number }>(
359-
'refresh',
360-
// Send configuration information to the Python finder.
361-
{
362-
// This has a special meaning in locator, its lot a low priority
363-
// as we treat this as workspace folders that can contain a large number of files.
364-
search_paths: getWorkspaceFolderPaths(),
365-
// Also send the python paths that are configured in the settings.
366-
python_interpreter_paths: pythonSettings,
367-
// We do not want to mix this with `search_paths`
368-
virtual_env_paths: getCustomVirtualEnvDirs(),
369-
conda_executable: getPythonSettingAndUntildify<string>(CONDAPATH_SETTING_KEY),
370-
poetry_executable: getPythonSettingAndUntildify<string>('poetryPath'),
371-
pipenv_executable: getPythonSettingAndUntildify<string>('pipenvPath'),
372-
},
373-
);
374-
}
375344
}
376345

377346
/**
378347
* Gets all custom virtual environment locations to look for environments.
379348
*/
380-
async function getCustomVirtualEnvDirs(): Promise<string[]> {
349+
function getCustomVirtualEnvDirs(): string[] {
381350
const venvDirs: string[] = [];
382351
const venvPath = getPythonSettingAndUntildify<string>(VENVPATH_SETTING_KEY);
383352
if (venvPath) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.