Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

sync

  • Loading branch information...
commit cb9cac32b8f89a22bada73a15eb746aece7330ce 1 parent 4963c51
Matthias Bussonnier authored August 03, 2012
31  IPython/core/docdecorators.py
... ...
@@ -0,0 +1,31 @@
  1
+from IPython.utils.text import dedent
  2
+
  3
+try:
  4
+    from docutils.core import publish_parts
  5
+except ImportError:
  6
+    publish_parts = None
  7
+
  8
+import numpydoc
  9
+#from IPython.utils.text import dedent
  10
+
  11
+
  12
+def numpy_to_rst(strn):
  13
+    return str(numpydoc.numpydoc.SphinxDocString(strn))
  14
+
  15
+def doc_to_html(doc, format='numpy'):
  16
+    if format == 'numpy' : 
  17
+        if not numpydoc:
  18
+            return None
  19
+        doc = numpy_to_rst(doc)
  20
+    if publish_parts:
  21
+        parts = publish_parts(doc, writer_name='html')
  22
+        fragments = '<div class="docstring">'+parts['fragment']+'</div>'
  23
+        return fragments
  24
+    return None
  25
+
  26
+def extract(obj, format='numpy'):
  27
+    return doc_to_html(obj.__doc__ , format=format)
  28
+
  29
+def doc_translate(obj):
  30
+    obj._doc_html_ = extract(obj, format='numpy')
  31
+
503  Untitled2.ipynb
@@ -11,28 +11,336 @@
11 11
      "cell_type": "code",
12 12
      "collapsed": false,
13 13
      "input": [
14  
-      "from IPython.display import *\n",
15 14
       "import numpy\n",
  15
+      "import docutils\n",
  16
+      "import numpydoc\n",
16 17
       "import IPython.core.oinspect as oi\n",
17 18
       "from docutils.core import publish_parts\n",
18  
-      "import docutils"
  19
+      "from IPython.display import *\n",
  20
+      "from IPython.utils.text import dedent\n",
  21
+      "#from IPython.core.docdecorators import *"
19 22
      ],
20 23
      "language": "python",
21 24
      "metadata": {},
22 25
      "outputs": [],
23  
-     "prompt_number": 4
  26
+     "prompt_number": 1
24 27
     },
