forked from DonJayamanne/pythonVSCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtypes.ts
More file actions
130 lines (112 loc) · 5.37 KB
/
types.ts
File metadata and controls
130 lines (112 loc) · 5.37 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
import { ChildProcess, ExecOptions, SpawnOptions as ChildProcessSpawnOptions } from 'child_process';
import { Observable } from 'rxjs/Observable';
import { CancellationToken, OutputChannel, Uri } from 'vscode';
import { PythonExecInfo } from '../../pythonEnvironments/exec';
import { InterpreterInformation, PythonEnvironment } from '../../pythonEnvironments/info';
import { ExecutionInfo, IDisposable } from '../types';
export type Output<T extends string | Buffer> = {
source: 'stdout' | 'stderr';
out: T;
};
export type ObservableExecutionResult<T extends string | Buffer> = {
proc: ChildProcess | undefined;
out: Observable<Output<T>>;
dispose(): void;
};
export type SpawnOptions = ChildProcessSpawnOptions & {
encoding?: string;
token?: CancellationToken;
mergeStdOutErr?: boolean;
throwOnStdErr?: boolean;
extraVariables?: NodeJS.ProcessEnv;
outputChannel?: OutputChannel;
stdinStr?: string;
useWorker?: boolean;
};
export type ShellOptions = ExecOptions & { throwOnStdErr?: boolean; useWorker?: boolean };
export type ExecutionResult<T extends string | Buffer> = {
stdout: T;
stderr?: T;
};
export const IProcessLogger = Symbol('IProcessLogger');
export interface IProcessLogger {
/**
* Pass `args` as `undefined` if first argument is supposed to be a shell command.
* Note it is assumed that command args are always quoted and respect
* `String.prototype.toCommandArgument()` prototype.
*/
logProcess(fileOrCommand: string, args?: string[], options?: SpawnOptions): void;
}
export interface IProcessService extends IDisposable {
execObservable(file: string, args: string[], options?: SpawnOptions): ObservableExecutionResult<string>;
exec(file: string, args: string[], options?: SpawnOptions): Promise<ExecutionResult<string>>;
shellExec(command: string, options?: ShellOptions): Promise<ExecutionResult<string>>;
on(event: 'exec', listener: (file: string, args: string[], options?: SpawnOptions) => void): this;
}
export const IProcessServiceFactory = Symbol('IProcessServiceFactory');
export interface IProcessServiceFactory {
create(resource?: Uri, options?: { doNotUseCustomEnvs: boolean }): Promise<IProcessService>;
}
export const IPythonExecutionFactory = Symbol('IPythonExecutionFactory');
export type ExecutionFactoryCreationOptions = {
resource?: Uri;
pythonPath?: string;
};
export type ExecutionFactoryCreateWithEnvironmentOptions = {
resource?: Uri;
interpreter?: PythonEnvironment;
allowEnvironmentFetchExceptions?: boolean;
/**
* Ignore running `conda run` when running code.
* It is known to fail in certain scenarios. Where necessary we might want to bypass this.
*
* @type {boolean}
*/
};
export interface IPythonExecutionFactory {
create(options: ExecutionFactoryCreationOptions): Promise<IPythonExecutionService>;
createActivatedEnvironment(options: ExecutionFactoryCreateWithEnvironmentOptions): Promise<IPythonExecutionService>;
createCondaExecutionService(
pythonPath: string,
processService: IProcessService,
): Promise<IPythonExecutionService | undefined>;
}
export const IPythonExecutionService = Symbol('IPythonExecutionService');
export interface IPythonExecutionService {
getInterpreterInformation(): Promise<InterpreterInformation | undefined>;
getExecutablePath(): Promise<string | undefined>;
isModuleInstalled(moduleName: string): Promise<boolean>;
getModuleVersion(moduleName: string): Promise<string | undefined>;
getExecutionInfo(pythonArgs?: string[]): PythonExecInfo;
execObservable(args: string[], options: SpawnOptions): ObservableExecutionResult<string>;
execModuleObservable(moduleName: string, args: string[], options: SpawnOptions): ObservableExecutionResult<string>;
exec(args: string[], options: SpawnOptions): Promise<ExecutionResult<string>>;
execModule(moduleName: string, args: string[], options: SpawnOptions): Promise<ExecutionResult<string>>;
execForLinter(moduleName: string, args: string[], options: SpawnOptions): Promise<ExecutionResult<string>>;
}
export interface IPythonEnvironment {
getInterpreterInformation(): Promise<InterpreterInformation | undefined>;
getExecutionObservableInfo(pythonArgs?: string[], pythonExecutable?: string): PythonExecInfo;
getExecutablePath(): Promise<string | undefined>;
isModuleInstalled(moduleName: string): Promise<boolean>;
getModuleVersion(moduleName: string): Promise<string | undefined>;
getExecutionInfo(pythonArgs?: string[], pythonExecutable?: string): PythonExecInfo;
}
export type ShellExecFunc = (command: string, options?: ShellOptions | undefined) => Promise<ExecutionResult<string>>;
export class StdErrError extends Error {
constructor(message: string) {
super(message);
}
}
export const IPythonToolExecutionService = Symbol('IPythonToolRunnerService');
export interface IPythonToolExecutionService {
execObservable(
executionInfo: ExecutionInfo,
options: SpawnOptions,
resource: Uri,
): Promise<ObservableExecutionResult<string>>;
exec(executionInfo: ExecutionInfo, options: SpawnOptions, resource: Uri): Promise<ExecutionResult<string>>;
execForLinter(executionInfo: ExecutionInfo, options: SpawnOptions, resource: Uri): Promise<ExecutionResult<string>>;
}