Module: utils/notebookGenerator

Jupyter Notebook Generator for AutoRA Workflows Produces the same Python program as the Python code generator, but split into ordered notebook cells. The first code cell installs every package required by the imports that follow.
Source:

Methods

(static) generateNotebook(state) → {Object}

Generate a Jupyter notebook (parsed JSON object) from workflow state.
Parameters:
Name Type Description
state Object Editor state with `nodes`, `connections` and `components`.
Source:
Returns:
Jupyter notebook object with `cells`, `metadata`, `nbformat` and `nbformat_minor`.
Type
Object

(static) generateNotebookString(state) → {string}

Generate the notebook as a formatted JSON string ready to write to a `.ipynb` file.
Parameters:
Name Type Description
state Object Editor state with `nodes`, `connections` and `components`.
Source:
Returns:
Notebook serialized as a formatted JSON string.
Type
string

(inner) buildRunCell(blocks, componentMeta) → {string}

Build the "run the workflow" code cell. Unlike the standalone Python file, the notebook runs the loop at top level so each cycle's state is inspectable.
Parameters:
Name Type Description
blocks Array.<Block> Ordered execution block tree (see getExecutionOrder in pythonGenerator; `Block` is defined there).
componentMeta Map Map of node id to component metadata (`varName`, `nodeName`, `pythonName`).
Source:
Returns:
Python source for the run cell.
Type
string

(inner) codeCell(text) → {Object}

Build a notebook code cell from a block of source text.
Parameters:
Name Type Description
text string Python source text.
Source:
Returns:
Jupyter code cell object.
Type
Object

(inner) dedent(text) → {string}

Remove a single level (4 spaces) of leading indentation from each line so function-body templates can be reused at notebook top level.
Parameters:
Name Type Description
text string Indented multi-line source text.
Source:
Returns:
Text with one 4-space indent level removed from each line.
Type
string

(inner) markdownCell(text) → {Object}

Build a notebook markdown cell from one or more lines of text.
Parameters:
Name Type Description
text string Markdown source text.
Source:
Returns:
Jupyter markdown cell object.
Type
Object

(inner) toSource(text) → {Array.<string>}

Convert a string into the array-of-lines form Jupyter uses for `source`, where every line except the last keeps its trailing newline.
Parameters:
Name Type Description
text string Multi-line source text.
Source:
Returns:
Array of lines, each but the last ending in a newline.
Type
Array.<string>