25 28
     {
26 29
      "cell_type": "code",
27 30
      "collapsed": false,
28 31
      "input": [
29  
-      "import numpy\n",
30  
-      "numpy.histogram2d = oi.rst_docscting(numpy.histogram2d)"
  32
+      "doc_translate(numpy.histogram2d)"
  33
+     ],
  34
+     "language": "python",
  35
+     "metadata": {},
  36
+     "outputs": [
  37
+      {
  38
+       "ename": "KeyError",
  39
+       "evalue": "'sphinx'",
  40
+       "output_type": "pyerr",
  41
+       "traceback": [
  42
+        "\u001b[0;31m---------------------------------------------------------------------------\u001b[0m\n\u001b[0;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
  43
+        "\u001b[0;32m<ipython-input-2-23b36b749ffd>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m()\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mdoc_translate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mnumpy\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mhistogram2d\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
  44
+        "\u001b[0;32m/Users/matthiasbussonnier/ipython/IPython/core/docdecorators.pyc\u001b[0m in \u001b[0;36mdoc_translate\u001b[0;34m(obj)\u001b[0m\n\u001b[1;32m     28\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     29\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mdoc_translate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mobj\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 30\u001b[0;31m     \u001b[0mobj\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m_doc_html_\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mextract\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mobj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mformat\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'numpy'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     31\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
  45
+        "\u001b[0;32m/Users/matthiasbussonnier/ipython/IPython/core/docdecorators.pyc\u001b[0m in \u001b[0;36mextract\u001b[0;34m(obj, format)\u001b[0m\n\u001b[1;32m     25\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     26\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mextract\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mobj\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mformat\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'numpy'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 27\u001b[0;31m     \u001b[0;32mreturn\u001b[0m \u001b[0mdoc_to_html\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mobj\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0m__doc__\u001b[0m \u001b[0;34m,\u001b[0m \u001b[0mformat\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mformat\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     28\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     29\u001b[0m \u001b[0;32mdef\u001b[0m \u001b[0mdoc_translate\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mobj\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  46
+        "\u001b[0;32m/Users/matthiasbussonnier/ipython/IPython/core/docdecorators.pyc\u001b[0m in \u001b[0;36mdoc_to_html\u001b[0;34m(doc, format)\u001b[0m\n\u001b[1;32m     19\u001b[0m         \u001b[0mdoc\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mnumpy_to_rst\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdoc\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     20\u001b[0m     \u001b[0;32mif\u001b[0m \u001b[0mpublish_parts\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 21\u001b[0;31m         \u001b[0mparts\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpublish_parts\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdoc\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mwriter_name\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m'html'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     22\u001b[0m         \u001b[0mfragments\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'<div class=\"docstring\">'\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0mparts\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'fragment'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m+\u001b[0m\u001b[0;34m'</div>'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     23\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mfragments\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  47
+        "\u001b[0;32m/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/docutils-0.9-py2.7.egg/docutils/core.pyc\u001b[0m in \u001b[0;36mpublish_parts\u001b[0;34m(source, source_path, source_class, destination_path, reader, reader_name, parser, parser_name, writer, writer_name, settings, settings_spec, settings_overrides, config_section, enable_exit_status)\u001b[0m\n\u001b[1;32m    450\u001b[0m         \u001b[0msettings_overrides\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0msettings_overrides\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    451\u001b[0m         \u001b[0mconfig_section\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mconfig_section\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 452\u001b[0;31m         enable_exit_status=enable_exit_status)\n\u001b[0m\u001b[1;32m    453\u001b[0m     \u001b[0;32mreturn\u001b[0m \u001b[0mpub\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwriter\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mparts\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    454\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
  48
+        "\u001b[0;32m/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/docutils-0.9-py2.7.egg/docutils/core.pyc\u001b[0m in \u001b[0;36mpublish_programmatically\u001b[0;34m(source_class, source, source_path, destination_class, destination, destination_path, reader, reader_name, parser, parser_name, writer, writer_name, settings, settings_spec, settings_overrides, config_section, enable_exit_status)\u001b[0m\n\u001b[1;32m    664\u001b[0m     \u001b[0mpub\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mset_source\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0msource\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msource_path\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    665\u001b[0m     \u001b[0mpub\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mset_destination\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdestination\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdestination_path\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 666\u001b[0;31m     \u001b[0moutput\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mpub\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpublish\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0menable_exit_status\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0menable_exit_status\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    667\u001b[0m     \u001b[0;32mreturn\u001b[0m \u001b[0moutput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpub\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  49
+        "\u001b[0;32m/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/docutils-0.9-py2.7.egg/docutils/core.pyc\u001b[0m in \u001b[0;36mpublish\u001b[0;34m(self, argv, usage, description, settings_spec, settings_overrides, config_section, enable_exit_status)\u001b[0m\n\u001b[1;32m    219\u001b[0m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mset_io\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    220\u001b[0m             self.document = self.reader.read(self.source, self.parser,\n\u001b[0;32m--> 221\u001b[0;31m                                              self.settings)\n\u001b[0m\u001b[1;32m    222\u001b[0m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mapply_transforms\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    223\u001b[0m             \u001b[0moutput\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwriter\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mwrite\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdocument\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdestination\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  50
+        "\u001b[0;32m/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/docutils-0.9-py2.7.egg/docutils/readers/__init__.pyc\u001b[0m in \u001b[0;36mread\u001b[0;34m(self, source, parser, settings)\u001b[0m\n\u001b[1;32m     67\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msettings\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0msettings\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     68\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minput\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msource\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mread\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 69\u001b[0;31m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mparse\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     70\u001b[0m         \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdocument\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     71\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
  51
+        "\u001b[0;32m/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/docutils-0.9-py2.7.egg/docutils/readers/__init__.pyc\u001b[0m in \u001b[0;36mparse\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m     73\u001b[0m         \u001b[0;34m\"\"\"Parse `self.input` into a document tree.\"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     74\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdocument\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdocument\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnew_document\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m---> 75\u001b[0;31m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mparser\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mparse\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minput\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdocument\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m     76\u001b[0m         \u001b[0mdocument\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcurrent_source\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdocument\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcurrent_line\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mNone\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m     77\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
  52
+        "\u001b[0;32m/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/docutils-0.9-py2.7.egg/docutils/parsers/rst/__init__.pyc\u001b[0m in \u001b[0;36mparse\u001b[0;34m(self, inputstring, document)\u001b[0m\n\u001b[1;32m    160\u001b[0m               \u001b[0minputstring\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mtab_width\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mdocument\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msettings\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mtab_width\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    161\u001b[0m               convert_whitespace=True)\n\u001b[0;32m--> 162\u001b[0;31m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstatemachine\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0minputlines\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdocument\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0minliner\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0minliner\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    163\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfinish_parse\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    164\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
  53
+        "\u001b[0;32m/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/docutils-0.9-py2.7.egg/docutils/parsers/rst/states.pyc\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self, input_lines, document, input_offset, match_titles, inliner)\u001b[0m\n\u001b[1;32m    172\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnode\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdocument\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    173\u001b[0m         results = StateMachineWS.run(self, input_lines, input_offset,\n\u001b[0;32m--> 174\u001b[0;31m                                      input_source=document['source'])\n\u001b[0m\u001b[1;32m    175\u001b[0m         \u001b[0;32massert\u001b[0m \u001b[0mresults\u001b[0m \u001b[0;34m==\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m'RSTStateMachine.run() results should be empty!'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    176\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnode\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mmemo\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mNone\u001b[0m    \u001b[0;31m# remove unneeded references\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  54
+        "\u001b[0;32m/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/docutils-0.9-py2.7.egg/docutils/statemachine.pyc\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self, input_lines, input_offset, context, input_source, initial_state)\u001b[0m\n\u001b[1;32m    237\u001b[0m                                 % (source, offset, self.line))\n\u001b[1;32m    238\u001b[0m                         context, next_state, result = self.check_line(\n\u001b[0;32m--> 239\u001b[0;31m                             context, state, transitions)\n\u001b[0m\u001b[1;32m    240\u001b[0m                     \u001b[0;32mexcept\u001b[0m \u001b[0mEOFError\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    241\u001b[0m                         \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdebug\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  55
+        "\u001b[0;32m/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/docutils-0.9-py2.7.egg/docutils/statemachine.pyc\u001b[0m in \u001b[0;36mcheck_line\u001b[0;34m(self, context, state, transitions)\u001b[0m\n\u001b[1;32m    458\u001b[0m                           \u001b[0;34m'\"%s\" in state \"%s\".'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    459\u001b[0m                           % (name, state.__class__.__name__))\n\u001b[0;32m--> 460\u001b[0;31m                 \u001b[0;32mreturn\u001b[0m \u001b[0mmethod\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmatch\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcontext\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnext_state\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    461\u001b[0m         \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    462\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mdebug\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  56
+        "\u001b[0;32m/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/docutils-0.9-py2.7.egg/docutils/parsers/rst/states.pyc\u001b[0m in \u001b[0;36mexplicit_markup\u001b[0;34m(self, match, context, next_state)\u001b[0m\n\u001b[1;32m   2277\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mexplicit_markup\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmatch\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcontext\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mnext_state\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2278\u001b[0m         \u001b[0;34m\"\"\"Footnotes, hyperlink targets, directives, comments.\"\"\"\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2279\u001b[0;31m         \u001b[0mnodelist\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mblank_finish\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexplicit_construct\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmatch\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   2280\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mparent\u001b[0m \u001b[0;34m+=\u001b[0m \u001b[0mnodelist\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2281\u001b[0m         \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexplicit_list\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mblank_finish\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  57
+        "\u001b[0;32m/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/docutils-0.9-py2.7.egg/docutils/parsers/rst/states.pyc\u001b[0m in \u001b[0;36mexplicit_construct\u001b[0;34m(self, match)\u001b[0m\n\u001b[1;32m   2289\u001b[0m             \u001b[0;32mif\u001b[0m \u001b[0mexpmatch\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2290\u001b[0m                 \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2291\u001b[0;31m                     \u001b[0;32mreturn\u001b[0m \u001b[0mmethod\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mexpmatch\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   2292\u001b[0m                 \u001b[0;32mexcept\u001b[0m \u001b[0mMarkupError\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2293\u001b[0m                     \u001b[0mlineno\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mstate_machine\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mabs_line_number\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  58
+        "\u001b[0;32m/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/docutils-0.9-py2.7.egg/docutils/parsers/rst/states.pyc\u001b[0m in \u001b[0;36mdirective\u001b[0;34m(self, match, **option_presets)\u001b[0m\n\u001b[1;32m   2032\u001b[0m         \u001b[0;32mif\u001b[0m \u001b[0mdirective_class\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2033\u001b[0m             return self.run_directive(\n\u001b[0;32m-> 2034\u001b[0;31m                 directive_class, match, type_name, option_presets)\n\u001b[0m\u001b[1;32m   2035\u001b[0m         \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2036\u001b[0m             \u001b[0;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0munknown_directive\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mtype_name\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
  59
+        "\u001b[0;32m/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/docutils-0.9-py2.7.egg/docutils/parsers/rst/states.pyc\u001b[0m in \u001b[0;36mrun_directive\u001b[0;34m(self, directive, match, type_name, option_presets)\u001b[0m\n\u001b[1;32m   2081\u001b[0m             content_offset, block_text, self, self.state_machine)\n\u001b[1;32m   2082\u001b[0m         \u001b[0;32mtry\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m-> 2083\u001b[0;31m             \u001b[0mresult\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mdirective_instance\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m   2084\u001b[0m         \u001b[0;32mexcept\u001b[0m \u001b[0mdocutils\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mparsers\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mrst\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mDirectiveError\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0merror\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m   2085\u001b[0m             msg_node = self.reporter.system_message(error.level, error.msg,\n",
  60
+        "\u001b[0;32m/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.3-py2.7.egg/sphinx/directives/other.pyc\u001b[0m in \u001b[0;36mrun\u001b[0;34m(self)\u001b[0m\n\u001b[1;32m    217\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0mrun\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mself\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    218\u001b[0m         ret = make_admonition(\n\u001b[0;32m--> 219\u001b[0;31m             \u001b[0maddnodes\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mseealso\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mname\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;34m[\u001b[0m\u001b[0m_\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'See also'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0moptions\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    220\u001b[0m             \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcontent\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mlineno\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mcontent_offset\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mself\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mblock_text\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    221\u001b[0m             self.state, self.state_machine)\n",
  61
+        "\u001b[0;32m/usr/local/Cellar/python/2.7.3/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/Sphinx-1.1.3-py2.7.egg/sphinx/locale/__init__.pyc\u001b[0m in \u001b[0;36m_\u001b[0;34m(message)\u001b[0m\n\u001b[1;32m    189\u001b[0m \u001b[0;32melse\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    190\u001b[0m     \u001b[0;32mdef\u001b[0m \u001b[0m_\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmessage\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m--> 191\u001b[0;31m         \u001b[0;32mreturn\u001b[0m \u001b[0mtranslators\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;34m'sphinx'\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mugettext\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmessage\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m    192\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m    193\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n",
  62
+        "\u001b[0;31mKeyError\u001b[0m: 'sphinx'"
  63
+       ]
  64
+      }
  65
+     ],
  66
+     "prompt_number": 2
  67
+    },
  68
