<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Mike&#039;s Blabberings &#187; style</title>
	<atom:link href="http://www.mike-griffith.com/blog/tag/style/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.mike-griffith.com/blog</link>
	<description>on software, testing, and the web.</description>
	<lastBuildDate>Wed, 11 Aug 2010 20:41:01 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Checking for pythondoc comments with pylint</title>
		<link>http://www.mike-griffith.com/blog/2008/09/checking-for-pythondoc-comments-with-pylint/</link>
		<comments>http://www.mike-griffith.com/blog/2008/09/checking-for-pythondoc-comments-with-pylint/#comments</comments>
		<pubDate>Mon, 22 Sep 2008 18:56:05 +0000</pubDate>
		<dc:creator>Mike</dc:creator>
				<category><![CDATA[software development]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[style]]></category>

		<guid isPermaLink="false">http://blog.rideshootlive.com/?p=78</guid>
		<description><![CDATA[When using automated code-style checkers, such as pylint, we often want to check that our documentation meets certain standards in addition to the code itself.   If you want to stray from PEP8 and use PythonDoc aka pydoc instead of the traditional docstring-style comments, you might struggle for a moment to find something to [...]]]></description>
			<content:encoded><![CDATA[<p>When using automated code-style checkers, such as <a href="http://www.logilab.org/857">pylint</a>, we often want to check that our documentation meets certain standards in addition to the code itself.   If you want to stray from PEP8 and use <a href="http://effbot.org/zone/pythondoc.htm">PythonDoc</a> aka pydoc instead of the traditional docstring-style comments, you might struggle for a moment to find something to help enforce your standards.</p>
<p>Most pylint checkers use the abstract syntax tree to evaluate code style, and unfortunately, the AST skips over comments (although it does grab docstrings).   So out of the box, you can check to make sure there are docstring-comments, but not that there are PythonDocs attached to a module.  For reference, a pydoc-ified module looks something like:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">##</span>
<span style="color: #808080; font-style: italic;"># Class description</span>
<span style="color: #ff7700;font-weight:bold;">class</span> MyClass<span style="color: black;">&#40;</span><span style="color: #008000;">object</span><span style="color: black;">&#41;</span>:
    <span style="color: #808080; font-style: italic;">##</span>
    <span style="color: #808080; font-style: italic;"># Method description</span>
    <span style="color: #808080; font-style: italic;"># @param p1</span>
    <span style="color: #ff7700;font-weight:bold;">def</span> do_me<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, p1<span style="color: black;">&#41;</span>:
        <span style="color: #ff7700;font-weight:bold;">pass</span></pre></td></tr></table></div>

<p>Because all the pydoc markup is hidden from the AST, it didn’t seem like we’d be able to check for it.  Turns out, it doesn’t need to be in the AST for us to utilize pylint’s plugin architecture.  There are actually a few checkers that by default work on the file itself.</p>
<p>With this knowledge, we can write a checker that extends pylint.checkers.BaseRawChecker and utilize pythondoc’s API to parse the file and verify that the returned ElementTree contains what we need.</p>
<p>You can <a href="/code/pylint_pydoc_checker.py">download the implementation in pylint_pydoc_checker.py</a>.  This will parse the file and make sure that there is at least 1 top-level pythondoc description.</p>
<p>To activate the plugin, add this line to your .pylintrc</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
</pre></td><td class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;"># List of plugins (as comma separated values of python modules names) to load,</span>
<span style="color: #666666; font-style: italic;"># usually to register additional checkers.</span>
<span style="color: #666666; font-style: italic;"># You can put the pylint_pydoc_checker in a modularized namespace if you wish</span>
load-plugins=pylint_pydoc_checker
&nbsp;
<span style="color: #666666; font-style: italic;"># Disable the message(s) with the given id(s).</span>
<span style="color: #666666; font-style: italic;"># Don't show the docstring warning (C0111), since we're checking for pydoc comments</span>
disable-msg=C0111</pre></td></tr></table></div>

<p>This does require the 2.1b6 version of pythondoc, available on <a href="http://effbot.org/zone/pythondoc.htm">effbot</a>.</p>
<p><strong>Update 2008.10.28:</strong> Modified .pylintrc setup.  Thanks Larry Kincaid for pointing out the issues!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.mike-griffith.com/blog/2008/09/checking-for-pythondoc-comments-with-pylint/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
