git-linter/modules/git_lint/reporters.html

168 lines
18 KiB
HTML
Raw Permalink Normal View History

2016-10-04 00:31:52 +00:00
<!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" />
2017-08-02 17:49:29 +00:00
<title>git_lint.reporters &#8212; Git Lint 0.0.7 documentation</title>
2016-10-04 00:31:52 +00:00
2016-10-06 15:32:58 +00:00
<link rel="stylesheet" href="../../static/alabaster.css" type="text/css" />
2016-10-04 00:31:52 +00:00
<link rel="stylesheet" href="../../static/pygments.css" type="text/css" />
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT: '../../',
2017-08-02 17:49:29 +00:00
VERSION: '0.0.7',
2016-10-04 00:31:52 +00:00
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>
2017-08-02 17:49:29 +00:00
<link rel="top" title="Git Lint 0.0.7 documentation" href="../../index.html" />
2016-10-06 15:32:58 +00:00
<link rel="up" title="Module code" href="../index.html" />
<link rel="stylesheet" href="../../static/custom.css" type="text/css" />
<meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=0.9" />
2016-10-04 00:31:52 +00:00
</head>
2016-10-05 16:16:06 +00:00
<body role="document">
2016-10-06 15:32:58 +00:00
2016-10-04 00:31:52 +00:00
<div class="document">
<div class="documentwrapper">
<div class="bodywrapper">
2016-10-05 16:16:06 +00:00
<div class="body" role="main">
2016-10-04 00:31:52 +00:00
<h1>Source code for git_lint.reporters</h1><div class="highlight"><pre>
2016-10-05 16:16:06 +00:00
<span></span><span class="kn">from</span> <span class="nn">__future__</span> <span class="k">import</span> <span class="n">print_function</span>
2017-08-02 17:49:29 +00:00
<span class="kn">from</span> <span class="nn">functools</span> <span class="k">import</span> <span class="n">reduce</span>
2016-10-05 16:16:06 +00:00
<span class="kn">from</span> <span class="nn">.git_lint</span> <span class="k">import</span> <span class="n">load_config</span><span class="p">,</span> <span class="n">run_linters</span><span class="p">,</span> <span class="n">git_base</span>
2016-10-04 00:31:52 +00:00
<span class="kn">import</span> <span class="nn">operator</span>
<span class="kn">import</span> <span class="nn">gettext</span>
<span class="n">_</span> <span class="o">=</span> <span class="n">gettext</span><span class="o">.</span><span class="n">gettext</span>
2016-10-05 21:58:53 +00:00
<div class="viewcode-block" id="print_report"><a class="viewcode-back" href="../../git_lint.html#git_lint.reporters.print_report">[docs]</a><span class="k">def</span> <span class="nf">print_report</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">unlintable_filenames</span><span class="p">,</span> <span class="n">cant_lint_filenames</span><span class="p">,</span>
<span class="n">broken_linter_names</span><span class="p">,</span> <span class="n">unfindable_filenames</span><span class="p">,</span> <span class="n">options</span><span class="o">=</span><span class="p">{</span><span class="s1">&#39;bylinter&#39;</span><span class="p">:</span> <span class="kc">True</span><span class="p">}):</span>
2016-10-04 00:31:52 +00:00
2016-10-05 21:58:53 +00:00
<span class="k">def</span> <span class="nf">base_file_cleaner</span><span class="p">(</span><span class="n">files</span><span class="p">):</span>
<span class="k">return</span> <span class="p">[</span><span class="n">file</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">git_base</span> <span class="o">+</span> <span class="s1">&#39;/&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="k">for</span> <span class="n">file</span> <span class="ow">in</span> <span class="n">files</span><span class="p">]</span>
2016-10-05 16:16:06 +00:00
2016-10-05 21:58:53 +00:00
<span class="c1"># ICK. Mutation, references, and hidden assignment.</span>
<span class="k">def</span> <span class="nf">group_by</span><span class="p">(</span><span class="n">iterable</span><span class="p">,</span> <span class="n">field_id</span><span class="p">):</span>
<span class="n">results</span> <span class="o">=</span> <span class="p">[]</span>
<span class="n">keys</span> <span class="o">=</span> <span class="p">{}</span>
<span class="k">for</span> <span class="n">obj</span> <span class="ow">in</span> <span class="n">iterable</span><span class="p">:</span>
<span class="n">key</span> <span class="o">=</span> <span class="n">obj</span><span class="p">[</span><span class="n">field_id</span><span class="p">]</span>
<span class="k">if</span> <span class="n">key</span> <span class="ow">in</span> <span class="n">keys</span><span class="p">:</span>
<span class="n">keys</span><span class="p">[</span><span class="n">key</span><span class="p">]</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="n">obj</span><span class="p">)</span>
<span class="k">continue</span>
<span class="n">keys</span><span class="p">[</span><span class="n">key</span><span class="p">]</span> <span class="o">=</span> <span class="p">[</span><span class="n">obj</span><span class="p">]</span>
<span class="n">results</span><span class="o">.</span><span class="n">append</span><span class="p">((</span><span class="n">key</span><span class="p">,</span> <span class="n">keys</span><span class="p">[</span><span class="n">key</span><span class="p">]))</span>
<span class="k">return</span> <span class="n">results</span>
2016-10-04 00:31:52 +00:00
<span class="n">sort_position</span> <span class="o">=</span> <span class="mi">1</span>
2016-10-05 16:16:06 +00:00
<span class="n">grouping</span> <span class="o">=</span> <span class="n">_</span><span class="p">(</span><span class="s1">&#39;Linter: </span><span class="si">{}</span><span class="s1">&#39;</span><span class="p">)</span>
<span class="k">if</span> <span class="s1">&#39;byfile&#39;</span> <span class="ow">in</span> <span class="n">options</span><span class="p">:</span>
2016-10-04 00:31:52 +00:00
<span class="n">sort_position</span> <span class="o">=</span> <span class="mi">0</span>
2016-10-05 16:16:06 +00:00
<span class="n">grouping</span> <span class="o">=</span> <span class="n">_</span><span class="p">(</span><span class="s1">&#39;Filename: </span><span class="si">{}</span><span class="s1">&#39;</span><span class="p">)</span>
2016-10-04 00:31:52 +00:00
<span class="n">grouped_results</span> <span class="o">=</span> <span class="n">group_by</span><span class="p">(</span><span class="n">results</span><span class="p">,</span> <span class="n">sort_position</span><span class="p">)</span>
<span class="k">for</span> <span class="n">group</span> <span class="ow">in</span> <span class="n">grouped_results</span><span class="p">:</span>
2016-10-05 16:16:06 +00:00
<span class="n">messages</span> <span class="o">=</span> <span class="n">reduce</span><span class="p">(</span><span class="n">operator</span><span class="o">.</span><span class="n">add</span><span class="p">,</span> <span class="p">[</span><span class="n">item</span><span class="p">[</span><span class="mi">3</span><span class="p">]</span> <span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">group</span><span class="p">[</span><span class="mi">1</span><span class="p">]],</span> <span class="p">[])</span>
2016-10-04 00:31:52 +00:00
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">messages</span><span class="p">)</span> <span class="o">==</span> <span class="mi">0</span><span class="p">:</span>
<span class="k">continue</span>
2016-10-05 16:16:06 +00:00
<span class="nb">print</span><span class="p">(</span><span class="n">grouping</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">group</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span>
2016-10-04 00:31:52 +00:00
<span class="k">for</span> <span class="p">(</span><span class="n">filename</span><span class="p">,</span> <span class="n">lintername</span><span class="p">,</span> <span class="n">returncode</span><span class="p">,</span> <span class="n">text</span><span class="p">)</span> <span class="ow">in</span> <span class="n">group</span><span class="p">[</span><span class="mi">1</span><span class="p">]:</span>
<span class="k">if</span> <span class="n">text</span><span class="p">:</span>
2016-10-05 16:16:06 +00:00
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">base_file_cleaner</span><span class="p">(</span><span class="n">text</span><span class="p">)))</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">)</span>
<span class="nb">print</span> <span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">)</span>
2016-10-04 00:31:52 +00:00
2016-10-05 16:16:06 +00:00
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">broken_linter_names</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">cant_lint_filenames</span><span class="p">)</span> <span class="ow">or</span> <span class="p">(</span><span class="s1">&#39;verbose&#39;</span> <span class="ow">in</span> <span class="n">options</span><span class="p">)):</span>
<span class="nb">print</span><span class="p">(</span><span class="n">_</span><span class="p">(</span><span class="s1">&#39;Linters not found:&#39;</span><span class="p">),</span> <span class="s1">&#39;,&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">(</span><span class="n">broken_linter_names</span><span class="p">))</span>
2016-10-04 00:31:52 +00:00
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">cant_lint_filenames</span><span class="p">):</span>
2016-10-05 16:16:06 +00:00
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39; &#39;</span> <span class="o">+</span> <span class="n">_</span><span class="p">(</span><span class="s1">&#39;Files not linted:&#39;</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s1">&#39; </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">f</span><span class="p">)</span> <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">cant_lint_filenames</span><span class="p">]))</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">)</span>
2016-10-04 00:31:52 +00:00
2016-10-05 16:16:06 +00:00
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">unlintable_filenames</span><span class="p">)</span> <span class="ow">and</span> <span class="p">(</span><span class="s1">&#39;verbose&#39;</span> <span class="ow">in</span> <span class="n">options</span><span class="p">):</span>
<span class="nb">print</span><span class="p">(</span><span class="n">_</span><span class="p">(</span><span class="s1">&#39;No recognizeable linters for:&#39;</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s1">&#39; </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">f</span><span class="p">)</span> <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">unlintable_filenames</span><span class="p">]))</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">)</span>
2016-10-04 00:31:52 +00:00
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">unfindable_filenames</span><span class="p">):</span>
2016-10-05 16:16:06 +00:00
<span class="nb">print</span><span class="p">(</span><span class="n">_</span><span class="p">(</span><span class="s1">&#39;Files not found:&#39;</span><span class="p">))</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="se">\n</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s1">&#39; </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">f</span><span class="p">)</span> <span class="k">for</span> <span class="n">f</span> <span class="ow">in</span> <span class="n">unfindable_filenames</span><span class="p">]))</span>
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;&#39;</span><span class="p">)</span></div>
2016-10-04 00:31:52 +00:00
2016-10-05 16:16:06 +00:00
2016-10-04 00:31:52 +00:00
<div class="viewcode-block" id="print_help"><a class="viewcode-back" href="../../git_lint.html#git_lint.reporters.print_help">[docs]</a><span class="k">def</span> <span class="nf">print_help</span><span class="p">(</span><span class="n">options</span><span class="p">,</span> <span class="n">name</span><span class="p">):</span>
2016-10-05 16:16:06 +00:00
<span class="nb">print</span><span class="p">(</span><span class="n">_</span><span class="p">(</span><span class="s1">&#39;Usage: </span><span class="si">{}</span><span class="s1"> [options] [filenames]&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">name</span><span class="p">))</span>
2016-10-04 00:31:52 +00:00
<span class="k">for</span> <span class="n">item</span> <span class="ow">in</span> <span class="n">options</span><span class="p">:</span>
2017-08-02 17:49:29 +00:00
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39; </span><span class="si">{:&lt;2}</span><span class="s1"> --</span><span class="si">{:&lt;12}</span><span class="s1"> </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">((</span><span class="n">item</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="ow">and</span> <span class="p">(</span><span class="s1">&#39;-&#39;</span> <span class="o">+</span> <span class="n">item</span><span class="p">[</span><span class="mi">0</span><span class="p">]))</span> <span class="ow">or</span> <span class="s1">&#39;&#39;</span><span class="p">,</span> <span class="n">item</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span> <span class="n">item</span><span class="p">[</span><span class="mi">3</span><span class="p">]))</span></div>
2016-10-05 16:16:06 +00:00
2016-10-04 00:31:52 +00:00
<div class="viewcode-block" id="print_version"><a class="viewcode-back" href="../../git_lint.html#git_lint.reporters.print_version">[docs]</a><span class="k">def</span> <span class="nf">print_version</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">version</span><span class="p">):</span>
2016-10-05 16:16:06 +00:00
<span class="nb">print</span><span class="p">(</span><span class="n">_</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">{}</span><span class="s1"> </span><span class="si">{}</span><span class="s1"> Copyright (c) 2009, 2016 Kennth M. &quot;Elf&quot; Sternberg&#39;</span><span class="p">)</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">name</span><span class="p">,</span> <span class="n">version</span><span class="p">))</span></div>
2016-10-04 00:31:52 +00:00
<div class="viewcode-block" id="print_linters"><a class="viewcode-back" href="../../git_lint.html#git_lint.reporters.print_linters">[docs]</a><span class="k">def</span> <span class="nf">print_linters</span><span class="p">(</span><span class="n">config</span><span class="p">,</span> <span class="n">broken_linter_names</span><span class="p">):</span>
2016-10-05 16:16:06 +00:00
<span class="nb">print</span><span class="p">(</span><span class="n">_</span><span class="p">(</span><span class="s1">&#39;Currently supported linters:&#39;</span><span class="p">))</span>
2016-10-04 00:31:52 +00:00
<span class="k">for</span> <span class="n">linter</span> <span class="ow">in</span> <span class="n">config</span><span class="p">:</span>
2016-10-05 16:16:06 +00:00
<span class="nb">print</span><span class="p">(</span><span class="s1">&#39;</span><span class="si">{:&lt;14}</span><span class="s1"> </span><span class="si">{}</span><span class="s1">&#39;</span><span class="o">.</span><span class="n">format</span><span class="p">(</span><span class="n">linter</span><span class="o">.</span><span class="n">name</span><span class="p">,</span>
2016-10-04 00:31:52 +00:00
<span class="p">((</span><span class="n">linter</span><span class="o">.</span><span class="n">name</span> <span class="ow">in</span> <span class="n">broken_linter_names</span> <span class="ow">and</span>
2016-10-05 16:16:06 +00:00
<span class="n">_</span><span class="p">(</span><span class="s1">&#39;(WARNING: executable not found)&#39;</span><span class="p">)</span> <span class="ow">or</span>
<span class="n">linter</span><span class="o">.</span><span class="n">linter</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s1">&#39;comment&#39;</span><span class="p">,</span> <span class="s1">&#39;&#39;</span><span class="p">)))))</span></div>
</pre></div>
2016-10-04 00:31:52 +00:00
</div>
</div>
</div>
2016-10-05 16:16:06 +00:00
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
2016-10-06 15:32:58 +00:00
<div class="sphinxsidebarwrapper"><div class="relations">
<h3>Related Topics</h3>
<ul>
<li><a href="../../index.html">Documentation overview</a><ul>
<li><a href="../index.html">Module code</a><ul>
</ul></li>
</ul></li>
</ul>
</div>
2016-10-05 16:16:06 +00:00
<div id="searchbox" style="display: none" role="search">
2016-10-04 00:31:52 +00:00
<h3>Quick search</h3>
<form class="search" action="../../search.html" method="get">
2016-10-05 16:16:06 +00:00
<div><input type="text" name="q" /></div>
<div><input type="submit" value="Go" /></div>
2016-10-04 00:31:52 +00:00
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
</div>
</div>
<div class="clearer"></div>
</div>
2016-10-06 15:32:58 +00:00
<div class="footer">
&copy;2016, Kenneth M. "Elf" Sternberg.
|
Powered by <a href="http://sphinx-doc.org/">Sphinx 1.4.6</a>
&amp; <a href="https://github.com/bitprophet/alabaster">Alabaster 0.7.9</a>
2016-10-04 00:31:52 +00:00
</div>
2016-10-06 15:32:58 +00:00
2016-10-04 00:31:52 +00:00
</body>
</html>