+    {
  69
+     "cell_type": "code",
  70
+     "collapsed": false,
  71
+     "input": [
  72
+      "def numpy_to_rst(strn):\n",
  73
+      "    return str(numpydoc.numpydoc.SphinxDocString(strn))\n",
  74
+      "\n",
  75
+      "def doc_to_html(doc, format='numpy'):\n",
  76
+      "    if format == 'numpy' : \n",
  77
+      "        if not numpydoc:\n",
  78
+      "            return None\n",
  79
+      "        doc = numpy_to_rst(doc)\n",
  80
+      "    if publish_parts:\n",
  81
+      "        parts = publish_parts(doc, writer_name='html')\n",
  82
+      "        fragments = '<div class=\"docstring\">'+parts['fragment']+'</div>'\n",
  83
+      "        return fragments\n",
  84
+      "    return None\n",
  85
+      "\n",
  86
+      "def extract(obj, format='numpy'):\n",
  87
+      "    return doc_to_html(obj.__doc__ , format=format)\n",
  88
+      "\n",
  89
+      "def doc_translate(obj):\n",
  90
+      "    obj._doc_html_ = extract(obj, format='numpy')\n",
  91
+      "\n",
  92
+      "display(HTML(extract(numpy,format='rst')))\n",
  93
+      "#display(HTML(extract(rst_docstring)))\n"
  94
+     ],
  95
+     "language": "python",
  96
+     "metadata": {},
  97
+     "outputs": [
  98
+      {
  99
+       "html": [
  100
+        "<div class=\"docstring\"><dl class=\"docutils\">\n",
  101
+        "<dt>Provides</dt>\n",
  102
+        "<dd><ol class=\"first last arabic simple\">\n",
  103
+        "<li>An array object of arbitrary homogeneous items</li>\n",
  104
+        "<li>Fast mathematical operations over arrays</li>\n",
  105
+        "<li>Linear Algebra, Fourier Transforms, Random Number Generation</li>\n",
  106
+        "</ol>\n",
  107
+        "</dd>\n",
  108
+        "</dl>\n",
  109
+        "<div class=\"section\" id=\"how-to-use-the-documentation\">\n",
  110
+        "<h1>How to use the documentation</h1>\n",
  111
+        "<p>Documentation is available in two forms: docstrings provided\n",
  112
+        "with the code, and a loose standing reference guide, available from\n",
  113
+        "<a class=\"reference external\" href=\"http://www.scipy.org\">the NumPy homepage</a>.</p>\n",
  114
+        "<p>We recommend exploring the docstrings using\n",
  115
+        "<a class=\"reference external\" href=\"http://ipython.scipy.org\">IPython</a>, an advanced Python shell with\n",
  116
+        "TAB-completion and introspection capabilities.  See below for further\n",
  117
+        "instructions.</p>\n",
  118
+        "<p>The docstring examples assume that <cite>numpy</cite> has been imported as <cite>np</cite>:</p>\n",
  119
+        "<pre class=\"literal-block\">\n",
  120
+        "&gt;&gt;&gt; import numpy as np\n",
  121
+        "</pre>\n",
  122
+        "<p>Code snippets are indicated by three greater-than signs:</p>\n",
  123
+        "<pre class=\"literal-block\">\n",
  124
+        "&gt;&gt;&gt; x = 42\n",
  125
+        "&gt;&gt;&gt; x = x + 1\n",
  126
+        "</pre>\n",
  127
+        "<p>Use the built-in <tt class=\"docutils literal\">help</tt> function to view a function's docstring:</p>\n",
  128
+        "<pre class=\"literal-block\">\n",
  129
+        "&gt;&gt;&gt; help(np.sort)\n",
  130
+        "... # doctest: +SKIP\n",
  131
+        "</pre>\n",
  132
+        "<p>For some objects, <tt class=\"docutils literal\">np.info(obj)</tt> may provide additional help.  This is\n",
  133
+        "particularly true if you see the line &quot;Help on ufunc object:&quot; at the top\n",
  134
+        "of the help() page.  Ufuncs are implemented in C, not Python, for speed.\n",
  135
+        "The native Python help() does not know how to view their help, but our\n",
  136
+        "np.info() function does.</p>\n",
  137
+        "<p>To search for documents containing a keyword, do:</p>\n",
  138
+        "<pre class=\"literal-block\">\n",
  139
+        "&gt;&gt;&gt; np.lookfor('keyword')\n",
  140
+        "... # doctest: +SKIP\n",
  141
+        "</pre>\n",
  142
+        "<p>General-purpose documents like a glossary and help on the basic concepts\n",
  143
+        "of numpy are available under the <tt class=\"docutils literal\">doc</tt> sub-module:</p>\n",
  144
+        "<pre class=\"literal-block\">\n",
  145
+        "&gt;&gt;&gt; from numpy import doc\n",
  146
+        "&gt;&gt;&gt; help(doc)\n",
  147
+        "... # doctest: +SKIP\n",
  148
+        "</pre>\n",
  149
+        "</div>\n",
  150
+        "<div class=\"section\" id=\"available-subpackages\">\n",
  151
+        "<h1>Available subpackages</h1>\n",
  152
+        "<dl class=\"docutils\">\n",
  153
+        "<dt>doc</dt>\n",
  154
+        "<dd>Topical documentation on broadcasting, indexing, etc.</dd>\n",
  155
+        "<dt>lib</dt>\n",
  156
+        "<dd>Basic functions used by several sub-packages.</dd>\n",
  157
+        "<dt>random</dt>\n",
  158
+        "<dd>Core Random Tools</dd>\n",
  159
+        "<dt>linalg</dt>\n",
  160
+        "<dd>Core Linear Algebra Tools</dd>\n",
  161
+        "<dt>fft</dt>\n",
  162
+        "<dd>Core FFT routines</dd>\n",
  163
+        "<dt>polynomial</dt>\n",
  164
+        "<dd>Polynomial tools</dd>\n",
  165
+        "<dt>testing</dt>\n",
  166
+        "<dd>Numpy testing tools</dd>\n",
  167
+        "<dt>f2py</dt>\n",
  168
+        "<dd>Fortran to Python Interface Generator.</dd>\n",
  169
+        "<dt>distutils</dt>\n",
  170
+        "<dd>Enhancements to distutils with support for\n",
  171
+        "Fortran compilers support and more.</dd>\n",
  172
+        "</dl>\n",
  173
+        "</div>\n",
  174
+        "<div class=\"section\" id=\"utilities\">\n",
  175
+        "<h1>Utilities</h1>\n",
  176
+        "<dl class=\"docutils\">\n",
  177
+        "<dt>test</dt>\n",
  178
+        "<dd>Run numpy unittests</dd>\n",
  179
+        "<dt>show_config</dt>\n",
  180
+        "<dd>Show numpy build configuration</dd>\n",
  181
+        "<dt>dual</dt>\n",
  182
+        "<dd>Overwrite certain functions with high-performance Scipy tools</dd>\n",
  183
+        "<dt>matlib</dt>\n",
  184
+        "<dd>Make everything matrices.</dd>\n",
  185
+        "<dt>__version__</dt>\n",
  186
+        "<dd>Numpy version string</dd>\n",
  187
+        "</dl>\n",
  188
+        "</div>\n",
  189
+        "<div class=\"section\" id=\"viewing-documentation-using-ipython\">\n",
  190
+        "<h1>Viewing documentation using IPython</h1>\n",
  191
+        "<p>Start IPython with the NumPy profile (<tt class=\"docutils literal\">ipython <span class=\"pre\">-p</span> numpy</tt>), which will\n",
  192
+        "import <cite>numpy</cite> under the alias <cite>np</cite>.  Then, use the <tt class=\"docutils literal\">cpaste</tt> command to\n",
  193
+        "paste examples into the shell.  To see which functions are available in\n",
  194
+        "<cite>numpy</cite>, type <tt class=\"docutils literal\"><span class=\"pre\">np.&lt;TAB&gt;</span></tt> (where <tt class=\"docutils literal\">&lt;TAB&gt;</tt> refers to the TAB key), or use\n",
  195
+        "<tt class=\"docutils literal\"><span class=\"pre\">np.*cos*?&lt;ENTER&gt;</span></tt> (where <tt class=\"docutils literal\">&lt;ENTER&gt;</tt> refers to the ENTER key) to narrow\n",
  196
+        "down the list.  To view the docstring for a function, use\n",
  197
+        "<tt class=\"docutils literal\"><span class=\"pre\">np.cos?&lt;ENTER&gt;</span></tt> (to view the docstring) and <tt class=\"docutils literal\"><span class=\"pre\">np.cos??&lt;ENTER&gt;</span></tt> (to view\n",
  198
+        "the source code).</p>\n",
  199
+        "</div>\n",
  200
+        "<div class=\"section\" id=\"copies-vs-in-place-operation\">\n",
  201
+        "<h1>Copies vs. in-place operation</h1>\n",
  202
+        "<p>Most of the functions in <cite>numpy</cite> return a copy of the array argument\n",
  203
+        "(e.g., <cite>np.sort</cite>).  In-place versions of these functions are often\n",
  204
+        "available as array methods, i.e. <tt class=\"docutils literal\">x = <span class=\"pre\">np.array([1,2,3]);</span> x.sort()</tt>.\n",
  205
+        "Exceptions to this rule are documented.</p>\n",
  206
+        "</div>\n",
  207
+        "</div>"
  208
+       ],
  209
+       "output_type": "display_data",
  210
+       "text": [
  211
+        "<IPython.core.display.HTML at 0x106b6af10>"
  212
+       ]
  213
+      }
  214
+     ],
  215
+     "prompt_number": 9
  216
+    },
  217
