Selaa lähdekoodia

Use a static function for cell execution

Steven Silvester 8 vuotta sitten
vanhempi
commit
56b16322e5

+ 32 - 28
packages/cells/src/widget.ts

@@ -489,7 +489,7 @@ class CodeCell extends Cell {
     // Set a CSS if there are no outputs, and connect a signal for future
     // changes to the number of outputs. This is for conditional styling
     // if there are no outputs.
-    if (model.outputs.length===0) {
+    if (model.outputs.length === 0) {
       this.addClass(NO_OUTPUTS_CLASS);
     }
     output.outputLengthChanged.connect(this._outputLengthHandler, this);
@@ -540,33 +540,6 @@ class CodeCell extends Cell {
     super.dispose();
   }
 
-  /**
-   * Execute the cell given a client session.
-   */
-  execute(session: IClientSession): Promise<KernelMessage.IExecuteReplyMsg> {
-    let model = this.model;
-    let code = model.value.text;
-    if (!code.trim() || !session.kernel) {
-      model.executionCount = null;
-      model.outputs.clear();
-      return Promise.resolve(null);
-    }
-    model.executionCount = null;
-    this.setPrompt('*');
-    this.model.trusted = true;
-
-    return this._output.execute(code, session).then(reply => {
-      let status = reply.content.status;
-      if (status === 'abort') {
-        model.executionCount = null;
-        this.setPrompt(' ');
-      } else {
-        model.executionCount = reply.content.execution_count;
-      }
-      return reply;
-    });
-  }
-
   /**
    * Handle `update-request` messages.
    */
@@ -643,6 +616,37 @@ namespace CodeCell {
     rendermime: RenderMime;
   }
 
+  /**
+   * Execute a cell given a client session.
+   */
+  export
+  function execute(cell: CodeCell, session: IClientSession): Promise<KernelMessage.IExecuteReplyMsg> {
+    let model = cell.model;
+    let code = model.value.text;
+    if (!code.trim() || !session.kernel) {
+      model.executionCount = null;
+      model.outputs.clear();
+      return Promise.resolve(void 0);
+    }
+
+    model.executionCount = null;
+    cell.setPrompt('*');
+
+    // Override the default for `stop_on_error`.
+    let content: KernelMessage.IExecuteRequest = {
+      code,
+      stop_on_error: true
+    };
+
+    let future = session.kernel.requestExecute(content);
+    model.trusted = true;
+    cell.outputArea.future = future;
+
+    return future.done.then((msg: KernelMessage.IExecuteReplyMsg) => {
+      model.executionCount = msg.content.execution_count;
+      return msg;
+    });
+  }
 }
 
 

+ 2 - 2
packages/console/src/widget.ts

@@ -462,7 +462,7 @@ class CodeConsole extends Widget {
     // do in IPython or QtConsole.
     if ( source === 'clear' || source === '%clear' ) {
       this.clear();
-      return Promise.resolve(void 0)
+      return Promise.resolve(void 0);
     }
     cell.model.contentChanged.connect(this.update, this);
     let onSuccess = (value: KernelMessage.IExecuteReplyMsg) => {
@@ -494,7 +494,7 @@ class CodeConsole extends Widget {
       cell.model.contentChanged.disconnect(this.update, this);
       this.update();
     };
-    return cell.execute(this.session).then(onSuccess, onFailure);
+    return CodeCell.execute(cell, this.session).then(onSuccess, onFailure);
   }
 
   /**

+ 1 - 1
packages/notebook/src/actions.ts

@@ -980,7 +980,7 @@ namespace Private {
       break;
     case 'code':
       if (session) {
-        return (child as CodeCell).execute(session).then(reply => {
+        return CodeCell.execute(child as CodeCell, session).then(reply => {
           if (child.isDisposed) {
             return false;
           }

+ 0 - 4
packages/services/src/kernel/kernel.ts

@@ -1,10 +1,6 @@
 // Copyright (c) Jupyter Development Team.
 // Distributed under the terms of the Modified BSD License.
 
-import {
-  nbformat
-} from '@jupyterlab/coreutils';
-
 import {
   IIterator
 } from '@phosphor/algorithm';