-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathmain.ts
More file actions
67 lines (62 loc) · 2.55 KB
/
Copy pathmain.ts
File metadata and controls
67 lines (62 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { Disposable, LogOutputChannel } from 'vscode';
import { PythonEnvironmentApi } from '../../api';
import { setVenvManagerStrings, VenvManagerStringsWithUv } from '../../common/localize';
import { createSimpleDebounce } from '../../common/utils/debounce';
import { onDidEndTerminalShellExecution } from '../../common/window.apis';
import { createFileSystemWatcher, onDidDeleteFiles } from '../../common/workspace.apis';
import { getPythonApi } from '../../features/pythonApi';
import { NativePythonFinder } from '../common/nativePythonFinder';
import { isUvInstalled } from './helpers';
import { PipPackageManager } from './pipManager';
import { isPipInstallCommand } from './pipUtils';
import { SysPythonManager } from './sysPythonManager';
import { VenvManager } from './venvManager';
export async function registerSystemPythonFeatures(
nativeFinder: NativePythonFinder,
disposables: Disposable[],
log: LogOutputChannel,
envManager: SysPythonManager,
): Promise<void> {
const api: PythonEnvironmentApi = await getPythonApi();
const venvManager = new VenvManager(nativeFinder, api, envManager, log);
const pkgManager = new PipPackageManager(api, log, venvManager);
const uvAvailable = await isUvInstalled(log);
if (uvAvailable) {
venvManager.setDisplayName('venv [uv]');
log.info('uv detected - updating venv manager display name');
// Switch all venv-related UI strings to uv versions
setVenvManagerStrings(VenvManagerStringsWithUv);
}
disposables.push(
api.registerPackageManager(pkgManager),
api.registerEnvironmentManager(envManager),
api.registerEnvironmentManager(venvManager),
);
const venvDebouncedRefresh = createSimpleDebounce(500, () => {
venvManager.watcherRefresh();
});
const watcher = createFileSystemWatcher('{**/activate}', false, true, false);
disposables.push(
watcher,
watcher.onDidCreate(() => {
venvDebouncedRefresh.trigger();
}),
watcher.onDidDelete(() => {
venvDebouncedRefresh.trigger();
}),
onDidDeleteFiles(() => {
venvDebouncedRefresh.trigger();
}),
);
disposables.push(
onDidEndTerminalShellExecution(async (e) => {
const cwd = e.terminal.shellIntegration?.cwd;
if (isPipInstallCommand(e.execution.commandLine.value) && cwd) {
const env = await venvManager.get(cwd);
if (env) {
await pkgManager.refresh(env);
}
}
}),
);
}