Sophie

Sophie

distrib > Mandriva > 2010.1 > x86_64 > media > contrib-backports > by-pkgid > 3ba3bd1608c672ba2129b098a48e9e4d > files > 637

python3-docs-3.2.2-3mdv2010.2.noarch.rpm



<!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>30.11. compileall — Byte-compile Python libraries &mdash; Python v3.2.2 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:     '3.2.2',
        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>
    <script type="text/javascript" src="../_static/sidebar.js"></script>
    <link rel="search" type="application/opensearchdescription+xml"
          title="Search within Python v3.2.2 documentation"
          href="../_static/opensearch.xml"/>
    <link rel="author" title="About these documents" href="../about.html" />
    <link rel="copyright" title="Copyright" href="../copyright.html" />
    <link rel="top" title="Python v3.2.2 documentation" href="../index.html" />
    <link rel="up" title="30. Python Language Services" href="language.html" />
    <link rel="next" title="30.12. dis — Disassembler for Python bytecode" href="dis.html" />
    <link rel="prev" title="30.10. py_compile — Compile Python source files" href="py_compile.html" />
    <link rel="shortcut icon" type="image/png" href="../_static/py.png" />
 

  </head>
  <body>
    <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="dis.html" title="30.12. dis — Disassembler for Python bytecode"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="py_compile.html" title="30.10. py_compile — Compile Python source files"
             accesskey="P">previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v3.2.2 documentation</a> &raquo;</li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="language.html" accesskey="U">30. Python Language Services</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="module-compileall">
<span id="compileall-byte-compile-python-libraries"></span><h1>30.11. <a class="reference internal" href="#module-compileall" title="compileall: Tools for byte-compiling all Python source files in a directory tree."><tt class="xref py py-mod docutils literal"><span class="pre">compileall</span></tt></a> &#8212; Byte-compile Python libraries<a class="headerlink" href="#module-compileall" title="Permalink to this headline">¶</a></h1>
<p>This module provides some utility functions to support installing Python
libraries.  These functions compile Python source files in a directory tree.
This module can be used to create the cached byte-code files at library
installation time, which makes them available for use even by users who don&#8217;t
have write permission to the library directories.</p>
<div class="section" id="command-line-use">
<h2>30.11.1. Command-line use<a class="headerlink" href="#command-line-use" title="Permalink to this headline">¶</a></h2>
<p>This module can work as a script (using <strong class="program">python -m compileall</strong>) to
compile Python sources.</p>
<dl class="cmdoption">
<dt>
<tt class="descname">[directory|file]...</tt></dt>
<dd><p>Positional arguments are files to compile or directories that contain
source files, traversed recursively.  If no argument is given, behave as if
the command line was <tt class="docutils literal"><span class="pre">-l</span> <span class="pre">&lt;directories</span> <span class="pre">from</span> <span class="pre">sys.path&gt;</span></tt>.</p>
</dd></dl>

<dl class="cmdoption">
<dt id="cmdoption-compileall-l">
<tt class="descname">-l</tt><tt class="descclassname"></tt><a class="headerlink" href="#cmdoption-compileall-l" title="Permalink to this definition">¶</a></dt>
<dd><p>Do not recurse into subdirectories, only compile source code files directly
contained in the named or implied directories.</p>
</dd></dl>

<dl class="cmdoption">
<dt id="cmdoption-compileall-f">
<tt class="descname">-f</tt><tt class="descclassname"></tt><a class="headerlink" href="#cmdoption-compileall-f" title="Permalink to this definition">¶</a></dt>
<dd><p>Force rebuild even if timestamps are up-to-date.</p>
</dd></dl>

<dl class="cmdoption">
<dt id="cmdoption-compileall-q">
<tt class="descname">-q</tt><tt class="descclassname"></tt><a class="headerlink" href="#cmdoption-compileall-q" title="Permalink to this definition">¶</a></dt>
<dd><p>Do not print the list of files compiled, print only error messages.</p>
</dd></dl>

