(
kernelConnection: Kernel.IKernelConnection,
code: string,
errorOptions?: SilentExecutionErrorOptions
)
| 654 | }; |
| 655 | |
| 656 | export async function executeSilently( |
| 657 | kernelConnection: Kernel.IKernelConnection, |
| 658 | code: string, |
| 659 | errorOptions?: SilentExecutionErrorOptions |
| 660 | ): Promise<nbformat.IOutput[]> { |
| 661 | logger.trace( |
| 662 | `Executing silently Code (${kernelConnection.status}) = ${splitLines(code.substring(0, 100)).join('\\n')}` |
| 663 | ); |
| 664 | |
| 665 | const request = kernelConnection.requestExecute( |
| 666 | { |
| 667 | code: code.replace(/\r\n/g, '\n'), |
| 668 | silent: false, |
| 669 | stop_on_error: false, |
| 670 | allow_stdin: true, |
| 671 | store_history: false |
| 672 | }, |
| 673 | true |
| 674 | ); |
| 675 | const outputs: nbformat.IOutput[] = []; |
| 676 | request.onIOPub = (msg) => { |
| 677 | if (jupyterLab.KernelMessage.isStreamMsg(msg)) { |
| 678 | logger.ci(`Got io pub message (stream), ${splitLines(msg.content.text.substr(0, 100)).join('\\n')}`); |
| 679 | if ( |
| 680 | outputs.length > 0 && |
| 681 | outputs[outputs.length - 1].output_type === 'stream' && |
| 682 | outputs[outputs.length - 1].name === msg.content.name |
| 683 | ) { |
| 684 | const streamOutput = outputs[outputs.length - 1] as nbformat.IStream; |
| 685 | streamOutput.text += msg.content.text; |
| 686 | } else { |
| 687 | const streamOutput: nbformat.IStream = { |
| 688 | name: msg.content.name, |
| 689 | text: msg.content.text, |
| 690 | output_type: 'stream' |
| 691 | }; |
| 692 | outputs.push(streamOutput); |
| 693 | } |
| 694 | } else if (jupyterLab.KernelMessage.isExecuteResultMsg(msg)) { |
| 695 | logger.ci(`Got io pub message (execresult)}`); |
| 696 | const output: nbformat.IExecuteResult = { |
| 697 | data: msg.content.data, |
| 698 | execution_count: msg.content.execution_count, |
| 699 | metadata: msg.content.metadata, |
| 700 | output_type: 'execute_result' |
| 701 | }; |
| 702 | outputs.push(output); |
| 703 | } else if (jupyterLab.KernelMessage.isDisplayDataMsg(msg)) { |
| 704 | logger.ci(`Got io pub message (displaydata)}`); |
| 705 | const output: nbformat.IDisplayData = { |
| 706 | data: msg.content.data, |
| 707 | metadata: msg.content.metadata, |
| 708 | output_type: 'display_data' |
| 709 | }; |
| 710 | outputs.push(output); |
| 711 | } else if (jupyterLab.KernelMessage.isErrorMsg(msg)) { |
| 712 | logger.ci( |
| 713 | `Got io pub message (error), ${msg.content.ename},${msg.content.evalue}, ${msg.content.traceback |
no test coverage detected