forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpythonToolService.ts
More file actions
37 lines (35 loc) · 2.28 KB
/
pythonToolService.ts
File metadata and controls
37 lines (35 loc) · 2.28 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
// 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 });
}
}
}