+    {
  218
+     "cell_type": "code",
  219
+     "collapsed": false,
  220
+     "input": [
  221
+      "print(matplotlib.__doc__)"
  222
+     ],
  223
+     "language": "python",
  224
+     "metadata": {},
  225
+     "outputs": [
  226
+      {
  227
+       "output_type": "stream",
  228
+       "stream": "stdout",
  229
+       "text": [
  230
+        "\n",
  231
+        "This is an object-orient plotting library.\n",
  232
+        "\n",
  233
+        "A procedural interface is provided by the companion pyplot module,\n",
  234
+        "which may be imported directly, e.g::\n",
  235
+        "\n",
  236
+        "    from matplotlib.pyplot import *\n",
  237
+        "\n",
  238
+        "To include numpy functions too, use::\n",
  239
+        "\n",
  240
+        "    from pylab import *\n",
  241
+        "\n",
  242
+        "or using ipython::\n",
  243
+        "\n",
  244
+        "    ipython -pylab\n",
  245
+        "\n",
  246
+        "For the most part, direct use of the object-oriented library is\n",
  247
+        "encouraged when programming; pyplot is primarily for working\n",
  248
+        "interactively.  The\n",
  249
+        "exceptions are the pyplot commands :func:`~matplotlib.pyplot.figure`,\n",
  250
+        ":func:`~matplotlib.pyplot.subplot`,\n",
  251
+        ":func:`~matplotlib.pyplot.subplots`,\n",
  252
+        ":func:`~matplotlib.backends.backend_qt4agg.show`, and\n",
  253
+        ":func:`~pyplot.savefig`, which can greatly simplify scripting.\n",
  254
+        "\n",
  255
+        "Modules include:\n",
  256
+        "\n",
  257
+        "    :mod:`matplotlib.axes`\n",
  258
+        "        defines the :class:`~matplotlib.axes.Axes` class.  Most pylab\n",
  259
+        "        commands are wrappers for :class:`~matplotlib.axes.Axes`\n",
  260
+        "        methods.  The axes module is the highest level of OO access to\n",
  261
+        "        the library.\n",
  262
+        "\n",
  263
+        "    :mod:`matplotlib.figure`\n",
  264
+        "        defines the :class:`~matplotlib.figure.Figure` class.\n",
  265
+        "\n",
  266
+        "    :mod:`matplotlib.artist`\n",
  267
+        "        defines the :class:`~matplotlib.artist.Artist` base class for\n",
  268
+        "        all classes that draw things.\n",
  269
+        "\n",
  270
+        "    :mod:`matplotlib.lines`\n",
  271
+        "        defines the :class:`~matplotlib.lines.Line2D` class for\n",
  272
+        "        drawing lines and markers\n",
  273
+        "\n",
  274
+        "    :mod:`matplotlib.patches`\n",
  275
+        "        defines classes for drawing polygons\n",
  276
+        "\n",
  277
+        "    :mod:`matplotlib.text`\n",
  278
+        "        defines the :class:`~matplotlib.text.Text`,\n",
  279
+        "        :class:`~matplotlib.text.TextWithDash`, and\n",
  280
+        "        :class:`~matplotlib.text.Annotate` classes\n",
  281
+        "\n",
  282
+        "    :mod:`matplotlib.image`\n",
  283
+        "        defines the :class:`~matplotlib.image.AxesImage` and\n",
  284
+        "        :class:`~matplotlib.image.FigureImage` classes\n",
  285
+        "\n",
  286
+        "    :mod:`matplotlib.collections`\n",
  287
+        "        classes for efficient drawing of groups of lines or polygons\n",
  288
+        "\n",
  289
+        "    :mod:`matplotlib.colors`\n",
  290
+        "        classes for interpreting color specifications and for making\n",
  291
+        "        colormaps\n",
  292
+        "\n",
  293
+        "    :mod:`matplotlib.cm`\n",
  294
+        "        colormaps and the :class:`~matplotlib.image.ScalarMappable`\n",
  295
+        "        mixin class for providing color mapping functionality to other\n",
  296
+        "        classes\n",
  297
+        "\n",
  298
+        "    :mod:`matplotlib.ticker`\n",
  299
+        "        classes for calculating tick mark locations and for formatting\n",
  300
+        "        tick labels\n",
  301
+        "\n",
  302
+        "    :mod:`matplotlib.backends`\n",
  303
+        "        a subpackage with modules for various gui libraries and output\n",
  304
+        "        formats\n",
  305
+        "\n",
  306
+        "The base matplotlib namespace includes:\n",
  307
+        "\n",
  308
+        "    :data:`~matplotlib.rcParams`\n",
  309
+        "        a global dictionary of default configuration settings.  It is\n",
  310
+        "        initialized by code which may be overridded by a matplotlibrc\n",
  311
+        "        file.\n",
  312
+        "\n",
  313
+        "    :func:`~matplotlib.rc`\n",
  314
+        "        a function for setting groups of rcParams values\n",
  315
+        "\n",
  316
+        "    :func:`~matplotlib.use`\n",
  317
+        "        a function for setting the matplotlib backend.  If used, this\n",
  318
+        "        function must be called immediately after importing matplotlib\n",
  319
+        "        for the first time.  In particular, it must be called\n",
  320
+        "        **before** importing pylab (if pylab is imported).\n",
  321
+        "\n",
  322
+        "matplotlib was initially written by John D. Hunter (jdh2358 at\n",
  323
+        "gmail.com) and is now developed and maintained by a host of others.\n",
  324
+        "\n",
  325
+        "Occasionally the internal documentation (python docstrings) will refer\n",
  326
+        "to MATLAB&reg;, a registered trademark of The MathWorks, Inc.\n",
  327
+        "\n",
  328
+        "\n"
  329
+       ]
  330
+      }
  331
+     ],
  332
+     "prompt_number": 20
  333
+    },
  334
