Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rework of monitoring output execution together with execution phase #312

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,9 @@ packages/*/content
# Static
**/static/*

# VS Code settings
packages/react/.vscode/launch.json

# Include
!**/.*ignore
!**/.*rc
Expand Down
27 changes: 14 additions & 13 deletions packages/react/src/components/output/Output.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@
* MIT License
*/

import { useState, useEffect } from 'react';
import { Box } from '@primer/react';
import { IOutput } from '@jupyterlab/nbformat';
import { IOutputAreaModel } from '@jupyterlab/outputarea';
import { KernelMessage } from '@jupyterlab/services';
import { newUuid } from '../../utils';
import { Box } from '@primer/react';
import { useEffect, useState } from 'react';
import { useJupyter } from '../../jupyter/JupyterContext';
import { Kernel } from '../../jupyter/kernel/Kernel';
import { KernelActionMenu, KernelProgressBar } from './../kernel';
import { Lumino } from '../lumino/Lumino';
import { newUuid } from '../../utils';
import { CodeMirrorEditor } from '../codemirror/CodeMirrorEditor';
import { Lumino } from '../lumino/Lumino';
import { KernelActionMenu, KernelProgressBar } from './../kernel';
import { OutputAdapter } from './OutputAdapter';
import { OutputRenderer } from './OutputRenderer';
import { useOutputsStore } from './OutputState';

import { IExecutionPhaseOutput } from '../../jupyter/kernel';
import './Output.css';

