171 lines
19 KiB
HTML
171 lines
19 KiB
HTML
<!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>git_lint.reporters — Git Lint 0.0.4 documentation</title>
|
|
|
|
<link rel="stylesheet" href="../../_static/classic.css" type="text/css" />
|
|
<link rel="stylesheet" href="../../_static/pygments.css" type="text/css" />
|
|
|
|
<script type="text/javascript">
|
|
var DOCUMENTATION_OPTIONS = {
|
|
URL_ROOT: '../../',
|
|
VERSION: '0.0.4',
|
|
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="Git Lint 0.0.4 documentation" href="../../index.html" />
|
|
<link rel="up" title="Module code" href="../index.html" />
|
|
</head>
|
|
<body role="document">
|
|
<div class="related" role="navigation" aria-label="related navigation">
|
|
<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="nav-item nav-item-0"><a href="../../index.html">Git Lint 0.0.4 documentation</a> »</li>
|
|
<li class="nav-item nav-item-1"><a href="../index.html" accesskey="U">Module code</a> »</li>
|
|
</ul>
|
|
</div>
|
|
|
|
<div class="document">
|
|
<div class="documentwrapper">
|
|
<div class="bodywrapper">
|
|
<div class="body" role="main">
|
|
|
|
<h1>Source code for git_lint.reporters</h1><div class="highlight"><pre>
|
|
<span></span><span class="kn">from</span> <span class="nn">__future__</span> <span class="k">import</span> <span class="n">print_function</span>
|
|
<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>
|
|
<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>
|
|
|
|
|
|
<div class="viewcode-block" id="base_file_cleaner"><a class="viewcode-back" href="../../git_lint.html#git_lint.reporters.base_file_cleaner">[docs]</a><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">'/'</span><span class="p">,</span> <span class="s1">''</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></div>
|
|
|
|
|
|
<span class="c1"># ICK. Mutation, references, and hidden assignment.</span>
|
|
<div class="viewcode-block" id="group_by"><a class="viewcode-back" href="../../git_lint.html#git_lint.reporters.group_by">[docs]</a><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></div>
|
|
|
|
|
|
<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">'bylinter'</span><span class="p">:</span> <span class="kc">True</span><span class="p">}):</span>
|
|
<span class="n">sort_position</span> <span class="o">=</span> <span class="mi">1</span>
|
|
<span class="n">grouping</span> <span class="o">=</span> <span class="n">_</span><span class="p">(</span><span class="s1">'Linter: </span><span class="si">{}</span><span class="s1">'</span><span class="p">)</span>
|
|
<span class="k">if</span> <span class="s1">'byfile'</span> <span class="ow">in</span> <span class="n">options</span><span class="p">:</span>
|
|
<span class="n">sort_position</span> <span class="o">=</span> <span class="mi">0</span>
|
|
<span class="n">grouping</span> <span class="o">=</span> <span class="n">_</span><span class="p">(</span><span class="s1">'Filename: </span><span class="si">{}</span><span class="s1">'</span><span class="p">)</span>
|
|
<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>
|
|
<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>
|
|
<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>
|
|
<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>
|
|
<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>
|
|
<span class="nb">print</span><span class="p">(</span><span class="s1">'</span><span class="se">\n</span><span class="s1">'</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">''</span><span class="p">)</span>
|
|
<span class="nb">print</span> <span class="p">(</span><span class="s1">''</span><span class="p">)</span>
|
|
|
|
<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">'verbose'</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">'These linters could not be run:'</span><span class="p">),</span> <span class="s1">','</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>
|
|
<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>
|
|
<span class="nb">print</span><span class="p">(</span><span class="n">_</span><span class="p">(</span><span class="s1">'Files not linted:'</span><span class="p">))</span>
|
|
<span class="nb">print</span><span class="p">(</span><span class="s1">'</span><span class="se">\n</span><span class="s1">'</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s1">' </span><span class="si">{}</span><span class="s1">'</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">''</span><span class="p">)</span>
|
|
|
|
<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">'verbose'</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">'No recognizeable linters for:'</span><span class="p">))</span>
|
|
<span class="nb">print</span><span class="p">(</span><span class="s1">'</span><span class="se">\n</span><span class="s1">'</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s1">' </span><span class="si">{}</span><span class="s1">'</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">''</span><span class="p">)</span>
|
|
|
|
<span class="k">if</span> <span class="nb">len</span><span class="p">(</span><span class="n">unfindable_filenames</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">'Files not be found:'</span><span class="p">))</span>
|
|
<span class="nb">print</span><span class="p">(</span><span class="s1">'</span><span class="se">\n</span><span class="s1">'</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s1">' </span><span class="si">{}</span><span class="s1">'</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">''</span><span class="p">)</span></div>
|
|
|
|
|
|
<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>
|
|
<span class="nb">print</span><span class="p">(</span><span class="n">_</span><span class="p">(</span><span class="s1">'Usage: </span><span class="si">{}</span><span class="s1"> [options] [filenames]'</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="k">for</span> <span class="n">item</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="s1">' -</span><span class="si">{:<1}</span><span class="s1"> --</span><span class="si">{:<12}</span><span class="s1"> </span><span class="si">{}</span><span class="s1">'</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="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>
|
|
|
|
|
|
<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>
|
|
<span class="nb">print</span><span class="p">(</span><span class="n">_</span><span class="p">(</span><span class="s1">'</span><span class="si">{}</span><span class="s1"> </span><span class="si">{}</span><span class="s1"> Copyright (c) 2009, 2016 Kennth M. "Elf" Sternberg'</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>
|
|
|
|
|
|
<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>
|
|
<span class="nb">print</span><span class="p">(</span><span class="n">_</span><span class="p">(</span><span class="s1">'Currently supported linters:'</span><span class="p">))</span>
|
|
<span class="k">for</span> <span class="n">linter</span> <span class="ow">in</span> <span class="n">config</span><span class="p">:</span>
|
|
<span class="nb">print</span><span class="p">(</span><span class="s1">'</span><span class="si">{:<14}</span><span class="s1"> </span><span class="si">{}</span><span class="s1">'</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>
|
|
<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>
|
|
<span class="n">_</span><span class="p">(</span><span class="s1">'(WARNING: executable not found)'</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">'comment'</span><span class="p">,</span> <span class="s1">''</span><span class="p">)))))</span></div>
|
|
|
|
|
|
</pre></div>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div class="sphinxsidebar" role="navigation" aria-label="main navigation">
|
|
<div class="sphinxsidebarwrapper">
|
|
<div id="searchbox" style="display: none" role="search">
|
|
<h3>Quick search</h3>
|
|
<form class="search" action="../../search.html" method="get">
|
|
<div><input type="text" name="q" /></div>
|
|
<div><input type="submit" value="Go" /></div>
|
|
<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>
|
|
<div class="related" role="navigation" aria-label="related navigation">
|
|
<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="nav-item nav-item-0"><a href="../../index.html">Git Lint 0.0.4 documentation</a> »</li>
|
|
<li class="nav-item nav-item-1"><a href="../index.html" >Module code</a> »</li>
|
|
</ul>
|
|
</div>
|
|
<div class="footer" role="contentinfo">
|
|
© Copyright 2016, Kenneth M. "Elf" Sternberg.
|
|
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.4.6.
|
|
</div>
|
|
</body>
|
|
</html> |