+    {
  335
+     "cell_type": "code",
  336
+     "collapsed": false,
  337
+     "input": [
  338
+      "#HTML(numpy_to_html(dedent(h2d.__doc__)))"
31 339
      ],
32 340
      "language": "python",
33 341
      "metadata": {},
34 342
      "outputs": [],
35  
-     "prompt_number": 5
  343
+     "prompt_number": 27
36 344
     },
37 345
     {
38 346
      "cell_type": "code",
@@ -73,8 +381,10 @@
73 381
       "        background: #F7F7F7;\n",
74 382
       "        border-radius : 3px;\n",
75 383
       "        padding-bottom : 2px;\n",
  384
+      "        padding-left : 0.5em;\n",
  385
+      "        padding-right:0.5em;\n",
76 386
       "}\n",
77  
-      ".doctest-block{\n",
  387
+      ".doctest-block, .literal-block {\n",
78 388
       "        border: thin solid #DDD;\n",
79 389
       "        background: #F7F7F7;\n",
80 390
       "        border-radius : 3px;\n",
@@ -132,8 +442,10 @@
132 442
         "        background: #F7F7F7;\n",
133 443
         "        border-radius : 3px;\n",
134 444
         "        padding-bottom : 2px;\n",
  445
+        "        padding-left : 0.5em;\n",
  446
+        "        padding-right:0.5em;\n",
135 447
         "}\n",
136  
-        ".doctest-block{\n",
  448
+        ".doctest-block, .literal-block {\n",
137 449
         "        border: thin solid #DDD;\n",
138 450
         "        background: #F7F7F7;\n",
139 451
         "        border-radius : 3px;\n",
@@ -152,13 +464,13 @@
152 464
         "</style>\n"
153 465
        ],