<dl class="cmdoption">
<dt id="cmdoption-compileall-d">
<tt class="descname">-d</tt><tt class="descclassname"> destdir</tt><a class="headerlink" href="#cmdoption-compileall-d" title="Permalink to this definition">¶</a></dt>
<dd><p>Directory prepended to the path to each file being compiled.  This will
appear in compilation time tracebacks, and is also compiled in to the
byte-code file, where it will be used in tracebacks and other messages in
cases where the source file does not exist at the time the byte-code file is
executed.</p>
</dd></dl>

<dl class="cmdoption">
<dt id="cmdoption-compileall-x">
<tt class="descname">-x</tt><tt class="descclassname"> regex</tt><a class="headerlink" href="#cmdoption-compileall-x" title="Permalink to this definition">¶</a></dt>
<dd><p>regex is used to search the full path to each file considered for
compilation, and if the regex produces a match, the file is skipped.</p>
</dd></dl>

<dl class="cmdoption">
<dt id="cmdoption-compileall-i">
<tt class="descname">-i</tt><tt class="descclassname"> list</tt><a class="headerlink" href="#cmdoption-compileall-i" title="Permalink to this definition">¶</a></dt>
<dd><p>Read the file <tt class="docutils literal"><span class="pre">list</span></tt> and add each line that it contains to the list of
files and directories to compile.  If <tt class="docutils literal"><span class="pre">list</span></tt> is <tt class="docutils literal"><span class="pre">-</span></tt>, read lines from
<tt class="docutils literal"><span class="pre">stdin</span></tt>.</p>
</dd></dl>

<dl class="cmdoption">
<dt id="cmdoption-compileall-b">
<tt class="descname">-b</tt><tt class="descclassname"></tt><a class="headerlink" href="#cmdoption-compileall-b" title="Permalink to this definition">¶</a></dt>
<dd><p>Write the byte-code files to their legacy locations and names, which may
overwrite byte-code files created by another version of Python.  The default
is to write files to their <span class="target" id="index-0"></span><a class="pep reference external" href="http://www.python.org/dev/peps/pep-3147"><strong>PEP 3147</strong></a> locations and names, which allows
byte-code files from multiple versions of Python to coexist.</p>
</dd></dl>

<p class="versionchanged">
<span class="versionmodified">Changed in version 3.2: </span>Added the <tt class="docutils literal"><span class="pre">-i</span></tt>, <tt class="docutils literal"><span class="pre">-b</span></tt> and <tt class="docutils literal"><span class="pre">-h</span></tt> options.</p>
<p>There is no command-line option to control the optimization level used by the
<a class="reference internal" href="functions.html#compile" title="compile"><tt class="xref py py-func docutils literal"><span class="pre">compile()</span></tt></a> function, because the Python interpreter itself already
provides the option: <strong class="program">python -O -m compileall</strong>.</p>
</div>
<div class="section" id="public-functions">
<h2>30.11.2. Public functions<a class="headerlink" href="#public-functions" title="Permalink to this headline">¶</a></h2>
<dl class="function">
<dt id="compileall.compile_dir">
<tt class="descclassname">compileall.</tt><tt class="descname">compile_dir</tt><big>(</big><em>dir</em>, <em>maxlevels=10</em>, <em>ddir=None</em>, <em>force=False</em>, <em>rx=None</em>, <em>quiet=False</em>, <em>legacy=False</em>, <em>optimize=-1</em><big>)</big><a class="headerlink" href="#compileall.compile_dir" title="Permalink to this definition">¶</a></dt>
<dd><p>Recursively descend the directory tree named by <em>dir</em>, compiling all <tt class="file docutils literal"><span class="pre">.py</span></tt>
files along the way.</p>
<p>The <em>maxlevels</em> parameter is used to limit the depth of the recursion; it
defaults to <tt class="docutils literal"><span class="pre">10</span></tt>.</p>
<p>If <em>ddir</em> is given, it is prepended to the path to each file being compiled
for use in compilation time tracebacks, and is also compiled in to the
byte-code file, where it will be used in tracebacks and other messages in
cases where the source file does not exist at the time the byte-code file is
executed.</p>
<p>If <em>force</em> is true, modules are re-compiled even if the timestamps are up to
date.</p>
<p>If <em>rx</em> is given, its search method is called on the complete path to each
file considered for compilation, and if it returns a true value, the file
is skipped.</p>
<p>If <em>quiet</em> is true, nothing is printed to the standard output unless errors
occur.</p>
<p>If <em>legacy</em> is true, byte-code files are written to their legacy locations
and names, which may overwrite byte-code files created by another version of
Python.  The default is to write files to their <span class="target" id="index-1"></span><a class="pep reference external" href="http://www.python.org/dev/peps/pep-3147"><strong>PEP 3147</strong></a> locations and
names, which allows byte-code files from multiple versions of Python to
coexist.</p>
<p><em>optimize</em> specifies the optimization level for the compiler.  It is passed to
the built-in <a class="reference internal" href="functions.html#compile" title="compile"><tt class="xref py py-func docutils literal"><span class="pre">compile()</span></tt></a> function.</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 3.2: </span>Added the <em>legacy</em> and <em>optimize</em> parameter.</p>
</dd></dl>

