forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
pythonToolService.ts
60 lines (58 loc) · 2.5 KB
/
pythonToolService.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { inject, injectable } from 'inversify';
import { Uri } from 'vscode';
import { IServiceContainer } from '../../ioc/types';
import { ExecutionInfo } from '../types';
import {
ExecutionResult,
IProcessServiceFactory,
IPythonExecutionFactory,
IPythonToolExecutionService,
ObservableExecutionResult,
SpawnOptions
} from './types';
@injectable()
export class PythonToolExecutionService implements IPythonToolExecutionService {
constructor(@inject(IServiceContainer) private serviceContainer: IServiceContainer) {}
public async execObservable(
executionInfo: ExecutionInfo,
options: SpawnOptions,
resource: Uri
): Promise<ObservableExecutionResult<string>> {
if (options.env) {
throw new Error('Environment variables are not supported');
}
if (executionInfo.moduleName && executionInfo.moduleName.length > 0) {
const pythonExecutionService = await this.serviceContainer
.get<IPythonExecutionFactory>(IPythonExecutionFactory)
.create({ resource });
return pythonExecutionService.execModuleObservable(executionInfo.moduleName, executionInfo.args, options);
} else {
const processService = await this.serviceContainer
.get<IProcessServiceFactory>(IProcessServiceFactory)
.create(resource);
return processService.execObservable(executionInfo.execPath!, executionInfo.args, { ...options });
}
}
public async exec(
executionInfo: ExecutionInfo,
options: SpawnOptions,
resource: Uri
): Promise<ExecutionResult<string>> {
if (options.env) {
throw new Error('Environment variables are not supported');
}
if (executionInfo.moduleName && executionInfo.moduleName.length > 0) {
const pythonExecutionService = await this.serviceContainer
.get<IPythonExecutionFactory>(IPythonExecutionFactory)
.create({ resource });
return pythonExecutionService.execModule(executionInfo.moduleName!, executionInfo.args, options);
} else {
const processService = await this.serviceContainer
.get<IProcessServiceFactory>(IProcessServiceFactory)
.create(resource);
return processService.exec(executionInfo.execPath!, executionInfo.args, { ...options });
}
}
}