forked from microsoft/vscode-python-environments
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ts
More file actions
65 lines (60 loc) · 2.43 KB
/
main.ts
File metadata and controls
65 lines (60 loc) · 2.43 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
import { Disposable, LogOutputChannel } from 'vscode';
import { PythonEnvironmentApi } from '../../api';
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 { UvProjectCreator } from './uvProjectCreator';
import { VenvManager } from './venvManager';
export async function registerSystemPythonFeatures(
nativeFinder: NativePythonFinder,
disposables: Disposable[],
log: LogOutputChannel,
): Promise<void> {
const api: PythonEnvironmentApi = await getPythonApi();
const envManager = new SysPythonManager(nativeFinder, api, log);
const venvManager = new VenvManager(nativeFinder, api, envManager, log);
const pkgManager = new PipPackageManager(api, log, venvManager);
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);
}
}
}),
);
setImmediate(async () => {
if (await isUvInstalled(log)) {
disposables.push(api.registerPythonProjectCreator(new UvProjectCreator(api, log)));
}
});
}