()
| 203 | |
| 204 | let remoteUrisCleared = false; |
| 205 | export function initializeCommonNodeApi() { |
| 206 | const { commands, Uri } = vscode; |
| 207 | const { initialize } = initializeModule; |
| 208 | |
| 209 | initializeCommonApi({ |
| 210 | async createTemporaryFile(options: { |
| 211 | contents?: string; |
| 212 | extension: string; |
| 213 | }): Promise<{ file: Uri } & IDisposable> { |
| 214 | const extension = options.extension || '.py'; |
| 215 | const tempFile = tmp.tmpNameSync({ postfix: extension }); |
| 216 | if (options.contents) { |
| 217 | await fs.writeFile(tempFile, options.contents); |
| 218 | } |
| 219 | return { file: Uri.file(tempFile), dispose: () => swallowExceptions(() => fs.unlinkSync(tempFile)) }; |
| 220 | }, |
| 221 | async startJupyterServer( |
| 222 | options: { |
| 223 | token?: string; |
| 224 | port?: number; |
| 225 | useCert?: boolean; |
| 226 | jupyterLab?: boolean; |
| 227 | password?: string; |
| 228 | detached?: boolean; |
| 229 | standalone?: boolean; |
| 230 | } = {} |
| 231 | ): Promise<{ url: string } & IDisposable> { |
| 232 | if (IS_REMOTE_NATIVE_TEST()) { |
| 233 | if (options.standalone) { |
| 234 | return JupyterServer.instance.startJupyter(options); |
| 235 | } |
| 236 | if (!remoteUrisCleared) { |
| 237 | await commands.executeCommand('deepnote.clearSavedJupyterUris'); |
| 238 | remoteUrisCleared = true; |
| 239 | } |
| 240 | const url = options.useCert |
| 241 | ? await JupyterServer.instance.startJupyterWithCert() |
| 242 | : await JupyterServer.instance.startJupyterWithToken(); |
| 243 | console.info(`Jupyter started and listening at ${url}`); |
| 244 | try { |
| 245 | await commands.executeCommand('deepnote.selectjupyteruri', Uri.parse(url)); |
| 246 | } catch (ex) { |
| 247 | console.error('Failed to select jupyter server, retry in 1s', ex); |
| 248 | } |
| 249 | // Todo: Fix in debt week, we need to retry, some changes have caused the first connection attempt to fail on CI. |
| 250 | // Possible we're trying to connect before the server is ready. |
| 251 | await sleep(5_000); |
| 252 | await commands.executeCommand('deepnote.selectjupyteruri', Uri.parse(url)); |
| 253 | return { url, dispose: noop }; |
| 254 | } else { |
| 255 | return { url: '', dispose: noop }; |
| 256 | } |
| 257 | }, |
| 258 | async stopJupyterServer() { |
| 259 | if (IS_REMOTE_NATIVE_TEST()) { |
| 260 | return; |
| 261 | } |
| 262 | await JupyterServer.instance.dispose().catch(noop); |
no test coverage detected