Skip to content

Commit

Permalink
Merge pull request #1016 from jfbercher/master
Browse files Browse the repository at this point in the history
[varInspector] Fix #1014 and #1015 - reload on  %reset magic and fix print on python2
  • Loading branch information
jfbercher authored Jul 14, 2017
2 parents 0a24d76 + 7ea5229 commit d7f4b63
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,12 @@ The initial configuration can be given using the IPython-contrib nbextensions fa

## Notes
- The displayed size of variables use the `getsizeof()` python method. This method doesn't work for all types, so the reported size is to be considered with some caution. The extension includes some code to correctly return the size of numpy arrays, pandas Series and DataFrame but the size for some other types may be incorrect.
- The extension builds on some
[example code](https://github.com/jupyter-widgets/ipywidgets/blob/ffa094e061c899292036049b00ff93e46e8b4691/docs/source/examples/Variable%20Inspector.ipynb)
provided by the ipywidgets package (essentially the `_fill` method).
- The extension builds on some code provided [here](https://github.com/ipython/ipywidgets/blob/master/docs/source/examples/Variable%20Inspector.ipynb) (essentially the `_fill` method)
- The extension uses Christian Bach's [table sorter jquery plugin](https://github.com/christianbach/tablesorter). License file is included.


## History

- @jfbercher march 22, 2017 -- initial release
- @jfbercher april 03, 2017 -- multiple kernel support. added support for R kernels.
- @jfbercher april 03, 2017 -- multiple kernel support. added support for R kernels.
- @jfbercher june 30, 2017 -- fixed #1014 (use of `%reset` with IPython kernel) and #1015 printing with python 2 kernel.
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,13 @@ function html_table(jsonVars) {

function code_exec_callback(msg) {
var jsonVars = msg.content['text'];
$('#varInspector').html(html_table(jsonVars))
var notWellDefined = false;
if (msg.content.evalue)
notWellDefined = msg.content.evalue == "name 'var_dic_list' is not defined" ||
msg.content.evalue.substr(0,28) == "Error in cat(var_dic_list())"
//means that var_dic_list was cleared ==> need to retart the extension
if (notWellDefined) varInspector_init()
else $('#varInspector').html(html_table(jsonVars))

require(['nbextensions/varInspector/jquery.tablesorter.min'],
function() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Description: The Variable Inspector extension collects all defined variables and
Link: README.md
Icon: icon.png
Main: main.js
Compatibility: 4.x
Compatibility: 4.x, 5.x
Parameters:
- name: varInspector.window_display
description: Display window at startup
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
from __future__ import print_function

import json
from sys import getsizeof

from IPython import get_ipython
from IPython.core.magics.namespace import NamespaceMagics

from IPython import get_ipython
import json
_nms = NamespaceMagics()
_Jupyter = get_ipython()
_nms.shell = _Jupyter.kernel.shell
Expand All @@ -24,9 +20,9 @@ def _getsizeof(x):

def var_dic_list():
types_to_exclude = ['module', 'function', 'builtin_function_or_method',
'instance', '_Feature']
'instance', '_Feature', 'type', 'ufunc']
values = _nms.who_ls()
vardic = [{'varName': v, 'varType': type(eval(v)).__name__, 'varSize': _getsizeof(eval(v)), 'varContent': str(eval(v))[:200]} # noqa
vardic = [{'varName': v, 'varType': type(eval(v)).__name__, 'varSize': str(_getsizeof(eval(v))), 'varContent': str(eval(v))[:200]} # noqa
for v in values if (v not in ['_html', '_nms', 'NamespaceMagics', '_Jupyter']) & (type(eval(v)).__name__ not in types_to_exclude)] # noqa
return json.dumps(vardic)

Expand Down

0 comments on commit d7f4b63

Please # to comment.