154 466
        "output_type": "pyout",
155  
-       "prompt_number": 51,
  467
+       "prompt_number": 17,
156 468
        "text": [
157  
-        "<IPython.core.display.HTML at 0x10a83ef90>"
  469
+        "<IPython.core.display.HTML at 0x107baef90>"
158 470
        ]
159 471
       }
160 472
      ],
161  
-     "prompt_number": 51
  473
+     "prompt_number": 17
162 474
     },
163 475
     {
164 476
      "cell_type": "code",
@@ -188,101 +500,98 @@
188 500
      "cell_type": "code",
189 501
      "collapsed": false,
190 502
      "input": [
191  
-      "print(numpy.histogram2d.__doc__)"
  503
+      "#print(numpy.histogram2d.__doc__)"
  504
+     ],
  505
+     "language": "python",
  506
+     "metadata": {},
  507
+     "outputs": [],
  508
+     "prompt_number": 26
  509
+    },
  510
+    {
  511
+     "cell_type": "code",
  512
+     "collapsed": false,
  513
+     "input": [
  514
+      "from IPython.utils.text import dedent\n",
  515
+      "\n",
  516
+      "try:\n",
  517
+      "    from docutils.core import publish_parts\n",
  518
+      "except ImportError:\n",
  519
+      "    publish_parts = None\n",
  520
+      "\n",
  521
+      "import numpydoc\n",
  522
+      "#from IPython.utils.text import dedent\n",
  523
+      "\n",
  524
+      "\n",
  525
+      "def numpy_to_rst(strn):\n",
  526
+      "    return str(numpydoc.numpydoc.SphinxDocString(strn))\n",
  527
+      "\n",
  528
+      "def doc_to_html(doc, format='numpy'):\n",
  529
+      "    if format == 'numpy' : \n",
  530
+      "        if not numpydoc:\n",
  531
+      "            return None\n",
  532
+      "        doc = numpy_to_rst(doc)\n",
  533
+      "    if publish_parts:\n",
  534
+      "        parts = publish_parts(doc, writer_name='html')\n",
  535
+      "        fragments = '<div class=\"docstring\">'+parts['fragment']+'</div>'\n",
  536
+      "        return fragments\n",
  537
+      "    return None\n",
  538
+      "\n",
  539
+      "def extract(obj, format='numpy'):\n",
  540
+      "    return doc_to_html(obj.__doc__ , format=format)\n",
  541
+      "\n",
  542
+      "def doc_translate(obj):\n",
  543
+      "    obj._doc_html_ = extract(obj, format='numpy')\n"
  544
+     ],
  545
+     "language": "python",
  546
+     "metadata": {},
  547
+     "outputs": [],
  548
+     "prompt_number": 1
  549
+    },
  550