<dl class="function">
<dt id="compileall.compile_file">
<tt class="descclassname">compileall.</tt><tt class="descname">compile_file</tt><big>(</big><em>fullname</em>, <em>ddir=None</em>, <em>force=False</em>, <em>rx=None</em>, <em>quiet=False</em>, <em>legacy=False</em>, <em>optimize=-1</em><big>)</big><a class="headerlink" href="#compileall.compile_file" title="Permalink to this definition">¶</a></dt>
<dd><p>Compile the file with path <em>fullname</em>.</p>
<p>If <em>ddir</em> is given, it is prepended to the path to the file being compiled
for use in compilation time tracebacks, and is also compiled in to the
byte-code file, where it will be used in tracebacks and other messages in
cases where the source file does not exist at the time the byte-code file is
executed.</p>
<p>If <em>rx</em> is given, its search method is passed the full path name to the
file being compiled, and if it returns a true value, the file is not
compiled and <tt class="xref docutils literal"><span class="pre">True</span></tt> is returned.</p>
<p>If <em>quiet</em> is true, nothing is printed to the standard output unless errors
occur.</p>
<p>If <em>legacy</em> is true, byte-code files are written to their legacy locations
and names, which may overwrite byte-code files created by another version of
Python.  The default is to write files to their <span class="target" id="index-2"></span><a class="pep reference external" href="http://www.python.org/dev/peps/pep-3147"><strong>PEP 3147</strong></a> locations and
names, which allows byte-code files from multiple versions of Python to
coexist.</p>
<p><em>optimize</em> specifies the optimization level for the compiler.  It is passed to
the built-in <a class="reference internal" href="functions.html#compile" title="compile"><tt class="xref py py-func docutils literal"><span class="pre">compile()</span></tt></a> function.</p>
<p class="versionadded">
<span class="versionmodified">New in version 3.2.</span></p>
</dd></dl>

<dl class="function">
<dt id="compileall.compile_path">
<tt class="descclassname">compileall.</tt><tt class="descname">compile_path</tt><big>(</big><em>skip_curdir=True</em>, <em>maxlevels=0</em>, <em>force=False</em>, <em>legacy=False</em>, <em>optimize=-1</em><big>)</big><a class="headerlink" href="#compileall.compile_path" title="Permalink to this definition">¶</a></dt>
<dd><p>Byte-compile all the <tt class="file docutils literal"><span class="pre">.py</span></tt> files found along <tt class="docutils literal"><span class="pre">sys.path</span></tt>. If
<em>skip_curdir</em> is true (the default), the current directory is not included
in the search.  All other parameters are passed to the <a class="reference internal" href="#compileall.compile_dir" title="compileall.compile_dir"><tt class="xref py py-func docutils literal"><span class="pre">compile_dir()</span></tt></a>
function.  Note that unlike the other compile functions, <tt class="docutils literal"><span class="pre">maxlevels</span></tt>
defaults to <tt class="docutils literal"><span class="pre">0</span></tt>.</p>
<p class="versionchanged">
<span class="versionmodified">Changed in version 3.2: </span>Added the <em>legacy</em> and <em>optimize</em> parameter.</p>
</dd></dl>

