Commit 7551f2be authored by Ondřej Nový's avatar Ondřej Nový

Import python-flake8_3.0.3+dfsg1.orig.tar.gz

parent cab28e68
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 55b5c554abc6926b5703672006d28269
tags: 645f666f9bcd5a90fca523b33c5a78b7
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>flake8.api &mdash; flake8 3.0.0b2 documentation</title>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="top" title="flake8 3.0.0b2 documentation" href="../../index.html"/>
<link rel="up" title="Module code" href="../index.html"/>
<script src="../../_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href="../../index.html" class="icon icon-home"> flake8
</a>
<div class="version">
3.0.0b2
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../faq.html">Frequently Asked Questions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../glossary.html">Glossary of Terms Used in Flake8 Documentation</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../user/index.html">Using Flake8</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../plugin-development/index.html">Writing Plugins for Flake8</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../internal/index.html">Exploring Flake8&#8217;s Internals</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../release-notes/index.html">Release Notes and History</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">flake8</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li>flake8.api</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for flake8.api</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;Module containing all public entry-points for Flake8.</span>
<span class="sd">This is the only submodule in Flake8 with a guaranteed stable API. All other</span>
<span class="sd">submodules are considered internal only and are subject to change.</span>
<span class="sd">&quot;&quot;&quot;</span>
<div class="viewcode-block" id="get_style_guide"><a class="viewcode-back" href="../../user/python-api.html#flake8.api.get_style_guide">[docs]</a><span class="k">def</span> <span class="nf">get_style_guide</span><span class="p">(</span><span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Stub out the only function I&#39;m aware of people using.&quot;&quot;&quot;</span>
<span class="k">pass</span></div>
</pre></div>
</div>
</div>
<footer>
<hr/>
<div role="contentinfo">
<p>
&copy; Copyright 2016, Ian Cordasco.
</p>
</div>
Built with <a href="http://sphinx-doc.org/">Sphinx</a> using a <a href="https://github.com/snide/sphinx_rtd_theme">theme</a> provided by <a href="https://readthedocs.org">Read the Docs</a>.
</footer>
</div>
</div>
</section>
</div>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'../../',
VERSION:'3.0.0b2',
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/js/theme.js"></script>
<script type="text/javascript">
jQuery(function () {
SphinxRtdTheme.StickyNav.enable();
});
</script>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>flake8.checker &mdash; flake8 3.0.2 documentation</title>
<link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" />
<link rel="top" title="flake8 3.0.2 documentation" href="../../index.html"/>
<link rel="up" title="Module code" href="../index.html"/>
<script src="../../_static/js/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav" role="document">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-scroll">
<div class="wy-side-nav-search">
<a href="../../index.html" class="icon icon-home"> flake8
</a>
<div class="version">
3.0.2
</div>
<div role="search">
<form id="rtd-search-form" class="wy-form" action="../../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../faq.html">Frequently Asked Questions</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../glossary.html">Glossary of Terms Used in Flake8 Documentation</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../user/index.html">Using Flake8</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../plugin-development/index.html">Writing Plugins for Flake8</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../internal/index.html">Exploring Flake8&#8217;s Internals</a></li>
</ul>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../release-notes/index.html">Release Notes and History</a></li>
</ul>
</div>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top" role="navigation" aria-label="top navigation">
<i data-toggle="wy-nav-top" class="fa fa-bars"></i>
<a href="../../index.html">flake8</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<div role="navigation" aria-label="breadcrumbs navigation">
<ul class="wy-breadcrumbs">
<li><a href="../../index.html">Docs</a> &raquo;</li>
<li><a href="../index.html">Module code</a> &raquo;</li>
<li>flake8.checker</li>
<li class="wy-breadcrumbs-aside">
</li>
</ul>
<hr/>
</div>
<div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
<div itemprop="articleBody">
<h1>Source code for flake8.checker</h1><div class="highlight"><pre>
<span></span><span class="sd">&quot;&quot;&quot;Checker Manager and Checker classes.&quot;&quot;&quot;</span>
<span class="kn">import</span> <span class="nn">errno</span>
<span class="kn">import</span> <span class="nn">logging</span>
<span class="kn">import</span> <span class="nn">os</span>
<span class="kn">import</span> <span class="nn">sys</span>
<span class="kn">import</span> <span class="nn">tokenize</span>
<span class="k">try</span><span class="p">:</span>
<span class="kn">import</span> <span class="nn">multiprocessing</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
<span class="n">multiprocessing</span> <span class="o">=</span> <span class="kc">None</span>
<span class="k">try</span><span class="p">:</span>
<span class="kn">import</span> <span class="nn">Queue</span> <span class="k">as</span> <span class="nn">queue</span>
<span class="k">except</span> <span class="ne">ImportError</span><span class="p">:</span>
<span class="kn">import</span> <span class="nn">queue</span>
<span class="kn">from</span> <span class="nn">flake8</span> <span class="k">import</span> <span class="n">defaults</span>
<span class="kn">from</span> <span class="nn">flake8</span> <span class="k">import</span> <span class="n">exceptions</span>
<span class="kn">from</span> <span class="nn">flake8</span> <span class="k">import</span> <span class="n">processor</span>
<span class="kn">from</span> <span class="nn">flake8</span> <span class="k">import</span> <span class="n">utils</span>
<span class="n">LOG</span> <span class="o">=</span> <span class="n">logging</span><span class="o">.</span><span class="n">getLogger</span><span class="p">(</span><span class="n">__name__</span><span class="p">)</span>
<span class="n">SERIAL_RETRY_ERRNOS</span> <span class="o">=</span> <span class="nb">set</span><span class="p">([</span>
<span class="c1"># ENOSPC: Added by sigmavirus24</span>
<span class="c1"># &gt; On some operating systems (OSX), multiprocessing may cause an</span>
<span class="c1"># &gt; ENOSPC error while trying to trying to create a Semaphore.</span>
<span class="c1"># &gt; In those cases, we should replace the customized Queue Report</span>
<span class="c1"># &gt; class with pep8&#39;s StandardReport class to ensure users don&#39;t run</span>
<span class="c1"># &gt; into this problem.</span>
<span class="c1"># &gt; (See also: https://gitlab.com/pycqa/flake8/issues/74)</span>
<span class="n">errno</span><span class="o">.</span><span class="n">ENOSPC</span><span class="p">,</span>
<span class="c1"># NOTE(sigmavirus24): When adding to this list, include the reasoning</span>
<span class="c1"># on the lines before the error code and always append your error</span>
<span class="c1"># code. Further, please always add a trailing `,` to reduce the visual</span>
<span class="c1"># noise in diffs.</span>
<span class="p">])</span>
<span class="k">def</span> <span class="nf">_run_checks_from_queue</span><span class="p">(</span><span class="n">process_queue</span><span class="p">,</span> <span class="n">results_queue</span><span class="p">,</span> <span class="n">statistics_queue</span><span class="p">):</span>
<span class="n">LOG</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;Running checks in parallel&#39;</span><span class="p">)</span>
<span class="k">try</span><span class="p">:</span>
<span class="k">for</span> <span class="n">checker</span> <span class="ow">in</span> <span class="nb">iter</span><span class="p">(</span><span class="n">process_queue</span><span class="o">.</span><span class="n">get</span><span class="p">,</span> <span class="s1">&#39;DONE&#39;</span><span class="p">):</span>
<span class="n">LOG</span><span class="o">.</span><span class="n">info</span><span class="p">(</span><span class="s1">&#39;Checking &quot;</span><span class="si">%s</span><span class="s1">&quot;&#39;</span><span class="p">,</span> <span class="n">checker</span><span class="o">.</span><span class="n">filename</span><span class="p">)</span>
<span class="n">checker</span><span class="o">.</span><span class="n">run_checks</span><span class="p">(</span><span class="n">results_queue</span><span class="p">,</span> <span class="n">statistics_queue</span><span class="p">)</span>
<span class="k">except</span> <span class="n">exceptions</span><span class="o">.</span><span class="n">PluginRequestedUnknownParameters</span> <span class="k">as</span> <span class="n">exc</span><span class="p">:</span>
<span class="nb">print</span><span class="p">(</span><span class="nb">str</span><span class="p">(</span><span class="n">exc</span><span class="p">))</span>
<span class="k">except</span> <span class="ne">Exception</span> <span class="k">as</span> <span class="n">exc</span><span class="p">:</span>
<span class="n">LOG</span><span class="o">.</span><span class="n">error</span><span class="p">(</span><span class="s1">&#39;Unhandled exception occurred&#39;</span><span class="p">)</span>
<span class="k">raise</span>
<span class="k">finally</span><span class="p">:</span>
<span class="n">results_queue</span><span class="o">.</span><span class="n">put</span><span class="p">(</span><span class="s1">&#39;DONE&#39;</span><span class="p">)</span>
<div class="viewcode-block" id="Manager"><a class="viewcode-back" href="../../internal/checker.html#flake8.checker.Manager">[docs]</a><span class="k">class</span> <span class="nc">Manager</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Manage the parallelism and checker instances for each plugin and file.</span>
<span class="sd"> This class will be responsible for the following:</span>
<span class="sd"> - Determining the parallelism of Flake8, e.g.:</span>
<span class="sd"> * Do we use :mod:`multiprocessing` or is it unavailable?</span>
<span class="sd"> * Do we automatically decide on the number of jobs to use or did the</span>
<span class="sd"> user provide that?</span>
<span class="sd"> - Falling back to a serial way of processing files if we run into an</span>
<span class="sd"> OSError related to :mod:`multiprocessing`</span>
<span class="sd"> - Organizing the results of each checker so we can group the output</span>
<span class="sd"> together and make our output deterministic.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">style_guide</span><span class="p">,</span> <span class="n">arguments</span><span class="p">,</span> <span class="n">checker_plugins</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Initialize our Manager instance.</span>
<span class="sd"> :param style_guide:</span>
<span class="sd"> The instantiated style guide for this instance of Flake8.</span>
<span class="sd"> :type style_guide:</span>
<span class="sd"> flake8.style_guide.StyleGuide</span>
<span class="sd"> :param list arguments:</span>
<span class="sd"> The extra arguments parsed from the CLI (if any)</span>
<span class="sd"> :param checker_plugins:</span>
<span class="sd"> The plugins representing checks parsed from entry-points.</span>
<span class="sd"> :type checker_plugins:</span>
<span class="sd"> flake8.plugins.manager.Checkers</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">arguments</span> <span class="o">=</span> <span class="n">arguments</span>
<span class="bp">self</span><span class="o">.</span><span class="n">style_guide</span> <span class="o">=</span> <span class="n">style_guide</span>
<span class="bp">self</span><span class="o">.</span><span class="n">options</span> <span class="o">=</span> <span class="n">style_guide</span><span class="o">.</span><span class="n">options</span>
<span class="bp">self</span><span class="o">.</span><span class="n">checks</span> <span class="o">=</span> <span class="n">checker_plugins</span>
<span class="bp">self</span><span class="o">.</span><span class="n">jobs</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">_job_count</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">process_queue</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">results_queue</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">statistics_queue</span> <span class="o">=</span> <span class="kc">None</span>
<span class="bp">self</span><span class="o">.</span><span class="n">using_multiprocessing</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">jobs</span> <span class="o">&gt;</span> <span class="mi">1</span>
<span class="bp">self</span><span class="o">.</span><span class="n">processes</span> <span class="o">=</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">checkers</span> <span class="o">=</span> <span class="p">[]</span>
<span class="bp">self</span><span class="o">.</span><span class="n">statistics</span> <span class="o">=</span> <span class="p">{</span>
<span class="s1">&#39;files&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
<span class="s1">&#39;logical lines&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
<span class="s1">&#39;physical lines&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
<span class="s1">&#39;tokens&#39;</span><span class="p">:</span> <span class="mi">0</span><span class="p">,</span>
<span class="p">}</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">using_multiprocessing</span><span class="p">:</span>
<span class="k">try</span><span class="p">:</span>
<span class="bp">self</span><span class="o">.</span><span class="n">process_queue</span> <span class="o">=</span> <span class="n">multiprocessing</span><span class="o">.</span><span class="n">Queue</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">results_queue</span> <span class="o">=</span> <span class="n">multiprocessing</span><span class="o">.</span><span class="n">Queue</span><span class="p">()</span>
<span class="bp">self</span><span class="o">.</span><span class="n">statistics_queue</span> <span class="o">=</span> <span class="n">multiprocessing</span><span class="o">.</span><span class="n">Queue</span><span class="p">()</span>
<span class="k">except</span> <span class="ne">OSError</span> <span class="k">as</span> <span class="n">oserr</span><span class="p">:</span>
<span class="k">if</span> <span class="n">oserr</span><span class="o">.</span><span class="n">errno</span> <span class="ow">not</span> <span class="ow">in</span> <span class="n">SERIAL_RETRY_ERRNOS</span><span class="p">:</span>
<span class="k">raise</span>
<span class="bp">self</span><span class="o">.</span><span class="n">using_multiprocessing</span> <span class="o">=</span> <span class="kc">False</span>
<span class="nd">@staticmethod</span>
<span class="k">def</span> <span class="nf">_cleanup_queue</span><span class="p">(</span><span class="n">q</span><span class="p">):</span>
<span class="k">while</span> <span class="ow">not</span> <span class="n">q</span><span class="o">.</span><span class="n">empty</span><span class="p">():</span>
<span class="n">q</span><span class="o">.</span><span class="n">get_nowait</span><span class="p">()</span>
<span class="k">def</span> <span class="nf">_force_cleanup</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">using_multiprocessing</span><span class="p">:</span>
<span class="k">for</span> <span class="n">proc</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">processes</span><span class="p">:</span>
<span class="n">proc</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="mf">0.2</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_cleanup_queue</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">process_queue</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_cleanup_queue</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">results_queue</span><span class="p">)</span>
<span class="bp">self</span><span class="o">.</span><span class="n">_cleanup_queue</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">statistics_queue</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">_process_statistics</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="n">all_statistics</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">statistics</span>
<span class="k">if</span> <span class="bp">self</span><span class="o">.</span><span class="n">using_multiprocessing</span><span class="p">:</span>
<span class="n">total_number_of_checkers</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">checkers</span><span class="p">)</span>