-
Notifications
You must be signed in to change notification settings - Fork 312
/
Copy pathapi.unstable.d.ts
280 lines (269 loc) · 12 KB
/
api.unstable.d.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import type { CancellationToken, Disposable, Event, NotebookDocument, Uri } from 'vscode';
import type { Session } from '@jupyterlab/services';
type EnvironmentPath = {
/**
* The ID of the environment.
*/
readonly id: string;
/**
* Path to environment folder or path to python executable that uniquely identifies an environment. Environments
* lacking a python executable are identified by environment folder paths, whereas other envs can be identified
* using python executable path.
*/
readonly path: string;
};
declare module './api' {
export interface Jupyter {
/**
* Promise indicating whether all parts of the extension have completed loading or not.
* @type {Promise<void>}
* @memberof IExtensionApi
*/
ready: Promise<void>;
/**
* Registers a remote server provider component that's used to pick remote jupyter server URIs
* @param serverProvider object called back when picking jupyter server URI
*/
registerRemoteServerProvider(serverProvider: IJupyterUriProvider): Disposable;
/**
* Adds a remote Jupyter Server to the list of Remote Jupyter servers.
* This will result in the Jupyter extension listing kernels from this server as items in the kernel picker.
*/
addRemoteJupyterServer(providerId: string, handle: string): Promise<void>;
/**
* Gets the service that provides access to kernels.
* Returns `undefined` if the calling extension is not allowed to access this API. This could
* happen either when user doesn't allow this or the extension doesn't allow this.
* There are a specific set of extensions that are currently allowed to access this API.
*/
getKernelService(): Promise<IExportedKernelService | undefined>;
/**
* Opens a notebook with a specific Python Environment as the active kernel.
* @param {Uri} uri Uri of the notebook to open.
* @param {EnvironmentPath} pythonEnvironment Python Environment
* @returns {Promise<NotebookDocument>} Promise that resolves to the notebook document.
*/
openNotebook(uri: Uri, pythonEnvironment: EnvironmentPath): Promise<NotebookDocument>;
/**
* Opens a notebook with a specific kernel as the active kernel.
* @param {Uri} uri Uri of the notebook to open.
* @param {String} kernelId Id of the kernel, retrieved from getKernelService().getKernelSpecifications()
* @returns {Promise<NotebookDocument>} Promise that resolves to the notebook document.
*/
openNotebook(uri: Uri, kernelId: string): Promise<NotebookDocument>;
}
//#region Python Env Information (soon to be deprecated in favour of Python Extensions new Environments API)
/**
* The supported Python environment types.
*/
export enum EnvironmentType {
Unknown = 'Unknown',
Conda = 'Conda',
VirtualEnv = 'VirtualEnv',
Pipenv = 'PipEnv',
Pyenv = 'Pyenv',
Venv = 'Venv',
Poetry = 'Poetry',
VirtualEnvWrapper = 'VirtualEnvWrapper'
}
/**
* A representation of a Python runtime's version.
*/
export type PythonVersion = {
/**
* The original version string.
*/
raw: string;
major: number;
minor: number;
patch: number;
};
export interface PythonEnvironment {
id: string;
uri: Uri;
}
//#endregion
//#region Kernel Information (Kernel Specs, connections)
/**
* Details of the kernel spec.
* See https://jupyter-client.readthedocs.io/en/stable/kernels.html#kernel-specs
*/
export interface IJupyterKernelSpec {
/**
* Id of an existing (active) Kernel from an active session.
*/
id?: string;
name: string;
/**
* The name of the language of the kernel
*/
language?: string;
path: string;
/**
* A dictionary of environment variables to set for the kernel.
* These will be added to the current environment variables before the kernel is started.
*/
env?: NodeJS.ProcessEnv | undefined;
/**
* Kernel display name.
*/
readonly display_name: string;
/**
* A dictionary of additional attributes about this kernel; used by clients to aid in kernel selection.
* Optionally storing the interpreter information in the metadata (helping extension search for kernels that match an interpreter).
* Metadata added here should be namespaced for the tool reading and writing that metadata.
*/
readonly metadata?: Record<string, unknown> & { interpreter?: Partial<PythonEnvironment> };
/**
* A list of command line arguments used to start the kernel.
* The text {connection_file} in any argument will be replaced with the path to the connection file.
*/
readonly argv: string[];
/**
* Optionally where this kernel spec json is located on the local FS.
*/
specFile?: string;
/**
* Optionally the Interpreter this kernel spec belongs to.
* You can have kernel specs that are scoped to an interpreter.
* E.g. if you have Python in `c:\Python\Python3.8`
* Then you could have kernels in `<sys.prefix folder for this interpreter>\share\jupyter\kernels`
* Plenty of conda packages ship kernels in this manner (beakerx, java, etc).
*/
interpreterPath?: string;
/**
* May be either signal or message and specifies how a client is supposed to interrupt cell execution on this kernel,
* either by sending an interrupt signal via the operating system’s signalling facilities (e.g. SIGINT on POSIX systems),
* or by sending an interrupt_request message on the control channel.
* If this is not specified the client will default to signal mode.
*/
readonly interrupt_mode?: 'message' | 'signal';
}
/**
* Connection metadata for Kernels started using kernelspec (JSON).
* This could be a raw kernel (spec might have path to executable for .NET or the like).
* If the executable is not defined in kernelspec json, & it is a Python kernel, then we'll use the provided python interpreter.
*/
export type LocalKernelSpecConnectionMetadata = Readonly<{
kernelModel?: undefined;
kernelSpec: IJupyterKernelSpec;
/**
* Indicates the interpreter that may be used to start the kernel.
* If possible to start a kernel without this Python interpreter, then this Python interpreter will be used for intellisense & the like.
* This interpreter could also be the interpreter associated with the kernel spec that we are supposed to start.
*/
interpreter?: PythonEnvironment;
kind: 'startUsingLocalKernelSpec';
id: string;
}>;
/**
* Connection metadata for Remote Kernels started using kernelspec (JSON).
* This could be a raw kernel (spec might have path to executable for .NET or the like).
* If the executable is not defined in kernelspec json, & it is a Python kernel, then we'll use the provided python interpreter.
*/
export type RemoteKernelSpecConnectionMetadata = Readonly<{
kernelModel?: undefined;
interpreter?: undefined;
kernelSpec: IJupyterKernelSpec;
kind: 'startUsingRemoteKernelSpec';
baseUrl: string;
id: string;
}>;
/**
* Connection metadata for Kernels started using Python interpreter.
* These are not necessarily raw (it could be plain old Jupyter Kernels, where we register Python interpreter as a kernel).
* We can have KernelSpec information here as well, however that is totally optional.
* We will always start this kernel using old Jupyter style (provided we first register this interpreter as a kernel) or raw.
*/
export type PythonKernelConnectionMetadata = Readonly<{
kernelSpec: IJupyterKernelSpec;
interpreter: PythonEnvironment;
kind: 'startUsingPythonInterpreter';
id: string;
}>;
interface IJupyterKernel {
/**
* Id of an existing (active) Kernel from an active session.
*/
id?: string;
name: string;
}
export type LiveKernelModel = IJupyterKernel &
Partial<IJupyterKernelSpec> & { model: Session.IModel | undefined; notebook?: { path?: string } };
/**
* Connection metadata for Live Kernels.
* With this we are able connect to an existing kernel (instead of starting a new session).
*/
export type LiveRemoteKernelConnectionMetadata = Readonly<{
kernelModel: LiveKernelModel;
/**
* Python interpreter will be used for intellisense & the like.
*/
interpreter?: PythonEnvironment;
baseUrl: string;
kind: 'connectToLiveRemoteKernel';
id: string;
}>;
export type KernelConnectionMetadata =
| LocalKernelSpecConnectionMetadata
| RemoteKernelSpecConnectionMetadata
| PythonKernelConnectionMetadata
| LiveRemoteKernelConnectionMetadata;
export type ActiveKernel = LiveRemoteKernelConnectionMetadata;
//#endregion
//#region Kernel API
/**
* Data represents the message payload received over the WebSocket.
*/
export type WebSocketData = string | Buffer | ArrayBuffer | Buffer[];
export interface IExportedKernelService {
readonly status: 'discovering' | 'idle';
/**
* Changes in kernel state (e.g. discovered kernels, not discovering kernel, etc).
*/
onDidChangeStatus: Event<void>;
/**
* List of running kernels changed.
*/
onDidChangeKernels: Event<void>;
/**
* List of kernel specs changed.
*/
onDidChangeKernelSpecifications: Event<void>;
/**
* Gets a list of all kernel specifications that can be used to start a new kernel or to connect to an existing kernel.
* Local, remote kernels are returned, including Python interpreters that
* are treated as kernelspecs (as we can start Kernels for Python interpreters without Jupyter).
*/
getKernelSpecifications(): Promise<KernelConnectionMetadata[]>;
/**
* Gets a list of all active kernel connections.
* If `uri` is undefined, then the kernel is not associated with any resource. I.e its currently not associated with any notebook in Jupyter extension.
* If `uri` is undefined, then the kernel is associated with the resource identified by the Uri.
*/
getActiveKernels(): { metadata: KernelConnectionMetadata; uri: Uri | undefined }[];
/**
* Gets the Kernel connection & the metadata that's associated with a given resource.
* (only successfully started/active connections are returned).
*/
getKernel(uri: Uri): { metadata: KernelConnectionMetadata; connection: Session.ISessionConnection } | undefined;
/**
* Starts a kernel for a given resource.
* The promise is resolved only after the kernel has successfully started.
* If one attempts to start another kernel for the same resource, the same promise is returned.
*/
startKernel(
metadata: KernelConnectionMetadata,
uri: Uri,
token?: CancellationToken
): Promise<Session.ISessionConnection>;
/**
* Connects an existing kernel to a resource.
* The promise is resolved only after the kernel is successfully attached to a resource.
* If one attempts to start another kernel or connect another kernel for the same resource, the same promise is returned.
*/
connect(metadata: LiveRemoteKernelConnectionMetadata, uri: Uri): Promise<Session.ISessionConnection>;
}
}