<p>To force a recompile of all the <tt class="file docutils literal"><span class="pre">.py</span></tt> files in the <tt class="file docutils literal"><span class="pre">Lib/</span></tt>
subdirectory and all its subdirectories:</p>
<div class="highlight-python3"><div class="highlight"><pre><span class="kn">import</span> <span class="nn">compileall</span>

<span class="n">compileall</span><span class="o">.</span><span class="n">compile_dir</span><span class="p">(</span><span class="s">&#39;Lib/&#39;</span><span class="p">,</span> <span class="n">force</span><span class="o">=</span><span class="k">True</span><span class="p">)</span>

<span class="c"># Perform same compilation, excluding files in .svn directories.</span>
<span class="kn">import</span> <span class="nn">re</span>
<span class="n">compileall</span><span class="o">.</span><span class="n">compile_dir</span><span class="p">(</span><span class="s">&#39;Lib/&#39;</span><span class="p">,</span> <span class="n">rx</span><span class="o">=</span><span class="n">re</span><span class="o">.</span><span class="n">compile</span><span class="p">(</span><span class="s">&#39;/[.]svn&#39;</span><span class="p">),</span> <span class="n">force</span><span class="o">=</span><span class="k">True</span><span class="p">)</span>
</pre></div>
</div>
<div class="admonition-see-also admonition seealso">
<p class="first admonition-title">See also</p>
<dl class="last docutils">
<dt>Module <a class="reference internal" href="py_compile.html#module-py_compile" title="py_compile: Generate byte-code files from Python source files."><tt class="xref py py-mod docutils literal"><span class="pre">py_compile</span></tt></a></dt>
<dd>Byte-compile a single source file.</dd>
</dl>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">30.11. <tt class="docutils literal"><span class="pre">compileall</span></tt> &#8212; Byte-compile Python libraries</a><ul>
<li><a class="reference internal" href="#command-line-use">30.11.1. Command-line use</a></li>
<li><a class="reference internal" href="#public-functions">30.11.2. Public functions</a></li>
</ul>
</li>
</ul>

  <h4>Previous topic</h4>
  <p class="topless"><a href="py_compile.html"
                        title="previous chapter">30.10. <tt class="docutils literal"><span class="pre">py_compile</span></tt> &#8212; Compile Python source files</a></p>
  <h4>Next topic</h4>
  <p class="topless"><a href="dis.html"
                        title="next chapter">30.12. <tt class="docutils literal"><span class="pre">dis</span></tt> &#8212; Disassembler for Python bytecode</a></p>
<h3>This Page</h3>
<ul class="this-page-menu">
  <li><a href="../bugs.html">Report a Bug</a></li>
  <li><a href="../_sources/library/compileall.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" size="18" />
      <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="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="dis.html" title="30.12. dis — Disassembler for Python bytecode"
             >next</a> |</li>
        <li class="right" >
          <a href="py_compile.html" title="30.10. py_compile — Compile Python source files"
             >previous</a> |</li>
        <li><img src="../_static/py.png" alt=""
                 style="vertical-align: middle; margin-top: -1px"/></li>
        <li><a href="../index.html">Python v3.2.2 documentation</a> &raquo;</li>

          <li><a href="index.html" >The Python Standard Library</a> &raquo;</li>
          <li><a href="language.html" >30. Python Language Services</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
    &copy; <a href="../copyright.html">Copyright</a> 1990-2011, Python Software Foundation.
    <br />
    The Python Software Foundation is a non-profit corporation.  
    <a href="http://www.python.org/psf/donations/">Please donate.</a>
    <br />
    Last updated on Sep 04, 2011.
    <a href="../bugs.html">Found a bug</a>?
    <br />
    Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 1.0.7.
    </div>

  </body>
</html>