172 lines
18 KiB
HTML
172 lines
18 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/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: '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>
|
||
|
<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><a href="../../index.html">Git Lint 0.0.4 documentation</a> »</li>
|
||
|
<li><a href="../index.html" accesskey="U">Module code</a> »</li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
|
||
|
<div class="document">
|
||
|
<div class="documentwrapper">
|
||
|
<div class="bodywrapper">
|
||
|
<div class="body">
|
||
|
|
||
|
<h1>Source code for git_lint.reporters</h1><div class="highlight"><pre>
|
||
|
<span class="kn">from</span> <span class="nn">__future__</span> <span class="kn">import</span> <span class="n">print_function</span>
|
||
|
<span class="kn">from</span> <span class="nn">.git_lint</span> <span class="kn">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="nb">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="s">'/'</span><span class="p">,</span> <span class="s">''</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span> <span class="k">for</span> <span class="nb">file</span> <span class="ow">in</span> <span class="n">files</span><span class="p">]</span>
|
||
|
|
||
|
|
||
|
<span class="c"># ICK. Mutation, references, and hidden assignment.</span></div>
|
||
|
<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="s">'bylinter'</span><span class="p">:</span> <span class="bp">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="s">'Linter: {}'</span><span class="p">)</span>
|
||
|
<span class="k">if</span> <span class="s">'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="s">'Filename: {}'</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="nb">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="k">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="k">print</span><span class="p">(</span><span class="s">'</span><span class="se">\n</span><span class="s">'</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="k">print</span><span class="p">(</span><span class="s">''</span><span class="p">)</span>
|
||
|
<span class="k">print</span> <span class="p">(</span><span class="s">''</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="s">'verbose'</span> <span class="ow">in</span> <span class="n">options</span><span class="p">)):</span>
|
||
|
<span class="k">print</span><span class="p">(</span><span class="n">_</span><span class="p">(</span><span class="s">'These linters could not be run:'</span><span class="p">),</span> <span class="s">','</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="k">print</span><span class="p">(</span><span class="n">_</span><span class="p">(</span><span class="s">'Files not linted:'</span><span class="p">))</span>
|
||
|
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="se">\n</span><span class="s">'</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s">' {}'</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="k">print</span><span class="p">(</span><span class="s">''</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="s">'verbose'</span> <span class="ow">in</span> <span class="n">options</span><span class="p">):</span>
|
||
|
<span class="k">print</span><span class="p">(</span><span class="n">_</span><span class="p">(</span><span class="s">'No recognizeable linters for:'</span><span class="p">))</span>
|
||
|
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="se">\n</span><span class="s">'</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s">' {}'</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="k">print</span><span class="p">(</span><span class="s">''</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="k">print</span><span class="p">(</span><span class="n">_</span><span class="p">(</span><span class="s">'Files not be found:'</span><span class="p">))</span>
|
||
|
<span class="k">print</span><span class="p">(</span><span class="s">'</span><span class="se">\n</span><span class="s">'</span><span class="o">.</span><span class="n">join</span><span class="p">([</span><span class="s">' {}'</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="k">print</span><span class="p">(</span><span class="s">''</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="k">print</span><span class="p">(</span><span class="n">_</span><span class="p">(</span><span class="s">'Usage: {} [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="k">print</span><span class="p">(</span><span class="s">' -{:<1} --{:<12} {}'</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="k">print</span><span class="p">(</span><span class="n">_</span><span class="p">(</span><span class="s">'{} {} 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="k">print</span><span class="p">(</span><span class="n">_</span><span class="p">(</span><span class="s">'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="k">print</span><span class="p">(</span><span class="s">'{:<14} {}'</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="s">'(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="s">'comment'</span><span class="p">,</span> <span class="s">''</span><span class="p">)))))</span>
|
||
|
</pre></div></div>
|
||
|
|
||
|
</div>
|
||
|
</div>
|
||
|
</div>
|
||
|
<div class="sphinxsidebar">
|
||
|
<div class="sphinxsidebarwrapper">
|
||
|
<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><a href="../../index.html">Git Lint 0.0.4 documentation</a> »</li>
|
||
|
<li><a href="../index.html" >Module code</a> »</li>
|
||
|
</ul>
|
||
|
</div>
|
||
|
<div class="footer">
|
||
|
© Copyright 2016, Kenneth M. "Elf" Sternberg.
|
||
|
Created using <a href="http://sphinx-doc.org/">Sphinx</a> 1.2.2.
|
||
|
</div>
|
||
|
</body>
|
||
|
</html>
|