-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathbashEnvs.ts
More file actions
51 lines (46 loc) · 2 KB
/
bashEnvs.ts
File metadata and controls
51 lines (46 loc) · 2 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
import { EnvironmentVariableCollection } from 'vscode';
import { PythonEnvironment } from '../../../../api';
import { traceError } from '../../../../common/logging';
import { getShellActivationCommand, getShellCommandAsString } from '../common/shellUtils';
import { ShellEnvsProvider } from '../startupProvider';
import { BASH_ENV_KEY } from './bashConstants';
export class BashEnvsProvider implements ShellEnvsProvider {
constructor(public readonly shellType: 'bash' | 'gitbash') {}
updateEnvVariables(collection: EnvironmentVariableCollection, env: PythonEnvironment): void {
try {
const bashActivation = getShellActivationCommand(this.shellType, env);
if (bashActivation) {
const command = getShellCommandAsString(this.shellType, bashActivation);
const v = collection.get(BASH_ENV_KEY);
if (v?.value === command) {
return;
}
collection.replace(BASH_ENV_KEY, command);
} else {
collection.delete(BASH_ENV_KEY);
}
} catch (err) {
traceError(`Failed to update env variables for ${this.shellType}`, err);
collection.delete(BASH_ENV_KEY);
}
}
removeEnvVariables(envCollection: EnvironmentVariableCollection): void {
envCollection.delete(BASH_ENV_KEY);
}
getEnvVariables(env?: PythonEnvironment): Map<string, string | undefined> | undefined {
if (!env) {
return new Map([[BASH_ENV_KEY, undefined]]);
}
try {
const bashActivation = getShellActivationCommand(this.shellType, env);
if (bashActivation) {
const command = getShellCommandAsString(this.shellType, bashActivation);
return new Map([[BASH_ENV_KEY, command]]);
}
return undefined;
} catch (err) {
traceError(`Failed to get env variables for ${this.shellType}`, err);
return undefined;
}
}
}