<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Module: lib.deepreload — IPython 2.3.0 documentation</title> <link rel="stylesheet" href="../../_static/default.css" type="text/css" /> <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> <script type="text/javascript"> var DOCUMENTATION_OPTIONS = { URL_ROOT: '../../', VERSION: '2.3.0', COLLAPSE_INDEX: false, FILE_SUFFIX: '.html', HAS_SOURCE: true }; </script> <script type="text/javascript" src="../../_static/jquery.js"></script> <script type="text/javascript" src="../../_static/underscore.js"></script> <script type="text/javascript" src="../../_static/doctools.js"></script> <link rel="top" title="IPython 2.3.0 documentation" href="../../index.html" /> <link rel="up" title="The IPython API" href="../index.html" /> <link rel="next" title="Module: lib.demo" href="IPython.lib.demo.html" /> <link rel="prev" title="Module: lib.clipboard" href="IPython.lib.clipboard.html" /> </head> <body> <div style="background-color: white; text-align: left; padding: 10px 10px 15px 15px"> <a href="http://ipython.org/"><img src="../../_static/logo.png" border="0" alt="IPython Documentation"/></a> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../../genindex.html" title="General Index" accesskey="I">index</a></li> <li class="right" > <a href="../../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="IPython.lib.demo.html" title="Module: lib.demo" accesskey="N">next</a> |</li> <li class="right" > <a href="IPython.lib.clipboard.html" title="Module: lib.clipboard" accesskey="P">previous</a> |</li> <li><a href="http://ipython.org">home</a>| </li> <li><a href="../../search.html">search</a>| </li> <li><a href="../../index.html">documentation </a> »</li> <li><a href="../index.html" accesskey="U">The IPython API</a> »</li> </ul> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="../../index.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">Module: <tt class="docutils literal"><span class="pre">lib.deepreload</span></tt></a><ul> <li><a class="reference internal" href="#functions">9 Functions</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="IPython.lib.clipboard.html" title="previous chapter">Module: <tt class="docutils literal"><span class="pre">lib.clipboard</span></tt></a></p> <h4>Next topic</h4> <p class="topless"><a href="IPython.lib.demo.html" title="next chapter">Module: <tt class="docutils literal"><span class="pre">lib.demo</span></tt></a></p> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="../../_sources/api/generated/IPython.lib.deepreload.txt" rel="nofollow">Show Source</a></li> </ul> <div id="searchbox" style="display: none"> <h3>Quick search</h3> <form class="search" action="../../search.html" method="get"> <input type="text" name="q" /> <input type="submit" value="Go" /> <input type="hidden" name="check_keywords" value="yes" /> <input type="hidden" name="area" value="default" /> </form> <p class="searchtip" style="font-size: 90%"> Enter search terms or a module, class or function name. </p> </div> <script type="text/javascript">$('#searchbox').show(0);</script> </div> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="module-IPython.lib.deepreload"> <span id="module-lib-deepreload"></span><h1>Module: <tt class="xref py py-mod docutils literal"><span class="pre">lib.deepreload</span></tt><a class="headerlink" href="#module-IPython.lib.deepreload" title="Permalink to this headline">¶</a></h1> <p>Provides a reload() function that acts recursively.</p> <p>Python’s normal <a class="reference external" href="http://docs.python.org/2/library/functions.html#reload" title="(in Python v2.7)"><tt class="docutils literal"><span class="pre">reload()</span></tt></a> function only reloads the module that it’s passed. The <a class="reference internal" href="#IPython.lib.deepreload.reload" title="IPython.lib.deepreload.reload"><tt class="xref py py-func docutils literal"><span class="pre">reload()</span></tt></a> function in this module also reloads everything imported from that module, which is useful when you’re changing files deep inside a package.</p> <p>To use this as your default reload function, type this for Python 2:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">__builtin__</span> <span class="kn">from</span> <span class="nn">IPython.lib</span> <span class="kn">import</span> <span class="n">deepreload</span> <span class="n">__builtin__</span><span class="o">.</span><span class="n">reload</span> <span class="o">=</span> <span class="n">deepreload</span><span class="o">.</span><span class="n">reload</span> </pre></div> </div> <p>Or this for Python 3:</p> <div class="highlight-python"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">builtins</span> <span class="kn">from</span> <span class="nn">IPython.lib</span> <span class="kn">import</span> <span class="n">deepreload</span> <span class="n">builtins</span><span class="o">.</span><span class="n">reload</span> <span class="o">=</span> <span class="n">deepreload</span><span class="o">.</span><span class="n">reload</span> </pre></div> </div> <p>A reference to the original <a class="reference external" href="http://docs.python.org/2/library/functions.html#reload" title="(in Python v2.7)"><tt class="docutils literal"><span class="pre">reload()</span></tt></a> is stored in this module as <tt class="xref py py-data docutils literal"><span class="pre">original_reload</span></tt>, so you can restore it later.</p> <p>This code is almost entirely based on knee.py, which is a Python re-implementation of hierarchical module import.</p> <div class="section" id="functions"> <h2>9 Functions<a class="headerlink" href="#functions" title="Permalink to this headline">¶</a></h2> <dl class="function"> <dt id="IPython.lib.deepreload.replace_import_hook"> <tt class="descclassname">IPython.lib.deepreload.</tt><tt class="descname">replace_import_hook</tt><big>(</big><em>*args</em>, <em>**kwds</em><big>)</big><a class="headerlink" href="#IPython.lib.deepreload.replace_import_hook" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="function"> <dt id="IPython.lib.deepreload.get_parent"> <tt class="descclassname">IPython.lib.deepreload.</tt><tt class="descname">get_parent</tt><big>(</big><em>globals</em>, <em>level</em><big>)</big><a class="headerlink" href="#IPython.lib.deepreload.get_parent" title="Permalink to this definition">¶</a></dt> <dd><p>Return the package that an import is being performed in. If globals comes from the module foo.bar.bat (not itself a package), this returns the sys.modules entry for foo.bar. If globals is from a package’s __init__.py, the package’s entry in sys.modules is returned.</p> <p>If globals doesn’t come from a package or a module in a package, or a corresponding entry is not found in sys.modules, None is returned.</p> </dd></dl> <dl class="function"> <dt id="IPython.lib.deepreload.load_next"> <tt class="descclassname">IPython.lib.deepreload.</tt><tt class="descname">load_next</tt><big>(</big><em>mod</em>, <em>altmod</em>, <em>name</em>, <em>buf</em><big>)</big><a class="headerlink" href="#IPython.lib.deepreload.load_next" title="Permalink to this definition">¶</a></dt> <dd><p>altmod is either None or same as mod</p> </dd></dl> <dl class="function"> <dt id="IPython.lib.deepreload.import_submodule"> <tt class="descclassname">IPython.lib.deepreload.</tt><tt class="descname">import_submodule</tt><big>(</big><em>mod</em>, <em>subname</em>, <em>fullname</em><big>)</big><a class="headerlink" href="#IPython.lib.deepreload.import_submodule" title="Permalink to this definition">¶</a></dt> <dd></dd></dl> <dl class="function"> <dt id="IPython.lib.deepreload.add_submodule"> <tt class="descclassname">IPython.lib.deepreload.</tt><tt class="descname">add_submodule</tt><big>(</big><em>mod</em>, <em>submod</em>, <em>fullname</em>, <em>subname</em><big>)</big><a class="headerlink" href="#IPython.lib.deepreload.add_submodule" title="Permalink to this definition">¶</a></dt> <dd><p>mod.{subname} = submod</p> </dd></dl> <dl class="function"> <dt id="IPython.lib.deepreload.ensure_fromlist"> <tt class="descclassname">IPython.lib.deepreload.</tt><tt class="descname">ensure_fromlist</tt><big>(</big><em>mod</em>, <em>fromlist</em>, <em>buf</em>, <em>recursive</em><big>)</big><a class="headerlink" href="#IPython.lib.deepreload.ensure_fromlist" title="Permalink to this definition">¶</a></dt> <dd><p>Handle ‘from module import a, b, c’ imports.</p> </dd></dl> <dl class="function"> <dt id="IPython.lib.deepreload.deep_import_hook"> <tt class="descclassname">IPython.lib.deepreload.</tt><tt class="descname">deep_import_hook</tt><big>(</big><em>name</em>, <em>globals=None</em>, <em>locals=None</em>, <em>fromlist=None</em>, <em>level=-1</em><big>)</big><a class="headerlink" href="#IPython.lib.deepreload.deep_import_hook" title="Permalink to this definition">¶</a></dt> <dd><p>Replacement for __import__()</p> </dd></dl> <dl class="function"> <dt id="IPython.lib.deepreload.deep_reload_hook"> <tt class="descclassname">IPython.lib.deepreload.</tt><tt class="descname">deep_reload_hook</tt><big>(</big><em>m</em><big>)</big><a class="headerlink" href="#IPython.lib.deepreload.deep_reload_hook" title="Permalink to this definition">¶</a></dt> <dd><p>Replacement for reload().</p> </dd></dl> <dl class="function"> <dt id="IPython.lib.deepreload.reload"> <tt class="descclassname">IPython.lib.deepreload.</tt><tt class="descname">reload</tt><big>(</big><em>module, exclude=['sys', 'os.path', '__builtin__', '__main__']</em><big>)</big><a class="headerlink" href="#IPython.lib.deepreload.reload" title="Permalink to this definition">¶</a></dt> <dd><p>Recursively reload all modules used in the given module. Optionally takes a list of modules to exclude from reloading. The default exclude list contains sys, __main__, and __builtin__, to prevent, e.g., resetting display, exception, and io hooks.</p> </dd></dl> </div> </div> </div> </div> </div> <div class="clearer"></div> </div> <div class="related"> <h3>Navigation</h3> <ul> <li class="right" style="margin-right: 10px"> <a href="../../genindex.html" title="General Index" >index</a></li> <li class="right" > <a href="../../py-modindex.html" title="Python Module Index" >modules</a> |</li> <li class="right" > <a href="IPython.lib.demo.html" title="Module: lib.demo" >next</a> |</li> <li class="right" > <a href="IPython.lib.clipboard.html" title="Module: lib.clipboard" >previous</a> |</li> <li><a href="http://ipython.org">home</a>| </li> <li><a href="../../search.html">search</a>| </li> <li><a href="../../index.html">documentation </a> »</li> <li><a href="../index.html" >The IPython API</a> »</li> </ul> </div> <div class="footer"> © Copyright The IPython Development Team. Last updated on Jul 14, 2015. Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3. </div> </body> </html>