+    {
  551
+     "cell_type": "code",
  552
+     "collapsed": false,
  553
+     "input": [
  554
+      "\n",
  555
+      "dd = doc_to_html(dedent(numpy.__doc__))\n",
  556
+      "nd = numpy_to_rst(numpy.__doc__)\n",
  557
+      "pp = publish_parts(dedent(numpy.__doc__), writer_name='html')['fragment']\n",
  558
+      "\n",
  559
+      "nd"
192 560
      ],
193 561
      "language": "python",
194 562
      "metadata": {},
195 563
      "outputs": [
196 564
       {
197  
-       "output_type": "stream",
198  
-       "stream": "stdout",
  565
+       "output_type": "pyout",
  566
+       "prompt_number": 9,
199 567
        "text": [
200  
-        "\n",
201  
-        "    Compute the bi-dimensional histogram of two data samples.\n",
202  
-        "\n",
203  
-        "    Parameters\n",
204  
-        "    ----------\n",
205  
-        "    x : array_like, shape(N,)\n",
206  
-        "        A sequence of values to be histogrammed along the first dimension.\n",
207  
-        "    y : array_like, shape(M,)\n",
208  
-        "        A sequence of values to be histogrammed along the second dimension.\n",
209  
-        "    bins : int or [int, int] or array_like or [array, array], optional\n",
210  
-        "        The bin specification:\n",
211  
-        "\n",
212  
-        "          * If int, the number of bins for the two dimensions (nx=ny=bins).\n",
213  
-        "          * If [int, int], the number of bins in each dimension (nx, ny = bins).\n",
214  
-        "          * If array_like, the bin edges for the two dimensions (x_edges=y_edges=bins).\n",
215  
-        "          * If [array, array], the bin edges in each dimension (x_edges, y_edges = bins).\n",
216  
-        "\n",
217  
-        "    range : array_like, shape(2,2), optional\n",
218  
-        "        The leftmost and rightmost edges of the bins along each dimension\n",
219  
-        "        (if not specified explicitly in the `bins` parameters):\n",
220  
-        "        ``[[xmin, xmax], [ymin, ymax]]``. All values outside of this range\n",
221  
-        "        will be considered outliers and not tallied in the histogram.\n",
222  
-        "    normed : bool, optional\n",
223  
-        "        If False, returns the number of samples in each bin. If True, returns\n",
224  
-        "        the bin density, i.e. the bin count divided by the bin area.\n",
225  
-        "    weights : array_like, shape(N,), optional\n",
226  
-        "        An array of values ``w_i`` weighing each sample ``(x_i, y_i)``. Weights\n",
227  
-        "        are normalized to 1 if `normed` is True. If `normed` is False, the\n",
228  
-        "        values of the returned histogram are equal to the sum of the weights\n",
229  
-        "        belonging to the samples falling into each bin.\n",
230  
-        "\n",
231  
-        "    Returns\n",
232  
-        "    -------\n",
233  
-        "    H : ndarray, shape(nx, ny)\n",
234  
-        "        The bi-dimensional histogram of samples `x` and `y`. Values in `x`\n",
235  
-        "        are histogrammed along the first dimension and values in `y` are\n",
236  
-        "        histogrammed along the second dimension.\n",
237  
-        "    xedges : ndarray, shape(nx,)\n",
238  
-        "        The bin edges along the first dimension.\n",
239  
-        "    yedges : ndarray, shape(ny,)\n",
240  
-        "        The bin edges along the second dimension.\n",
241  
-        "\n",
242  
-        "    See Also\n",
243  
-        "    --------\n",
244  
-        "    histogram: 1D histogram\n",
245  
-        "    histogramdd: Multidimensional histogram\n",
246  
-        "\n",
247  
-        "    Notes\n",
248  
-        "    -----\n",
249  
-        "    When `normed` is True, then the returned histogram is the sample density,\n",
250  
-        "    defined such that:\n",
251  
-        "\n",
252  
-        "    .. math::\n",
253  
-        "      \\sum_{i=0}^{nx-1} \\sum_{j=0}^{ny-1} H_{i,j} \\Delta x_i \\Delta y_j = 1\n",
254  
-        "\n",
255  
-        "    where `H` is the histogram array and :math:`\\Delta x_i \\Delta y_i`\n",
256  
-        "    the area of bin `{i,j}`.\n",
257  
-        "\n",
258  
-        "    Please note that the histogram does not follow the Cartesian convention\n",
259  
-        "    where `x` values are on the abcissa and `y` values on the ordinate axis.\n",
260  
-        "    Rather, `x` is histogrammed along the first dimension of the array\n",
261  
-        "    (vertical), and `y` along the second dimension of the array (horizontal).\n",
262  
-        "    This ensures compatibility with `histogramdd`.\n",
263  
-        "\n",
264  
-        "    Examples\n",
265  
-        "    --------\n",
266  
-        "    >>> x, y = np.random.randn(2, 100)\n",
267  
-        "    >>> H, xedges, yedges = np.histogram2d(x, y, bins=(5, 8))\n",
268  
-        "    >>> H.shape, xedges.shape, yedges.shape\n",
269  
-        "    ((5, 8), (6,), (9,))\n",
270  
-        "\n",
271  
-        "    We can now use the Matplotlib to visualize this 2-dimensional histogram:\n",
272  
-        "\n",
273  
-        "    >>> extent = [yedges[0], yedges[-1], xedges[-1], xedges[0]]\n",
274  
-        "    >>> import matplotlib.pyplot as plt\n",
275  
-        "    >>> plt.imshow(H, extent=extent, interpolation='nearest')\n",
276  
-        "    <matplotlib.image.AxesImage object at ...>\n",
277  
-        "    >>> plt.colorbar()\n",
278  
-        "    <matplotlib.colorbar.Colorbar instance at ...>\n",
279  
-        "    >>> plt.show()\n",
280  
-        "\n",
281  
-        "    \n"
  568
+        "'\\n\\n\\n\\n'"
282 569
        ]
283 570
       }
284 571
      ],
285  
-     "prompt_number": 44
  572
+     "prompt_number": 9
  573
+    },
  574
+    {
  575
+     "cell_type": "code",
  576
+     "collapsed": false,
  577
+     "input": [
  578
+      "sds = numpydoc.numpydoc.SphinxDocString(numpy.__doc__)"
  579
+     ],
  580
+     "language": "python",
  581
+     "metadata": {},
  582
+     "outputs": [],
  583
+     "prompt_number": 13
  584
+    },
  585
+    {
  586
+     "cell_type": "code",
  587
+     "collapsed": false,
  588
+     "input": [
  589
+      "sds.__doc__"
  590
+     ],
  591
+     "language": "python",
  592
+     "metadata": {},
  593
+     "outputs": [],
  594
+     "prompt_number": 14
286 595
     },
287 596
     {
288 597
      "cell_type": "code",

0 notes on commit cb9cac3

Please sign in to comment.
Something went wrong with that request. Please try again.