export type IOutputProps = {
Expand All @@ -40,9 +41,9 @@ export type IOutputProps = {
showControl?: boolean;
showEditor: boolean;
showKernelProgressBar?: boolean;
suppressCodeExecutionErrors?: boolean;
toolbarPosition: 'up' | 'middle' | 'none';
notifyOnComplete?: boolean;
onCodeExecutionError?: (err : any) => void;
onExecutionPhaseChanged? : (phaseOutput : IExecutionPhaseOutput) => void
};

export const Output = (props: IOutputProps) => {
Expand All @@ -65,8 +66,8 @@ export const Output = (props: IOutputProps) => {
showControl,
showEditor,
showKernelProgressBar = true,
notifyOnComplete = false,
onCodeExecutionError,
suppressCodeExecutionErrors = false,
onExecutionPhaseChanged,
id: sourceId,
toolbarPosition,
} = props;
Expand Down Expand Up @@ -102,7 +103,7 @@ export const Output = (props: IOutputProps) => {
}
};
if (id && kernel) {
const adapter = propsAdapter ?? new OutputAdapter(id, kernel, outputs ?? [], model);
const adapter = propsAdapter ?? new OutputAdapter(id, kernel, outputs ?? [], model,suppressCodeExecutionErrors);
setAdapter(adapter);
outputStore.setAdapter(id, adapter);
if (model) {
Expand All @@ -126,7 +127,7 @@ export const Output = (props: IOutputProps) => {
useEffect(() => {
if (adapter) {
if (autoRun) {
adapter.execute(code, notifyOnComplete,onCodeExecutionError);
adapter.execute(code,onExecutionPhaseChanged);
}
}
}, [adapter]);
Expand All @@ -146,12 +147,12 @@ export const Output = (props: IOutputProps) => {
const executeRequest = outputStore.getExecuteRequest(sourceId);
useEffect(() => {
if (adapter && executeRequest && executeRequest === id) {
adapter.execute(code, notifyOnComplete,onCodeExecutionError);
adapter.execute(code,onExecutionPhaseChanged);
}
}, [executeRequest, adapter]);
useEffect(() => {
if (adapter && executeTrigger > 0) {
adapter.execute(code, notifyOnComplete,onCodeExecutionError);
adapter.execute(code,onExecutionPhaseChanged);
}
}, [executeTrigger]);
useEffect(() => {
Expand Down
29 changes: 16 additions & 13 deletions packages/react/src/components/output/OutputAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,13 @@
* MIT License
*/

import {
WIDGET_MIMETYPE,
WidgetRenderer,
} from '@jupyter-widgets/html-manager/lib/output_renderers';
import { rendererFactory as javascriptRendererFactory } from '@jupyterlab/javascript-extension';
import { rendererFactory as jsonRendererFactory } from '@jupyterlab/json-extension';
import { IOutput } from '@jupyterlab/nbformat';
import { JSONObject } from '@lumino/coreutils';
import {
IOutputAreaModel,
OutputArea,
Expand All @@ -16,14 +21,10 @@ import {
RenderMimeRegistry,
standardRendererFactories,
} from '@jupyterlab/rendermime';
import { rendererFactory as jsonRendererFactory } from '@jupyterlab/json-extension';
import { rendererFactory as javascriptRendererFactory } from '@jupyterlab/javascript-extension';
import {
WIDGET_MIMETYPE,
WidgetRenderer,
} from '@jupyter-widgets/html-manager/lib/output_renderers';
import { requireLoader as loader } from '../../jupyter/ipywidgets/libembed-amd';
import { JSONObject } from '@lumino/coreutils';
import { ClassicWidgetManager } from '../../jupyter/ipywidgets/classic/manager';
import { requireLoader as loader } from '../../jupyter/ipywidgets/libembed-amd';
import { IExecutionPhaseOutput } from '../../jupyter/kernel';
import { Kernel } from '../../jupyter/kernel/Kernel';
import { execute } from './OutputExecutor';

Expand All @@ -34,15 +35,18 @@ export class OutputAdapter {
private _outputArea: OutputArea;
private _rendermime: RenderMimeRegistry;
private _iPyWidgetsClassicManager: ClassicWidgetManager;
private _suppressCodeExecutionErrors: boolean;

public constructor(
id: string,
kernel?: Kernel,
outputs?: IOutput[],
outputAreaModel?: IOutputAreaModel
outputAreaModel?: IOutputAreaModel,
suppressCodeExecutionErrors: boolean = false
) {
this._id = id;
this._kernel = kernel;
this._suppressCodeExecutionErrors = suppressCodeExecutionErrors;
this._renderers = standardRendererFactories.filter(
factory => factory.mimeTypes[0] !== 'text/javascript'
);
Expand Down Expand Up @@ -93,8 +97,7 @@ export class OutputAdapter {

public async execute(
code: string,
notifyOnComplete?: boolean,
onCodeExecutionError?: (err: any) => void
onExecutionPhaseChanged?: (phaseOutput: IExecutionPhaseOutput) => void
) {
if (this._kernel) {
this.clear();
Expand All @@ -105,8 +108,8 @@ export class OutputAdapter {
this._outputArea,
this._kernel,
metadata,
notifyOnComplete,
onCodeExecutionError
this._suppressCodeExecutionErrors,
onExecutionPhaseChanged
);
await done;
}
Expand Down
14 changes: 8 additions & 6 deletions packages/react/src/components/output/OutputExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
* MIT License
*/

import { JSONObject } from '@lumino/coreutils';
import { KernelMessage } from '@jupyterlab/services';
import { OutputArea } from '@jupyterlab/outputarea';
import { KernelMessage } from '@jupyterlab/services';
import { JSONObject } from '@lumino/coreutils';
import { IExecutionPhaseOutput } from '../../jupyter/kernel';
import { Kernel } from './../../jupyter/kernel/Kernel';

/**
Expand All @@ -18,8 +19,8 @@ export async function execute(
output: OutputArea,
kernel: Kernel,
metadata?: JSONObject,
notifyOnComplete?: boolean,
onCodeExecutionError?: (err: any) => void
suppressCodeExecutionErrors: boolean = false,
onExecutionPhaseChanged?: (phaseOutput: IExecutionPhaseOutput) => void
): Promise<KernelMessage.IExecuteReplyMsg | undefined> {
// Override the default for `stop_on_error`.
let stopOnError = true;
Expand All @@ -33,9 +34,10 @@ export async function execute(
const kernelExecutor = kernel.execute(code, {
model: output.model,
stopOnError,
notifyOnComplete,
onCodeExecutionError,
suppressCodeExecutionErrors,
onExecutionPhaseChanged,
});

const future = kernelExecutor!.future;
// TODO fix in upstream jupyterlab if possible...
(output as any)._onIOPub = future!.onIOPub;
Expand Down
59 changes: 0 additions & 59 deletions packages/react/src/examples/OutputWithErrorHandle.tsx

This file was deleted.

Loading
Loading