forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
Copy pathpyenvActivationProvider.ts
46 lines (38 loc) · 1.86 KB
/
pyenvActivationProvider.ts
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { inject, injectable } from 'inversify';
import { Uri } from 'vscode';
import { IInterpreterService } from '../../../interpreter/contracts';
import { IServiceContainer } from '../../../ioc/types';
import { EnvironmentType } from '../../../pythonEnvironments/info';
import { ITerminalActivationCommandProvider, TerminalShellType } from '../types';
@injectable()
export class PyEnvActivationCommandProvider implements ITerminalActivationCommandProvider {
constructor(@inject(IServiceContainer) private readonly serviceContainer: IServiceContainer) {}
// eslint-disable-next-line class-methods-use-this
public isShellSupported(_targetShell: TerminalShellType): boolean {
return true;
}
public async getActivationCommands(resource: Uri | undefined, _: TerminalShellType): Promise<string[] | undefined> {
const interpreter = await this.serviceContainer
.get<IInterpreterService>(IInterpreterService)
.getActiveInterpreter(resource);
if (!interpreter || interpreter.envType !== EnvironmentType.Pyenv || !interpreter.envName) {
return undefined;
}
return [`pyenv shell ${interpreter.envName.toCommandArgumentForPythonExt()}`];
}
public async getActivationCommandsForInterpreter(
pythonPath: string,
_targetShell: TerminalShellType,
): Promise<string[] | undefined> {
const interpreter = await this.serviceContainer
.get<IInterpreterService>(IInterpreterService)
.getInterpreterDetails(pythonPath);
if (!interpreter || interpreter.envType !== EnvironmentType.Pyenv || !interpreter.envName) {
return undefined;
}
return [`pyenv shell ${interpreter.envName.toCommandArgumentForPythonExt()}`];
}
}