annotate scripts/miscellaneous/jupyter_notebook.m @ 31247:3dae836c598c

doc: Expand and edit documentation for memoization (bug #60860)
author Arun Giridhar <arungiridhar@gmail.com>
date Fri, 30 Sep 2022 06:38:59 -0400
parents 1b96856b88ef
children 597f3ee61a48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
30376
c23dafed5ffd maint: Use same Copyright code block in all files.
Rik <rik@octave.org>
parents: 30353
diff changeset
1 ########################################################################
c23dafed5ffd maint: Use same Copyright code block in all files.
Rik <rik@octave.org>
parents: 30353
diff changeset
2 ##
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30388
diff changeset
3 ## Copyright (C) 2021-2022 The Octave Project Developers
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
4 ##
30376
c23dafed5ffd maint: Use same Copyright code block in all files.
Rik <rik@octave.org>
parents: 30353
diff changeset
5 ## See the file COPYRIGHT.md in the top-level directory of this
c23dafed5ffd maint: Use same Copyright code block in all files.
Rik <rik@octave.org>
parents: 30353
diff changeset
6 ## distribution or <https://octave.org/copyright/>.
c23dafed5ffd maint: Use same Copyright code block in all files.
Rik <rik@octave.org>
parents: 30353
diff changeset
7 ##
c23dafed5ffd maint: Use same Copyright code block in all files.
Rik <rik@octave.org>
parents: 30353
diff changeset
8 ## Octave is free software: you can redistribute it and/or modify it
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
9 ## under the terms of the GNU General Public License as published by
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
10 ## the Free Software Foundation, either version 3 of the License, or
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
11 ## (at your option) any later version.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
12 ##
30376
c23dafed5ffd maint: Use same Copyright code block in all files.
Rik <rik@octave.org>
parents: 30353
diff changeset
13 ## Octave is distributed in the hope that it will be useful, but
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
14 ## WITHOUT ANY WARRANTY; without even the implied warranty of
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
15 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
16 ## GNU General Public License for more details.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
17 ##
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
18 ## You should have received a copy of the GNU General Public License
30376
c23dafed5ffd maint: Use same Copyright code block in all files.
Rik <rik@octave.org>
parents: 30353
diff changeset
19 ## along with Octave; see the file COPYING. If not, see
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
20 ## <https://www.gnu.org/licenses/>.
30376
c23dafed5ffd maint: Use same Copyright code block in all files.
Rik <rik@octave.org>
parents: 30353
diff changeset
21 ##
c23dafed5ffd maint: Use same Copyright code block in all files.
Rik <rik@octave.org>
parents: 30353
diff changeset
22 ########################################################################
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
23
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
24 classdef jupyter_notebook < handle
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
25
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
26 ## -*- texinfo -*-
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
27 ## @deftypefn {} {@var{notebook} =} jupyter_notebook (@var{notebook_filename})
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
28 ## @deftypefnx {} {@var{notebook} =} jupyter_notebook (@var{notebook_filename}, @var{options})
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
29 ##
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
30 ## Run and fill the Jupyter Notebook in file @var{notebook_filename} from
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
31 ## within GNU Octave.
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
32 ##
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
33 ## Both text and graphical Octave outputs are supported.
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
34 ##
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
35 ## This class has a public property @code{notebook} which is a structure
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
36 ## representing the JSON-decoded Jupyter Notebook. This property is
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
37 ## intentionally public to enable advanced notebook manipulations.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
38 ##
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
39 ## Note: Jupyter Notebook versions (@code{nbformat}) lower than 4.0 are not
30353
212461a26e9c doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30294
diff changeset
40 ## supported.
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
41 ##
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
42 ## The optional second argument @var{options} is a struct with fields:
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
43 ##
30294
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
44 ## @itemize @bullet
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
45 ## @item
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
46 ## @code{tmpdir} to set the temporary working directory.
30294
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
47 ## @end itemize
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
48 ##
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
49 ## @code{%plot} magic is supported with the following settings:
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
50 ##
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
51 ## @itemize @bullet
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
52 ## @item
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
53 ## "%plot -f <format>" or "%plot --format <format>": specifies the
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
54 ## image storage format. Supported formats are:
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
55 ##
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
56 ## @itemize @minus
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
57 ## @item
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
58 ## PNG (default)
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
59 ##
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
60 ## @item SVG
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
61 ## (Note: If SVG images do not appear in the notebook, it is most likely
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
62 ## related to Jupyter Notebook security mechanisms and explicitly "trusting"
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
63 ## them will be necessary).
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
64 ##
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
65 ## @item
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
66 ## JPG
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
67 ## @end itemize
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
68 ##
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
69 ## @item
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
70 ## "%plot -r <number>" or "%plot --resolution <number>": specifies the
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
71 ## image resolution.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
72 ##
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
73 ## @item
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
74 ## "%plot -w <number>" or "%plot --width <number>": specifies the
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
75 ## image width.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
76 ##
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
77 ## @item
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
78 ## "%plot -h <number>" or "%plot --height <number>": specifies the
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
79 ## image height.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
80 ## @end itemize
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
81 ##
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
82 ## Examples:
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
83 ##
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
84 ## @example
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
85 ## @group
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
86 ## ## Run all cells and generate the filled notebook
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
87 ##
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
88 ## ## Instantiate an object from a notebook file
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
89 ## notebook = jupyter_notebook ("myNotebook.ipynb");
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
90 ## ## Run the code and embed the results in the @code{notebook} property
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
91 ## notebook.run_all ();
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
92 ## ## Generate a new notebook by overwriting the original notebook
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
93 ## notebook.generate_notebook ("myNotebook.ipynb");
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
94 ## @end group
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
95 ##
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
96 ## @group
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
97 ## ## Run just the second cell and generate the filled notebook
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
98 ##
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
99 ## ## Instantiate an object from a notebook file
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
100 ## notebook = jupyter_notebook ("myNotebook.ipynb");
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
101 ## ## Run the code and embed the results in the @code{notebook} property
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
102 ## notebook.run (2)
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
103 ## ## Generate a new notebook in a new file
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
104 ## notebook.generate_notebook ("myNewNotebook.ipynb");
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
105 ## @end group
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
106 ##
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
107 ## @group
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
108 ## ## Generate an Octave script from a notebook
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
109 ##
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
110 ## ## Instantiate an object from a notebook file
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
111 ## notebook = jupyter_notebook ("myNotebook.ipynb");
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
112 ## ## Generate the Octave script
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
113 ## notebook.generate_octave_script ("jup_script.m");
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
114 ## @end group
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
115 ## @end example
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
116 ##
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
117 ## @seealso{jsondecode, jsonencode}
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
118 ## @end deftypefn
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
119
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
120 properties
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
121
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
122 notebook = struct ();
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
123
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
124 endproperties
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
125
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
126 properties (Access = "private")
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
127
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
128 context = struct ("ans", "");
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
129
30294
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
130 ## Note: This name needs to be stored in a property because it is
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
131 ## set in the constructor but used in some other methods. However,
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
132 ## we want to defer calling tempname() until immediately before
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
133 ## calling mkdir(). The temporary directory currently created and
30294
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
134 ## deleted in the constructor and the name is reset to the empty
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
135 ## string when the directory is deleted. Another possible
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
136 ## implementation might be to generate the name and create the
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
137 ## temporary directory here, then delete it in the class destructor.
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
138
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
139 tmpdir = "";
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
140
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
141 endproperties
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
142
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
143 methods
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
144
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
145 function obj = jupyter_notebook (notebook_filename, options)
30294
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
146
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
147 if (nargin < 1)
30294
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
148 print_usage ();
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
149 endif
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
150
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
151 if (! (ischar (notebook_filename) && isrow (notebook_filename)))
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
152 error ("jupyter_notebook: NOTEBOOK_FILENAME must be a string");
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
153 endif
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
154
30294
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
155 ## Validate options if present.
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
156 if (nargin == 2 && ! isstruct (options))
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
157 error ("jupyter_notebook: OPTIONS must be a struct");
30294
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
158 endif
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
159 if (nargin == 2 && isfield (options, "tmpdir"))
30294
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
160 obj.tmpdir = options.tmpdir;
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
161 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
162
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
163 obj.notebook = jsondecode (fileread (notebook_filename),
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
164 "makeValidName", false);
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
165
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
166 ## Validate the notebook's format according to nbformat: 4.0
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
167 if (! all (isfield (obj.notebook,
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
168 {"metadata", "nbformat", "nbformat_minor", "cells"})))
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
169 error ("jupyter_notebook: invalid format for Jupyter notebooks");
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
170 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
171
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
172 ## Issue a warning if the format is lower than 4.0.
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
173 if (obj.notebook.nbformat < 4)
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
174 warning (["jupyter_notebook: nbformat versions lower than 4.0 are ", ...
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
175 "not supported"]);
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
176 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
177
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
178 ## Handle the case of only one cell.
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
179 ## Make "obj.notebook.cells" a cell of structs to match the format.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
180 if (numel (obj.notebook.cells) == 1)
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
181 obj.notebook.cells = {obj.notebook.cells};
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
182 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
183
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
184 ## Handle the case where the cells have the same keys.
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
185 ## Make "obj.notebook.cells" a cell of structs, instead of struct array,
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
186 ## to unify the indexing method.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
187 if (isstruct (obj.notebook.cells))
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
188 obj.notebook.cells = num2cell (obj.notebook.cells);
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
189 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
190
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
191 for i = 1:numel (obj.notebook.cells)
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
192 nbcell = obj.notebook.cells{i};
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
193 if (! isfield (nbcell, "source"))
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
194 error ('jupyter_notebook: cells must contain a "source" field');
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
195 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
196
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
197 if (! isfield (nbcell, "cell_type"))
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
198 error ('jupyter_notebook: cells must contain a "cell_type" field');
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
199 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
200
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
201 ## Handle null JSON values which are decoded into empty arrays.
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
202 if (isfield (nbcell, "execution_count")
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
203 && numel (nbcell.execution_count) == 0)
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
204 obj.notebook.cells{i}.execution_count = 1;
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
205 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
206
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
207 ## Handle the case of only one output in the cell.
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
208 ## Make the outputs of the cell a cell of structs to match the format.
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
209 if (isfield (nbcell, "outputs") && numel (nbcell.outputs) == 1)
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
210 obj.notebook.cells{i}.outputs = {obj.notebook.cells{i}.outputs};
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
211 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
212 endfor
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
213
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
214 endfunction
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
215
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
216
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
217 function generate_octave_script (obj, script_filename)
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
218
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
219 ## -*- texinfo -*-
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
220 ## @deftypefn {} {} generate_octave_script (@var{script_filename})
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
221 ##
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
222 ## Write an Octave script that has the contents of the Jupyter Notebook
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
223 ## stored in the @code{notebook} attribute to @var{script_filename}.
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
224 ##
30353
212461a26e9c doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30294
diff changeset
225 ## Non-code cells are generated as block comments.
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
226 ##
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
227 ## See @code{help jupyter_notebook} for examples.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
228 ##
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
229 ## @seealso{jupyter_notebook}
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
230 ## @end deftypefn
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
231
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
232 if (nargin != 2)
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
233 print_usage ();
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
234 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
235
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
236 if (! (ischar (script_filename) && isrow (script_filename)))
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
237 error ("jupyter_notebook: SCRIPT_FILENAME must be a string");
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
238 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
239
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
240 fid = fopen (script_filename, "w");
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
241
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
242 for i = 1:numel (obj.notebook.cells)
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
243 nbcell = obj.notebook.cells{i};
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
244 is_markdown = strcmp (nbcell.cell_type, "markdown");
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
245
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
246 if (is_markdown)
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
247 fputs (fid, "\n#{\n");
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
248 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
249
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
250 for k = 1:numel (nbcell.source)
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
251 fputs (fid, nbcell.source{k});
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
252 endfor
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
253
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
254 if (is_markdown)
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
255 fputs (fid, "\n#}\n");
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
256 endif
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
257 fputs (fid, "\n");
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
258 endfor
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
259 fclose (fid);
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
260
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
261 endfunction
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
262
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
263
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
264 function generate_notebook (obj, notebook_filename)
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
265
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
266 ## -*- texinfo -*-
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
267 ## @deftypefn {} {} generate_notebook (@var{notebook_filename})
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
268 ##
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
269 ## Write the Jupyter Notebook stored in the @code{notebook}
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
270 ## attribute to @var{notebook_filename}.
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
271 ##
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
272 ## The @code{notebook} attribute is encoded to JSON text.
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
273 ##
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
274 ## See @code{help jupyter_notebook} for examples.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
275 ##
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
276 ## @seealso{jupyter_notebook}
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
277 ## @end deftypefn
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
278
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
279 if (nargin != 2)
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
280 print_usage ();
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
281 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
282
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
283 if (! (ischar (notebook_filename) && isrow (notebook_filename)))
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
284 error ("jupyter_notebook: NOTEBOOK_FILENAME must be a string");
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
285 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
286
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
287 fid = fopen (notebook_filename, "w");
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
288
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
289 fputs (fid, jsonencode (obj.notebook,
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
290 "ConvertInfAndNaN", false,
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
291 "PrettyPrint", true));
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
292
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
293 fclose (fid);
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
294
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
295 endfunction
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
296
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
297
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
298 function run (obj, cell_index)
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
299
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
300 ## -*- texinfo -*-
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
301 ## @deftypefn {} {} run (@var{cell_index})
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
302 ##
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
303 ## Run the Jupyter Notebook cell with index @var{cell_index}
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
304 ## and eventually replace previous output cells in the object.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
305 ##
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
306 ## The first Jupyter Notebook cell has the index 1.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
307 ##
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
308 ## Note: The code evaluation of the Jupyter Notebook cells is done
30353
212461a26e9c doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30294
diff changeset
309 ## in a separate Jupyter Notebook context. Thus, currently open
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
310 ## figures and workspace variables won't be affected by executing
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
311 ## this function. However, current workspace variables cannot be
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
312 ## accessed either.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
313 ##
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
314 ## See @code{help jupyter_notebook} for examples.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
315 ##
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
316 ## @seealso{jupyter_notebook}
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
317 ## @end deftypefn
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
318
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
319 if (nargin != 2)
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
320 print_usage ();
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
321 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
322
30382
82ffc35691ad jupyter_notebook.m: fix typo in cset 363fb10055df.
Rik <rik@octave.org>
parents: 30381
diff changeset
323 if (! (isscalar (cell_index) && isindex (cell_index)))
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
324 error ("jupyter_notebook: CELL_INDEX must be a scalar positive integer");
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
325 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
326
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
327 if (cell_index > numel (obj.notebook.cells))
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
328 error ("jupyter_notebook: CELL_INDEX is out of bound");
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
329 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
330
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
331 nbcell = obj.notebook.cells{cell_index};
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
332
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
333 if (! strcmp (nbcell.cell_type, "code"))
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
334 return;
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
335 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
336
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
337 ## Remove previous outputs.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
338 obj.notebook.cells{cell_index}.outputs = {};
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
339
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
340 if (isempty (nbcell.source))
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
341 return;
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
342 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
343
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
344 ## Default values for printOptions.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
345 printOptions.imageFormat = "png";
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
346 printOptions.resolution = "0";
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
347
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
348 ## The default width and height in Jupyter notebook
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
349 printOptions.width = "640";
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
350 printOptions.height = "480";
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
351
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
352 ## Parse "plot magic" commands.
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
353 ## https://github.com/Calysto/metakernel/blob/master/metakernel/magics/README.md#plot
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
354 for j = 1 : numel (nbcell.source)
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
355 if (strncmpi (nbcell.source{j}, "%plot", 5))
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
356 magics = strsplit (strtrim (nbcell.source{j}));
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
357 for i = 1 : numel (magics)
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
358 if (any (strcmp (magics{i}, {"-f", "--format"}))
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
359 && (i < numel (magics)))
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
360 printOptions.imageFormat = magics{i+1};
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
361 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
362 if (any (strcmp (magics{i}, {"-r", "--resolution"}))
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
363 && (i < numel (magics)))
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
364 printOptions.resolution = magics{i+1};
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
365 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
366 if (any (strcmp (magics{i}, {"-w", "--width"}))
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
367 && (i < numel (magics)))
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
368 printOptions.width = magics{i+1};
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
369 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
370 if (any (strcmp (magics{i}, {"-h", "--height"}))
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
371 && (i < numel (magics)))
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
372 printOptions.height = magics{i+1};
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
373 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
374 endfor
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
375 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
376 endfor
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
377
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
378 ## Remember previously opened figures.
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
379 fig_ids = findall (groot, "type", "figure");
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
380
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
381 ## Create a new figure, if there are existing plots.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
382 if (! isempty (fig_ids))
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
383 newFig = figure ();
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
384 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
385
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
386 stream_output = struct ("name", "stdout", "output_type", "stream");
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
387
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
388 output_lines = obj.evalCode (strjoin (nbcell.source));
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
389
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
390 if (! isempty (output_lines))
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
391 stream_output.text = {output_lines};
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
392 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
393
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
394 if (isfield (stream_output, "text"))
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
395 obj.notebook.cells{cell_index}.outputs{end+1} = stream_output;
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
396 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
397
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
398 ## If there are existing plots and newFig is empty, delete it.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
399 if (exist ("newFig") && isempty (get (newFig, "children")))
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
400 delete (newFig);
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
401 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
402
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
403 ## Check for newly created figures.
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
404 fig_ids_new = setdiff (findall (groot, "type", "figure"), fig_ids);
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
405
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
406 if (! isempty (fig_ids_new))
30294
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
407 if (! isempty (obj.tmpdir) && exist (obj.tmpdir, "dir"))
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
408 ## Delete open figures before raising the error.
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
409 delete (fig_ids_new);
30294
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
410 error (["JupyterNotebook: temporary directory %s exists. ", ...
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
411 "Please remove it manually."], obj.tmpdir);
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
412 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
413
30294
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
414 if (isempty (obj.tmpdir))
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
415 obj.tmpdir = tempname ();
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
416 clear_tmpdir_property = true;
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
417 else
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
418 clear_tmpdir_property = false;
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
419 endif
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
420 [status, msg] = mkdir (obj.tmpdir);
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
421 if (status == 0)
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
422 ## Delete open figures before raising the error.
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
423 delete (fig_ids_new);
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
424 error (["jupyter_notebook: cannot create a temporary directory. ", ...
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
425 msg]);
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
426 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
427
30294
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
428 ## FIXME: Maybe it would be better for these cleanup actions to
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
429 ## happen in an onCleanup object or unwind_protect block so that
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
430 ## they will be executed no matter how we exit this function?
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
431
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
432 for i = 1:numel (fig_ids_new)
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
433 figure (fig_ids_new(i), "visible", "off");
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
434 obj.embedImage (cell_index, fig_ids_new(i), printOptions);
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
435 delete (fig_ids_new(i));
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
436 endfor
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
437
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
438 [status, msg] = rmdir (obj.tmpdir);
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
439 if (status == 0)
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
440 error (["jupyter_notebook: cannot delete the temporary ", ...
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
441 "directory. ", msg]);
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
442 endif
30294
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
443 if (clear_tmpdir_property)
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
444 obj.tmpdir = "";
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
445 endif
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
446 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
447
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
448 endfunction
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
449
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
450
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
451 function run_all (obj)
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
452
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
453 ## -*- texinfo -*-
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
454 ## @deftypefn {} {} run_all ()
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
455 ##
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
456 ## Run all Jupyter Notebook cells and eventually replace previous
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
457 ## output cells in the object.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
458 ##
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
459 ## Note: The code evaluation of the Jupyter Notebook cells is done
30353
212461a26e9c doc: grammarcheck m-files in scripts/ directory ahead of 7.1 release.
Rik <rik@octave.org>
parents: 30294
diff changeset
460 ## in a separate Jupyter Notebook context. Thus, currently open
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
461 ## figures and workspace variables won't be affected by executing
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
462 ## this function. However, current workspace variables cannot be
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
463 ## accessed either.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
464 ##
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
465 ## See @code{help jupyter_notebook} for examples.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
466 ##
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
467 ## @seealso{jupyter_notebook}
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
468 ## @end deftypefn
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
469
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
470 if (nargin != 1)
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
471 print_usage ();
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
472 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
473
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
474 for i = 1:numel (obj.notebook.cells)
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
475 obj.run (i);
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
476 endfor
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
477
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
478 endfunction
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
479
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
480 endmethods
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
481
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
482
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
483 methods (Access = "private")
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
484
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
485 function retval = evalCode (__obj__, __code__)
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
486
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
487 ## Evaluate the code string "__code__" using "evalc".
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
488 ## Before the code is evaluated, the previous notebook context is
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
489 ## loaded from "__obj__" and the new context is saved to that struct.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
490
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
491 if (nargin != 2)
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
492 print_usage ();
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
493 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
494
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
495 if (isempty (__code__))
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
496 retval = [];
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
497 return;
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
498 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
499
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
500 if (! (ischar (__code__) && isrow (__code__)))
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
501 error ("jupyter_notebook: CODE must be a string");
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
502 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
503
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
504 __obj__.loadContext ();
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
505
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
506 ## Add a statement to detect the value of the variable "ans"
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
507 __code__ = [__code__, "\nans"];
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
508
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
509 retval = strtrim (evalc (__code__, ["printf (\"error: \"); ", ...
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
510 "printf (lasterror.message)"]));
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
511
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
512 ## Handle the "ans" variable in the context.
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
513 start_index = rindex (retval, "ans =") + 6;
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
514 if (start_index > 6)
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
515 if (start_index <= length (retval))
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
516 end_index = start_index;
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
517 ## FIXME: loops are slow.
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
518 idx = find (retval(start_index+1:end) == "\n", 1);
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
519 if (idx)
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
520 end_index = start_index + idx;
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
521 else
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
522 end_index = length (retval);
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
523 endif
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
524 __obj__.context.ans = retval(start_index:end_index);
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
525 else
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
526 end_index = length (retval);
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
527 __obj__.context.ans = "";
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
528 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
529
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
530 ## Delete the output of the additional statement if the execution
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
531 ## is completed with no errors.
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
532 if (end_index == length (retval))
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
533 ## Remove the extra new line if there are other outputs with
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
534 ## the "ans" statement output
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
535 if (start_index == 7)
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
536 start_index = 1;
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
537 else
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
538 start_index -= 7;
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
539 endif
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
540 retval(start_index:end_index) = "";
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
541 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
542 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
543
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
544 __obj__.saveContext ();
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
545
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
546 endfunction
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
547
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
548
30755
1b96856b88ef jupyter_notebook.m (saveContext): remove unused parameter
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 30564
diff changeset
549 function saveContext (obj)
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
550
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
551 ## Save the context in private "obj" attribute.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
552
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
553 ## Handle the "ans" variable in the context.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
554 obj.context = struct ("ans", obj.context.ans);
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
555
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
556 forbidden_var_names = {"__code__", "__obj__", "ans"};
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
557
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
558 ## Get variable names.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
559 var_names = {evalin("caller", "whos").name};
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
560
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
561 ## Store all variables to context.
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
562 for i = 1:numel (var_names)
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
563 if (! any (strcmp (var_names{i}, forbidden_var_names)))
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
564 obj.context.(var_names{i}) = evalin ("caller", var_names{i});
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
565 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
566 endfor
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
567
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
568 endfunction
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
569
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
570
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
571 function loadContext (obj)
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
572
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
573 ## Load the context from private "obj" attribute.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
574 for [val, key] = obj.context
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
575 assignin ("caller", key, val);
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
576 endfor
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
577
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
578 endfunction
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
579
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
580
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
581 function embedImage (obj, cell_index, figHandle, printOptions)
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
582
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
583 ## Embed images in the notebook.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
584 ##
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
585 ## To support a new format:
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
586 ## 1. Create a new function that embeds the new format
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
587 ## (e.g. embed_svg_image).
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
588 ## 2. Add a new case to the switch-statement below.
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
589
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
590 if (isempty (get (figHandle, "children")))
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
591 error_text = {"The figure is empty!"};
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
592 obj.addErrorOutput (cell_index, "The figure is empty!");
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
593 return;
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
594 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
595
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
596 ## Check if the resolution is correct
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
597 if (isempty (str2num (printOptions.resolution)))
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
598 obj.addErrorOutput (cell_index,
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
599 "A number is required for resolution, not a string");
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
600 return;
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
601 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
602
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
603 ## Check if the width is correct
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
604 if (isempty (str2num (printOptions.width)))
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
605 obj.addErrorOutput (cell_index,
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
606 "A number is required for width, not a string");
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
607 return;
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
608 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
609
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
610 ## Check if the height is correct
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
611 if (isempty (str2num (printOptions.height)))
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
612 obj.addErrorOutput (cell_index,
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
613 "A number is required for height, not a string");
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
614 return;
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
615 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
616
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
617 switch (lower (printOptions.imageFormat))
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
618 case "png"
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
619 display_output = obj.embed_png_jpg_image (figHandle,
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
620 printOptions, "png");
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
621 case "jpg"
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
622 display_output = obj.embed_png_jpg_image (figHandle,
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
623 printOptions, "jpg");
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
624 case "svg"
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
625 display_output = obj.embed_svg_image (figHandle, printOptions);
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
626 otherwise
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
627 obj.addErrorOutput (cell_index, ["Cannot embed the \'", ...
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
628 printOptions.imageFormat, ...
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
629 "\' image format\n"]);
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
630 return;
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
631 endswitch
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
632
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
633 obj.notebook.cells{cell_index}.outputs{end+1} = display_output;
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
634
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
635 endfunction
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
636
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
637
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
638 function dstruct = embed_png_jpg_image (obj, figHandle, printOptions, fmt)
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
639
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
640 if (strcmp (fmt, "png"))
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
641 mime = "image/png";
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
642 else
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
643 mime = "image/jpeg";
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
644 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
645
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
646 image_path = fullfile (obj.tmpdir, ["temp." fmt]);
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
647 print (figHandle, image_path, ["-d" fmt],
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
648 ["-r" printOptions.resolution]);
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
649
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
650 dstruct.output_type = "display_data";
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
651 dstruct.metadata.(mime).width = printOptions.width;
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
652 dstruct.metadata.(mime).height = printOptions.height;
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
653 dstruct.data.("text/plain") = {"<IPython.core.display.Image object>"};
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
654 dstruct.data.(mime) = base64_encode (uint8 (fileread (image_path)));
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
655
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
656 delete (image_path);
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
657
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
658 endfunction
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
659
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
660
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
661 function dstruct = embed_svg_image (obj, figHandle, printOptions)
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
662
30294
488548c762de jupyter_notebook: don't hardwire tmp directory name (bug #61470)
John W. Eaton <jwe@octave.org>
parents: 30293
diff changeset
663 image_path = fullfile (obj.tmpdir, "temp.svg");
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
664 print (figHandle, image_path, "-dsvg", ["-r" printOptions.resolution]);
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
665
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
666 dstruct.output_type = "display_data";
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
667 dstruct.metadata = struct ();
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
668 dstruct.data.("text/plain") = {"<IPython.core.display.SVG object>"};
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
669 dstruct.data.("image/svg+xml") = strsplit (fileread (image_path), "\n");
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
670
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
671 ## FIXME: The following is a workaround until we can properly print
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
672 ## SVG images in the right width and height.
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
673 ## Detect the <svg> tag; it is either the first or the second item.
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
674 if (strncmpi (dstruct.data.("image/svg+xml"){1}, "<svg", 4))
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
675 i = 1;
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
676 else
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
677 i = 2;
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
678 endif
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
679
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
680 ## Embed the width and height in the image itself
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
681 svg_tag = dstruct.data.("image/svg+xml"){i};
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
682 svg_tag = regexprep (svg_tag, 'width=".*?"',
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
683 ['width="' printOptions.width 'px"']);
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
684 svg_tag = regexprep (svg_tag, 'height=".*?"',
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
685 ['height="' printOptions.height 'px"']);
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
686 dstruct.data.("image/svg+xml"){i} = svg_tag;
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
687
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
688 delete (image_path);
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
689
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
690 endfunction
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
691
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
692
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
693 function addErrorOutput (obj, cell_index, error_msg)
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
694
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
695 stream_output.name = "stderr";
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
696 stream_output.output_type = "stream";
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
697 stream_output.text = {error_msg};
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
698 obj.notebook.cells{cell_index}.outputs{end+1} = stream_output;
30293
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
699
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
700 endfunction
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
701
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
702 endmethods
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
703
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
704 endclassdef
1a1f3ae76e74 Use underscores instead of CamelCase in jupyter_notebook classdef
Abdallah Elshamy <abdallah.k.elshamy@gmail.com>
parents:
diff changeset
705
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
706
30388
bf4cea7b9ba8 maint: jupyter_notebook.m: describe BIST location.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 30382
diff changeset
707 ## Note: Functional BIST tests are located in the 'test/jupyter-notebook'
bf4cea7b9ba8 maint: jupyter_notebook.m: describe BIST location.
Kai T. Ohlhus <k.ohlhus@gmail.com>
parents: 30382
diff changeset
708 ## directory.
30381
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
709
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
710 ## Test input validation
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
711 %!error <Invalid call> jupyter_notebook ()
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
712 %!error <NOTEBOOK_FILENAME must be a string> jupyter_notebook (1)
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
713 %!error <NOTEBOOK_FILENAME must be a string> jupyter_notebook (['a';'b'])
e0ed29a523b2 jupyter_notebook.m: review code and update to use more Octave coding standards.
Rik <rik@octave.org>
parents: 30376
diff changeset
714 %!error <OPTIONS must be a struct> jupyter_notebook ("fname", 1)