-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathactivation.ts
More file actions
59 lines (49 loc) · 2.02 KB
/
activation.ts
File metadata and controls
59 lines (49 loc) · 2.02 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
import { Terminal, window } from 'vscode';
import { PythonCommandRunConfiguration, PythonEnvironment } from '../../api';
import { identifyTerminalShell } from './shellDetector';
import { traceLog } from '../../common/logging';
export function isActivatableEnvironment(environment: PythonEnvironment): boolean {
return !!environment.execInfo?.activation || !!environment.execInfo?.shellActivation;
}
export function isActivatedRunAvailable(environment: PythonEnvironment): boolean {
return !!environment.execInfo?.activatedRun;
}
export function getActivationCommand(
terminal: Terminal,
environment: PythonEnvironment,
): PythonCommandRunConfiguration[] | undefined {
const shell = identifyTerminalShell(terminal);
traceLog('getActivationCommand: Shell type from API:', shell);
window.onDidChangeTerminalState((e) => {
// traceLog('getActivationCommand: Terminal state changed:', e);
traceLog('the shell type from API inside the listener:', e.state.shell);
});
let activation: PythonCommandRunConfiguration[] | undefined;
if (environment.execInfo?.shellActivation) {
activation = environment.execInfo.shellActivation.get(shell);
if (!activation) {
activation = environment.execInfo.shellActivation.get('unknown');
}
}
if (!activation) {
activation = environment.execInfo?.activation;
}
return activation;
}
export function getDeactivationCommand(
terminal: Terminal,
environment: PythonEnvironment,
): PythonCommandRunConfiguration[] | undefined {
const shell = identifyTerminalShell(terminal);
let deactivation: PythonCommandRunConfiguration[] | undefined;
if (environment.execInfo?.shellDeactivation) {
deactivation = environment.execInfo.shellDeactivation.get(shell);
if (!deactivation) {
deactivation = environment.execInfo.shellDeactivation.get('unknown');
}
}
if (!deactivation) {
deactivation = environment.execInfo?.deactivation;
}
return deactivation;
}