<!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>pep8 API — pep8 1.5.7 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: '1.5.7', 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="pep8 1.5.7 documentation" href="index.html" /> <link rel="next" title="Developer’s notes" href="developer.html" /> <link rel="prev" title="Advanced usage" href="advanced.html" /> </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="developer.html" title="Developer’s notes" accesskey="N">next</a> |</li> <li class="right" > <a href="advanced.html" title="Advanced usage" accesskey="P">previous</a> |</li> <li><a href="index.html">pep8 1.5.7 documentation</a> »</li> </ul> </div> <div class="document"> <div class="documentwrapper"> <div class="bodywrapper"> <div class="body"> <div class="section" id="module-pep8"> <span id="pep8-api"></span><h1>pep8 API<a class="headerlink" href="#module-pep8" title="Permalink to this headline">¶</a></h1> <p>The library provides classes which are usable by third party tools.</p> <div class="contents local topic" id="contents"> <ul class="simple"> <li><a class="reference internal" href="#checker-classes" id="id2">Checker Classes</a></li> <li><a class="reference internal" href="#report-classes" id="id3">Report Classes</a></li> <li><a class="reference internal" href="#utilities" id="id4">Utilities</a></li> </ul> </div> <div class="section" id="checker-classes"> <span id="main-classes"></span><h2><a class="toc-backref" href="#id2">Checker Classes</a><a class="headerlink" href="#checker-classes" title="Permalink to this headline">¶</a></h2> <p>The <a class="reference internal" href="#pep8.StyleGuide" title="pep8.StyleGuide"><tt class="xref py py-class docutils literal"><span class="pre">StyleGuide</span></tt></a> class is used to configure a style guide checker instance to check multiple files.</p> <p>The <a class="reference internal" href="#pep8.Checker" title="pep8.Checker"><tt class="xref py py-class docutils literal"><span class="pre">Checker</span></tt></a> class can be used to check a single file.</p> <dl class="class"> <dt id="pep8.StyleGuide"> <em class="property">class </em><tt class="descclassname">pep8.</tt><tt class="descname">StyleGuide</tt><big>(</big><em>parse_argv=False</em>, <em>config_file=None</em>, <em>parser=None</em>, <em>paths=None</em>, <em>report=None</em>, <em>**kwargs</em><big>)</big><a class="reference internal" href="_modules/pep8.html#StyleGuide"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.StyleGuide" title="Permalink to this definition">¶</a></dt> <dd><p>Initialize a PEP-8 instance with few options.</p> <dl class="method"> <dt id="pep8.StyleGuide.init_report"> <tt class="descname">init_report</tt><big>(</big><em>reporter=None</em><big>)</big><a class="reference internal" href="_modules/pep8.html#StyleGuide.init_report"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.StyleGuide.init_report" title="Permalink to this definition">¶</a></dt> <dd><p>Initialize the report instance.</p> </dd></dl> <dl class="method"> <dt id="pep8.StyleGuide.check_files"> <tt class="descname">check_files</tt><big>(</big><em>paths=None</em><big>)</big><a class="reference internal" href="_modules/pep8.html#StyleGuide.check_files"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.StyleGuide.check_files" title="Permalink to this definition">¶</a></dt> <dd><p>Run all checks on the paths.</p> </dd></dl> <dl class="method"> <dt id="pep8.StyleGuide.input_file"> <tt class="descname">input_file</tt><big>(</big><em>filename</em>, <em>lines=None</em>, <em>expected=None</em>, <em>line_offset=0</em><big>)</big><a class="reference internal" href="_modules/pep8.html#StyleGuide.input_file"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.StyleGuide.input_file" title="Permalink to this definition">¶</a></dt> <dd><p>Run all checks on a Python source file.</p> </dd></dl> <dl class="method"> <dt id="pep8.StyleGuide.input_dir"> <tt class="descname">input_dir</tt><big>(</big><em>dirname</em><big>)</big><a class="reference internal" href="_modules/pep8.html#StyleGuide.input_dir"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.StyleGuide.input_dir" title="Permalink to this definition">¶</a></dt> <dd><p>Check all files in this directory and all subdirectories.</p> </dd></dl> <dl class="method"> <dt id="pep8.StyleGuide.excluded"> <tt class="descname">excluded</tt><big>(</big><em>filename</em>, <em>parent=None</em><big>)</big><a class="reference internal" href="_modules/pep8.html#StyleGuide.excluded"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.StyleGuide.excluded" title="Permalink to this definition">¶</a></dt> <dd><p>Check if the file should be excluded.</p> <p>Check if ‘options.exclude’ contains a pattern that matches filename.</p> </dd></dl> <dl class="method"> <dt id="pep8.StyleGuide.ignore_code"> <tt class="descname">ignore_code</tt><big>(</big><em>code</em><big>)</big><a class="reference internal" href="_modules/pep8.html#StyleGuide.ignore_code"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.StyleGuide.ignore_code" title="Permalink to this definition">¶</a></dt> <dd><p>Check if the error code should be ignored.</p> <p>If ‘options.select’ contains a prefix of the error code, return False. Else, if ‘options.ignore’ contains a prefix of the error code, return True.</p> </dd></dl> <dl class="method"> <dt id="pep8.StyleGuide.get_checks"> <tt class="descname">get_checks</tt><big>(</big><em>argument_name</em><big>)</big><a class="reference internal" href="_modules/pep8.html#StyleGuide.get_checks"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.StyleGuide.get_checks" title="Permalink to this definition">¶</a></dt> <dd><p>Get all the checks for this category.</p> <p>Find all globally visible functions where the first argument name starts with argument_name and which contain selected tests.</p> </dd></dl> </dd></dl> <dl class="class"> <dt id="pep8.Checker"> <em class="property">class </em><tt class="descclassname">pep8.</tt><tt class="descname">Checker</tt><big>(</big><em>filename=None</em>, <em>lines=None</em>, <em>report=None</em>, <em>**kwargs</em><big>)</big><a class="reference internal" href="_modules/pep8.html#Checker"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.Checker" title="Permalink to this definition">¶</a></dt> <dd><p>Load a Python source file, tokenize it, check coding style.</p> <dl class="method"> <dt id="pep8.Checker.readline"> <tt class="descname">readline</tt><big>(</big><big>)</big><a class="reference internal" href="_modules/pep8.html#Checker.readline"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.Checker.readline" title="Permalink to this definition">¶</a></dt> <dd><p>Get the next line from the input buffer.</p> </dd></dl> <dl class="method"> <dt id="pep8.Checker.run_check"> <tt class="descname">run_check</tt><big>(</big><em>check</em>, <em>argument_names</em><big>)</big><a class="reference internal" href="_modules/pep8.html#Checker.run_check"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.Checker.run_check" title="Permalink to this definition">¶</a></dt> <dd><p>Run a check plugin.</p> </dd></dl> <dl class="method"> <dt id="pep8.Checker.check_physical"> <tt class="descname">check_physical</tt><big>(</big><em>line</em><big>)</big><a class="reference internal" href="_modules/pep8.html#Checker.check_physical"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.Checker.check_physical" title="Permalink to this definition">¶</a></dt> <dd><p>Run all physical checks on a raw input line.</p> </dd></dl> <dl class="method"> <dt id="pep8.Checker.build_tokens_line"> <tt class="descname">build_tokens_line</tt><big>(</big><big>)</big><a class="reference internal" href="_modules/pep8.html#Checker.build_tokens_line"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.Checker.build_tokens_line" title="Permalink to this definition">¶</a></dt> <dd><p>Build a logical line from tokens.</p> </dd></dl> <dl class="method"> <dt id="pep8.Checker.check_logical"> <tt class="descname">check_logical</tt><big>(</big><big>)</big><a class="reference internal" href="_modules/pep8.html#Checker.check_logical"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.Checker.check_logical" title="Permalink to this definition">¶</a></dt> <dd><p>Build a line from tokens and run all logical checks on it.</p> </dd></dl> <dl class="method"> <dt id="pep8.Checker.check_ast"> <tt class="descname">check_ast</tt><big>(</big><big>)</big><a class="reference internal" href="_modules/pep8.html#Checker.check_ast"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.Checker.check_ast" title="Permalink to this definition">¶</a></dt> <dd><p>Build the file’s AST and run all AST checks.</p> </dd></dl> <dl class="method"> <dt id="pep8.Checker.generate_tokens"> <tt class="descname">generate_tokens</tt><big>(</big><big>)</big><a class="reference internal" href="_modules/pep8.html#Checker.generate_tokens"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.Checker.generate_tokens" title="Permalink to this definition">¶</a></dt> <dd><p>Tokenize the file, run physical line checks and yield tokens.</p> </dd></dl> <dl class="method"> <dt id="pep8.Checker.check_all"> <tt class="descname">check_all</tt><big>(</big><em>expected=None</em>, <em>line_offset=0</em><big>)</big><a class="reference internal" href="_modules/pep8.html#Checker.check_all"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.Checker.check_all" title="Permalink to this definition">¶</a></dt> <dd><p>Run all checks on the input file.</p> </dd></dl> </dd></dl> </div> <div class="section" id="report-classes"> <span id="id1"></span><h2><a class="toc-backref" href="#id3">Report Classes</a><a class="headerlink" href="#report-classes" title="Permalink to this headline">¶</a></h2> <dl class="class"> <dt id="pep8.BaseReport"> <em class="property">class </em><tt class="descclassname">pep8.</tt><tt class="descname">BaseReport</tt><big>(</big><em>options</em><big>)</big><a class="reference internal" href="_modules/pep8.html#BaseReport"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.BaseReport" title="Permalink to this definition">¶</a></dt> <dd><p>Collect the results of the checks.</p> <dl class="method"> <dt id="pep8.BaseReport.start"> <tt class="descname">start</tt><big>(</big><big>)</big><a class="reference internal" href="_modules/pep8.html#BaseReport.start"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.BaseReport.start" title="Permalink to this definition">¶</a></dt> <dd><p>Start the timer.</p> </dd></dl> <dl class="method"> <dt id="pep8.BaseReport.stop"> <tt class="descname">stop</tt><big>(</big><big>)</big><a class="reference internal" href="_modules/pep8.html#BaseReport.stop"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.BaseReport.stop" title="Permalink to this definition">¶</a></dt> <dd><p>Stop the timer.</p> </dd></dl> <dl class="method"> <dt id="pep8.BaseReport.init_file"> <tt class="descname">init_file</tt><big>(</big><em>filename</em>, <em>lines</em>, <em>expected</em>, <em>line_offset</em><big>)</big><a class="reference internal" href="_modules/pep8.html#BaseReport.init_file"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.BaseReport.init_file" title="Permalink to this definition">¶</a></dt> <dd><p>Signal a new file.</p> </dd></dl> <dl class="method"> <dt id="pep8.BaseReport.increment_logical_line"> <tt class="descname">increment_logical_line</tt><big>(</big><big>)</big><a class="reference internal" href="_modules/pep8.html#BaseReport.increment_logical_line"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.BaseReport.increment_logical_line" title="Permalink to this definition">¶</a></dt> <dd><p>Signal a new logical line.</p> </dd></dl> <dl class="method"> <dt id="pep8.BaseReport.error"> <tt class="descname">error</tt><big>(</big><em>line_number</em>, <em>offset</em>, <em>text</em>, <em>check</em><big>)</big><a class="reference internal" href="_modules/pep8.html#BaseReport.error"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.BaseReport.error" title="Permalink to this definition">¶</a></dt> <dd><p>Report an error, according to options.</p> </dd></dl> <dl class="method"> <dt id="pep8.BaseReport.get_file_results"> <tt class="descname">get_file_results</tt><big>(</big><big>)</big><a class="reference internal" href="_modules/pep8.html#BaseReport.get_file_results"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.BaseReport.get_file_results" title="Permalink to this definition">¶</a></dt> <dd><p>Return the count of errors and warnings for this file.</p> </dd></dl> <dl class="method"> <dt id="pep8.BaseReport.get_count"> <tt class="descname">get_count</tt><big>(</big><em>prefix=''</em><big>)</big><a class="reference internal" href="_modules/pep8.html#BaseReport.get_count"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.BaseReport.get_count" title="Permalink to this definition">¶</a></dt> <dd><p>Return the total count of errors and warnings.</p> </dd></dl> <dl class="method"> <dt id="pep8.BaseReport.get_statistics"> <tt class="descname">get_statistics</tt><big>(</big><em>prefix=''</em><big>)</big><a class="reference internal" href="_modules/pep8.html#BaseReport.get_statistics"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.BaseReport.get_statistics" title="Permalink to this definition">¶</a></dt> <dd><p>Get statistics for message codes that start with the prefix.</p> <p>prefix=’’ matches all errors and warnings prefix=’E’ matches all errors prefix=’W’ matches all warnings prefix=’E4’ matches all errors that have to do with imports</p> </dd></dl> <dl class="method"> <dt id="pep8.BaseReport.print_statistics"> <tt class="descname">print_statistics</tt><big>(</big><em>prefix=''</em><big>)</big><a class="reference internal" href="_modules/pep8.html#BaseReport.print_statistics"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.BaseReport.print_statistics" title="Permalink to this definition">¶</a></dt> <dd><p>Print overall statistics (number of errors and warnings).</p> </dd></dl> <dl class="method"> <dt id="pep8.BaseReport.print_benchmark"> <tt class="descname">print_benchmark</tt><big>(</big><big>)</big><a class="reference internal" href="_modules/pep8.html#BaseReport.print_benchmark"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.BaseReport.print_benchmark" title="Permalink to this definition">¶</a></dt> <dd><p>Print benchmark numbers.</p> </dd></dl> </dd></dl> <dl class="class"> <dt id="pep8.FileReport"> <em class="property">class </em><tt class="descclassname">pep8.</tt><tt class="descname">FileReport</tt><big>(</big><em>options</em><big>)</big><a class="reference internal" href="_modules/pep8.html#FileReport"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.FileReport" title="Permalink to this definition">¶</a></dt> <dd><p>Collect the results of the checks and print only the filenames.</p> </dd></dl> <dl class="class"> <dt id="pep8.StandardReport"> <em class="property">class </em><tt class="descclassname">pep8.</tt><tt class="descname">StandardReport</tt><big>(</big><em>options</em><big>)</big><a class="reference internal" href="_modules/pep8.html#StandardReport"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.StandardReport" title="Permalink to this definition">¶</a></dt> <dd><p>Collect and print the results of the checks.</p> </dd></dl> <dl class="class"> <dt id="pep8.DiffReport"> <em class="property">class </em><tt class="descclassname">pep8.</tt><tt class="descname">DiffReport</tt><big>(</big><em>options</em><big>)</big><a class="reference internal" href="_modules/pep8.html#DiffReport"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.DiffReport" title="Permalink to this definition">¶</a></dt> <dd><p>Collect and print the results for the changed lines only.</p> </dd></dl> </div> <div class="section" id="utilities"> <h2><a class="toc-backref" href="#id4">Utilities</a><a class="headerlink" href="#utilities" title="Permalink to this headline">¶</a></h2> <dl class="function"> <dt id="pep8.expand_indent"> <tt class="descclassname">pep8.</tt><tt class="descname">expand_indent</tt><big>(</big><em>line</em><big>)</big><a class="reference internal" href="_modules/pep8.html#expand_indent"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.expand_indent" title="Permalink to this definition">¶</a></dt> <dd><p>Return the amount of indentation.</p> <p>Tabs are expanded to the next multiple of 8.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">expand_indent</span><span class="p">(</span><span class="s">' '</span><span class="p">)</span> <span class="go">4</span> <span class="gp">>>> </span><span class="n">expand_indent</span><span class="p">(</span><span class="s">'</span><span class="se">\t</span><span class="s">'</span><span class="p">)</span> <span class="go">8</span> <span class="gp">>>> </span><span class="n">expand_indent</span><span class="p">(</span><span class="s">' </span><span class="se">\t</span><span class="s">'</span><span class="p">)</span> <span class="go">8</span> <span class="gp">>>> </span><span class="n">expand_indent</span><span class="p">(</span><span class="s">' </span><span class="se">\t</span><span class="s">'</span><span class="p">)</span> <span class="go">16</span> </pre></div> </div> </dd></dl> <dl class="function"> <dt id="pep8.mute_string"> <tt class="descclassname">pep8.</tt><tt class="descname">mute_string</tt><big>(</big><em>text</em><big>)</big><a class="reference internal" href="_modules/pep8.html#mute_string"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.mute_string" title="Permalink to this definition">¶</a></dt> <dd><p>Replace contents with ‘xxx’ to prevent syntax matching.</p> <div class="highlight-python"><div class="highlight"><pre><span class="gp">>>> </span><span class="n">mute_string</span><span class="p">(</span><span class="s">'"abc"'</span><span class="p">)</span> <span class="go">'"xxx"'</span> <span class="gp">>>> </span><span class="n">mute_string</span><span class="p">(</span><span class="s">"'''abc'''"</span><span class="p">)</span> <span class="go">"'''xxx'''"</span> <span class="gp">>>> </span><span class="n">mute_string</span><span class="p">(</span><span class="s">"r'abc'"</span><span class="p">)</span> <span class="go">"r'xxx'"</span> </pre></div> </div> </dd></dl> <dl class="function"> <dt id="pep8.read_config"> <tt class="descclassname">pep8.</tt><tt class="descname">read_config</tt><big>(</big><em>options</em>, <em>args</em>, <em>arglist</em>, <em>parser</em><big>)</big><a class="reference internal" href="_modules/pep8.html#read_config"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.read_config" title="Permalink to this definition">¶</a></dt> <dd><p>Read both user configuration and local configuration.</p> </dd></dl> <dl class="function"> <dt id="pep8.process_options"> <tt class="descclassname">pep8.</tt><tt class="descname">process_options</tt><big>(</big><em>arglist=None</em>, <em>parse_argv=False</em>, <em>config_file=None</em><big>)</big><a class="reference internal" href="_modules/pep8.html#process_options"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.process_options" title="Permalink to this definition">¶</a></dt> <dd><p>Process options passed either via arglist or via command line args.</p> </dd></dl> <dl class="function"> <dt id="pep8.register_check"> <tt class="descclassname">pep8.</tt><tt class="descname">register_check</tt><big>(</big><em>func_or_cls</em>, <em>codes=None</em><big>)</big><a class="reference internal" href="_modules/pep8.html#register_check"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#pep8.register_check" title="Permalink to this definition">¶</a></dt> <dd><p>Register a new check object.</p> </dd></dl> </div> </div> </div> </div> </div> <div class="sphinxsidebar"> <div class="sphinxsidebarwrapper"> <h3><a href="index.html">Table Of Contents</a></h3> <ul> <li><a class="reference internal" href="#">pep8 API</a><ul> <li><a class="reference internal" href="#checker-classes">Checker Classes</a></li> <li><a class="reference internal" href="#report-classes">Report Classes</a></li> <li><a class="reference internal" href="#utilities">Utilities</a></li> </ul> </li> </ul> <h4>Previous topic</h4> <p class="topless"><a href="advanced.html" title="previous chapter">Advanced usage</a></p> <h4>Next topic</h4> <p class="topless"><a href="developer.html" title="next chapter">Developer’s notes</a></p> <h3>This Page</h3> <ul class="this-page-menu"> <li><a href="_sources/api.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="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="developer.html" title="Developer’s notes" >next</a> |</li> <li class="right" > <a href="advanced.html" title="Advanced usage" >previous</a> |</li> <li><a href="index.html">pep8 1.5.7 documentation</a> »</li> </ul> </div> <div class="footer"> © Copyright 2012-2013, Florent Xicluna. Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.3. </div> </body> </html>