├── README.md ├── jupyter-shape-commentator.yaml ├── LICENSE ├── README-old.md └── jupyter-shape-commentator.js /README.md: -------------------------------------------------------------------------------- 1 | Sorry, this extension is deprecated. 2 | Please use Shape Commentator IPython Extension instead. 3 | 4 | このツールは,廃止予定です. 5 | 代わりに,Shape CommentatorのIPython拡張が使えます. 6 | 7 | https://github.com/shiba6v/shape_commentator 8 | -------------------------------------------------------------------------------- /jupyter-shape-commentator.yaml: -------------------------------------------------------------------------------- 1 | Type: IPython Notebook Extension 2 | Name: Jupyter Shape Commentator 3 | Description: You can add shape comments to your code. 4 | Link: README.md 5 | Main: jupyter-shape-commentator.js 6 | Compatibility: 4.x, 5.x -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 shiba6v 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README-old.md: -------------------------------------------------------------------------------- 1 | ## About 2 | This is a Jupyter Notebook NBExtension of [ShapeCommentator](https://github.com/shiba6v/shape_commentator) 3 | 4 | ![sample](https://user-images.githubusercontent.com/13820488/62421463-0cc86c80-b6dd-11e9-84bb-44749d6078f3.gif) 5 | 6 | ## Supported Python Version 7 | - Python 3.x 8 | 9 | Python 2.x is not supported. 10 | 11 | ## Installation 12 | ``` 13 | # Install shape_commentator 0.6.2 or later 14 | pip install -U shape_commentator 15 | jupyter nbextension install https://github.com/shiba6v/jupyter-shape-commentator/archive/master.zip --user 16 | ``` 17 | 18 | Then, enable "Jupyter Shape Commentator" at Nbextensions tab in the notebook. 19 | 20 | ![activation](https://user-images.githubusercontent.com/13820488/61187745-12b7c880-a6b0-11e9-8d94-564192345aca.png) 21 | 22 | ## Usage 23 | 24 | ![usage](https://user-images.githubusercontent.com/13820488/61187744-11869b80-a6b0-11e9-8fea-8e65da84f64c.png) 25 | 26 | ![use_fig](https://user-images.githubusercontent.com/13820488/61187795-fcf6d300-a6b0-11e9-97c6-4fd029244839.png) 27 | 28 | ## Installation for Development 29 | ``` 30 | cd /path/to/jupyter-shape-commentator 31 | jupyter nbextension install ../jupyter-shape-commentator --user 32 | ``` -------------------------------------------------------------------------------- /jupyter-shape-commentator.js: -------------------------------------------------------------------------------- 1 | define([ 2 | 'base/js/namespace', 3 | 'base/js/events', 4 | ], 5 | function (Jupyter,events) { 6 | "use strict"; 7 | function rewrite_with_cellmagic(cell, cellmagic){ 8 | var callback_result = cell.get_callbacks(); 9 | callback_result.iopub.output = function() { 10 | var that = cell; 11 | // console.log(arguments); 12 | var data = arguments[0].content.data; 13 | // If it is NOT shape commentator result (e.g. stdio output), skip. 14 | if (data===undefined){ 15 | that.events.trigger('set_dirty.Notebook', {value: true}); 16 | that.output_area.handle_output.apply(that.output_area, arguments); 17 | return; 18 | } 19 | data = data["text/plain"]; 20 | data = data.slice(1,-1); 21 | data = data.replace(/\\n/g,"\n"); 22 | cell.set_text(unescape(data)); 23 | } 24 | var tmp_get_callbacks = cell.get_callbacks; 25 | var tmp_get_text = cell.get_text; 26 | cell.get_text = function () { 27 | return "shape_commentator.jupyter_ext.ENV_GLOBALS = globals()"; 28 | }; 29 | cell.execute(); 30 | cell.get_callbacks = function(){ 31 | return callback_result; 32 | } 33 | cell.get_text = function () { 34 | return "%%"+cellmagic+"\n"+this.code_mirror.getValue(); 35 | }; 36 | cell.execute(); 37 | cell.get_text = tmp_get_text; 38 | cell.get_callbacks = tmp_get_callbacks; 39 | } 40 | 41 | function shape_comment(){ 42 | // console.log("Calling shape_comment"); 43 | var cell = Jupyter.notebook.get_selected_cell(); 44 | rewrite_with_cellmagic(cell, "shape_comment"); 45 | } 46 | 47 | function shape_erase(){ 48 | // console.log("Calling shape_erase"); 49 | var cell = Jupyter.notebook.get_selected_cell(); 50 | rewrite_with_cellmagic(cell, "shape_erase"); 51 | } 52 | 53 | function load_ipython_extension() { 54 | // console.log("Calling load_ipython_extension"); 55 | 56 | if (document.getElementById('shape_commentator_button')==null) { 57 | Jupyter.toolbar.add_buttons_group([{ 58 | 'label': 'Shape', 59 | 'icon': 'fa-comment', 60 | 'callback': shape_comment, 61 | 'id': 'shape_commentator_button' 62 | }]); 63 | } 64 | 65 | if (document.getElementById('shape_commentator_erase_button')==null) { 66 | Jupyter.toolbar.add_buttons_group([{ 67 | 'label': 'Shape', 68 | 'icon': 'fa-eraser', 69 | 'callback': shape_erase, 70 | 'id': 'shape_commentator_erase_button' 71 | }]); 72 | } 73 | 74 | function import_shape_commentator(){ 75 | var options = { 76 | silent: false, 77 | store_history : false, 78 | stop_on_error: false 79 | }; 80 | console.log("Calling import_shape_commentator"); 81 | var cell = Jupyter.notebook.get_selected_cell(); 82 | var tmp_get_text = cell.get_text; 83 | cell.get_text = function () { 84 | return "import shape_commentator.jupyter_ext"; 85 | }; 86 | cell.execute(); 87 | cell.get_text = tmp_get_text; 88 | } 89 | 90 | events.on("kernel_ready.Kernel", function () { 91 | if (Jupyter.notebook !== undefined && Jupyter.notebook._fully_loaded) { 92 | import_shape_commentator(); 93 | } else { 94 | events.on("notebook_loaded.Notebook", function () { 95 | import_shape_commentator(); 96 | }) 97 | } 98 | }); 99 | } 100 | 101 | return { 102 | load_ipython_extension: load_ipython_extension 103 | }; 104 | } 105 | ); 106 | 107 | console.log("Loading Jupyter Shape Commentator"); --------------------------------------------------------------------------------