<?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>Deadpan Sincerity &#187; python</title>
	<atom:link href="http://blog.deadpansincerity.com/tag/python/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.deadpansincerity.com</link>
	<description>a weblog by david miller</description>
	<lastBuildDate>Fri, 09 Dec 2011 12:03:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Mercurial Hook to ensure issue references in Trac/Redmine</title>
		<link>http://blog.deadpansincerity.com/2011/06/mercurial-hook-to-ensure-issue-references-in-tracredmine/</link>
		<comments>http://blog.deadpansincerity.com/2011/06/mercurial-hook-to-ensure-issue-references-in-tracredmine/#comments</comments>
		<pubDate>Sat, 04 Jun 2011 10:41:07 +0000</pubDate>
		<dc:creator>david miller</dc:creator>
				<category><![CDATA[something's burning]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[wishful thinking]]></category>
		<category><![CDATA[bugs]]></category>
		<category><![CDATA[hg]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[mercurial]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[redmine]]></category>
		<category><![CDATA[trac]]></category>

		<guid isPermaLink="false">http://blog.deadpansincerity.com/?p=400</guid>
		<description><![CDATA[As much as I love the version control integration of the bug trackers I use (Redmine and Trac) I find myself forgetting to include the issue reference more often than I&#8217;d like to admit. Add to this the merry dance you have to go through to ammend commit messages in Mercurial and things get even [...]]]></description>
			<content:encoded><![CDATA[<p>As much as I love the version control integration of the bug trackers I use (<a href="http://www.redmine.org/">Redmine</a> and <a href="http://trac.edgewall.org/">Trac</a>) I find myself forgetting to include the issue reference more often than I&#8217;d like to admit.</p>
<p>Add to this the <a href="http://stackoverflow.com/questions/623052/how-to-edit-incorrect-commit-message-in-mercurial">merry dance</a> you have to go through to ammend commit messages in <a href="http://mercurial.selenic.com/">Mercurial</a> and things get even worse. (Oh how I&#8217;d love for hg to implement something similar to <a href="http://www.kernel.org/pub/software/scm/git/docs/git-commit.html">git&#8217;s</a> $ git commit &#8211;amend )</p>
<p>Hence, a Pre-transaction-commit hook for hg that will ask me if I&#8217;m sure I want to commit without an issue number. If want to commit anyway, it&#8217;s just two extra keystrokes, and saves a whole lot of rollback/apply nonsense.</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #808080; font-style: italic;">#!/usr/bin/env python</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">os</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">re</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">subprocess</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
<span style="color: #dc143c;">cmd</span> = <span style="color: #dc143c;">subprocess</span>.<span style="color: black;">Popen</span><span style="color: black;">&#40;</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'hg'</span>, <span style="color: #483d8b;">'log'</span>, <span style="color: #483d8b;">'-vr'</span>, <span style="color: #dc143c;">os</span>.<span style="color: black;">environ</span><span style="color: black;">&#91;</span><span style="color: #483d8b;">'HG_NODE'</span><span style="color: black;">&#93;</span><span style="color: black;">&#93;</span>,
                       stdout=<span style="color: #dc143c;">subprocess</span>.<span style="color: black;">PIPE</span><span style="color: black;">&#41;</span>.<span style="color: black;">communicate</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">0</span><span style="color: black;">&#93;</span>
msg = <span style="color: #dc143c;">cmd</span>.<span style="color: black;">split</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'description:'</span><span style="color: black;">&#41;</span><span style="color: black;">&#91;</span><span style="color: #ff4500;">1</span><span style="color: black;">&#93;</span>
issue_regexes = <span style="color: black;">&#91;</span>
    <span style="color: #808080; font-style: italic;"># Trac</span>
    r<span style="color: #483d8b;">'#<span style="color: #000099; font-weight: bold;">\d</span>+'</span>,
    <span style="color: #808080; font-style: italic;"># Redmine</span>
    r<span style="color: #483d8b;">'fixes #<span style="color: #000099; font-weight: bold;">\d</span>+'</span>,
    r<span style="color: #483d8b;">'refs #<span style="color: #000099; font-weight: bold;">\d</span>+'</span>,
    <span style="color: black;">&#93;</span>
<span style="color: #ff7700;font-weight:bold;">if</span> <span style="color: #ff7700;font-weight:bold;">not</span> <span style="color: #008000;">filter</span><span style="color: black;">&#40;</span><span style="color: #ff7700;font-weight:bold;">lambda</span> x: <span style="color: #dc143c;">re</span>.<span style="color: black;">search</span><span style="color: black;">&#40;</span>x, msg<span style="color: black;">&#41;</span>, issue_regexes<span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;No issue ref or fix... message is:&quot;</span>
    <span style="color: #ff7700;font-weight:bold;">print</span> msg
    <span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;Continue? [y/n] &quot;</span><span style="color: black;">&#41;</span>
    resp = <span style="color: #008000;">raw_input</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>.<span style="color: black;">lower</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
    <span style="color: #ff7700;font-weight:bold;">if</span> resp == <span style="color: #483d8b;">'n'</span>:
        <span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: #ff4500;">9</span><span style="color: black;">&#41;</span></pre></div></div>

<p>Then add the following to your project&#8217;s .hg/hgrc:</p>

<div class="wp_syntax"><div class="code"><pre class="javascript" style="font-family:monospace;"><span style="color: #009900;">&#91;</span>hooks<span style="color: #009900;">&#93;</span>
pretxncommit <span style="color: #339933;">=</span> path<span style="color: #339933;">/</span>to<span style="color: #339933;">/</span>your<span style="color: #339933;">/</span>pretxncommit.<span style="color: #660066;">py</span></pre></div></div>

<p>Saving you endless embarrassment:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">davidmiller<span style="color: #000000; font-weight: bold;">@</span>pascal:~<span style="color: #000000; font-weight: bold;">/</span>src<span style="color: #000000; font-weight: bold;">/</span>buggy_repo$ hg commit <span style="color: #660033;">-m</span> <span style="color: #ff0000;">&quot;A context-less void&quot;</span>
No issue ref or fix... message is:
&nbsp;
A context-less void
&nbsp;
&nbsp;
&nbsp;
Continue? <span style="color: #7a0874; font-weight: bold;">&#91;</span>y<span style="color: #000000; font-weight: bold;">/</span>n<span style="color: #7a0874; font-weight: bold;">&#93;</span> n
transaction abort<span style="color: #000000; font-weight: bold;">!</span>
rollback completed
abort: pretxncommit hook exited with status <span style="color: #000000;">9</span></pre></div></div>

<p>Love regards etc</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.deadpansincerity.com/2011/06/mercurial-hook-to-ensure-issue-references-in-tracredmine/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Announcing Pony Mode &#8211; a Django editing mode for Emacs</title>
		<link>http://blog.deadpansincerity.com/2011/05/announcing-pony-mode-a-django-editing-mode-for-emacs/</link>
		<comments>http://blog.deadpansincerity.com/2011/05/announcing-pony-mode-a-django-editing-mode-for-emacs/#comments</comments>
		<pubDate>Sat, 28 May 2011 11:33:10 +0000</pubDate>
		<dc:creator>david miller</dc:creator>
				<category><![CDATA[favourite things]]></category>
		<category><![CDATA[technical]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[emacs]]></category>
		<category><![CDATA[lisp]]></category>
		<category><![CDATA[projects]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://blog.deadpansincerity.com/?p=448</guid>
		<description><![CDATA[I&#8217;m pleased to announce the first beta &#8216;release&#8217; of Pony Mode, a minor mode for working on Django projects in Emacs. This mode provides integration with the django management commands within emacs, as well as test integration, a minor-mode with syntax highlighting for editing templates, will determine whether you are using Fabric or Buildout, as [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m pleased to announce the first beta &#8216;release&#8217; of <a href="https://github.com/davidmiller/pony-mode">Pony Mode</a>, a minor mode for working on <a href="www.djangoproject.com">Django</a> projects in <a href="http://www.gnu.org/software/emacs/">Emacs</a>.</p>
<p>This mode provides integration with the django management commands within emacs, as well as test integration, a minor-mode with syntax highlighting for editing templates, will determine whether you are using <a href="http://fabfile.org">Fabric</a> or <a href="http://www.buildout.org/">Buildout</a>, as well as much more!</p>
<p>This mode is under active development, so please file any bugs at the <a href="https://github.com/davidmiller/pony-mode/issues">Github page</a>, and feel free to provide any feedback/feature requests etc.</p>
<p>Current features include:</p>
<ul>
<li>Run dev server in an emacs buffer [C-c C-p r]</li>
<li>* Checks to see if runserver_plus is available</li>
<li>* If not uses in-built runserver</li>
<li>Jump to current project in browser (start server if required) [C-c C-p b]</li>
<li>Run test case at point in buffer [C-c C-p t]</li>
<li>Run tests for current app in buffer [C-c C-p t]</li>
<li>Run Syncdb on current project</li>
<li>Management commands for current project in interactive buffer</li>
<li>South integration &#8211; run south convert, schemamigration, migrate</li>
<li>Run django shell in buffer [C-c C-p s]</li>
<li>* Checks for shell_plus</li>
<li>* If not defaults to shell</li>
<li>Fabric integration [C-c C-p f]</li>
<li>Startapp and dumpdata on current project within emacs</li>
<li>Database integration with Emacs sql-mode interactive buffer [C-c C-c d</li>
<li>Django Template minor mode with syntax highlighting for django</li>
<p> template tags</p>
<li>Snippet collection for django</li>
<li>generate tags table for project</li>
<li>run manage commands in interactive buffer</li>
<li>Buildout integration</li>
<li>Generate TAGS table for project to enable quick navigation</li>
<li>Jump to template at point or from editing view [C-c C-p g t]</li>
</ul>
<p>Grab it while it&#8217;s hot!</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.deadpansincerity.com/2011/05/announcing-pony-mode-a-django-editing-mode-for-emacs/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>coverage command for separate test runner in django</title>
		<link>http://blog.deadpansincerity.com/2011/02/coverage-command-for-seperate-test-runner-in-django/</link>
		<comments>http://blog.deadpansincerity.com/2011/02/coverage-command-for-seperate-test-runner-in-django/#comments</comments>
		<pubDate>Fri, 18 Feb 2011 08:11:05 +0000</pubDate>
		<dc:creator>david miller</dc:creator>
				<category><![CDATA[technical]]></category>
		<category><![CDATA[commandline]]></category>
		<category><![CDATA[continuous integration]]></category>
		<category><![CDATA[coverage]]></category>
		<category><![CDATA[django]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[tdd]]></category>
		<category><![CDATA[unittesting]]></category>

		<guid isPermaLink="false">http://blog.deadpansincerity.com/?p=402</guid>
		<description><![CDATA[I&#8217;m a long-time fan of django-test-coverage. It takes Ned Batchelor&#8216;s coverage.py and wraps it in a django test runner for you, which is great. Particularly with large test suites though, the speed increase is too large to go unnoticed (In my projects normally in the region of 150% YMMV). And your tests can never be [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m a long-time fan of <a href="http://pypi.python.org/pypi/django-test-coverage/0.1">django-test-coverage</a>. It takes <a href="http://nedbatchelder.com/">Ned Batchelor</a>&#8216;s <a href="http://nedbatchelder.com/code/coverage/">coverage.py</a> and wraps it in a django test runner for you, which is great.</p>
<p>Particularly with large test suites though, the speed increase is too large to go unnoticed (In my projects normally in the region of 150% YMMV).</p>
<p>And your tests can <em>never</em> be too fast right?</p>
<p>One solution to this is to only use the coverage test runner in a seperate management command. That way you always have access to the stats, but your &#8216;regular&#8217; test run doesn&#8217;t take the performance hit. </p>
<p>Not only that, but you can also run the coverage stats on your continuous integration server once every few hours for a consistently recent picture of how your coverage is looking.</p>
<p>The code itself is nothing dead simple, just <a href="http://docs.djangoproject.com/en/dev/howto/custom-management-commands/">subclasses the django BaseCommand</a> class and then fetches the right test runner:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #483d8b;">&quot;&quot;&quot;
Run our tests with coverage turned on
&quot;&quot;&quot;</span>
<span style="color: #ff7700;font-weight:bold;">import</span> <span style="color: #dc143c;">sys</span>
&nbsp;
<span style="color: #ff7700;font-weight:bold;">from</span> django.<span style="color: black;">core</span>.<span style="color: black;">management</span>.<span style="color: black;">base</span> <span style="color: #ff7700;font-weight:bold;">import</span> BaseCommand
&nbsp;
<span style="color: #ff7700;font-weight:bold;">class</span> Command<span style="color: black;">&#40;</span>BaseCommand<span style="color: black;">&#41;</span>:
    <span style="color: #483d8b;">&quot;&quot;&quot;
    We totally want to get coverage details, but that's so slow!
    &quot;&quot;&quot;</span>
    option_list = BaseCommand.<span style="color: black;">option_list</span>
    <span style="color: #008000;">help</span> = <span style="color: #483d8b;">&quot;Run our tests with coverage turned on&quot;</span>
    args = <span style="color: #483d8b;">&quot;[appname ...]&quot;</span>
&nbsp;
    requires_model_validation = <span style="color: #008000;">False</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> handle<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, <span style="color: #66cc66;">*</span>tests, <span style="color: #66cc66;">**</span>options<span style="color: black;">&#41;</span>:
        <span style="color: #483d8b;">&quot;&quot;&quot;
        Actually do the test run
&nbsp;
        Arguments:
        - `*tests`: test labels
        - `**options`: passed opts
        &quot;&quot;&quot;</span>
        verbosity = <span style="color: #008000;">int</span><span style="color: black;">&#40;</span>options.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'verbosity'</span>, <span style="color: #ff4500;">1</span><span style="color: black;">&#41;</span><span style="color: black;">&#41;</span>
        interactive = options.<span style="color: black;">get</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">'interactive'</span>, <span style="color: #008000;">True</span><span style="color: black;">&#41;</span>
        mod = <span style="color: #008000;">__import__</span><span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;django-test-coverage.runner&quot;</span><span style="color: black;">&#41;</span>
        failures = mod.<span style="color: black;">runner</span>.<span style="color: black;">run_tests</span><span style="color: black;">&#40;</span>tests, verbosity=verbosity,
                                        interactive=interactive<span style="color: black;">&#41;</span>
        <span style="color: #ff7700;font-weight:bold;">if</span> failures:
            <span style="color: #dc143c;">sys</span>.<span style="color: black;">exit</span><span style="color: black;">&#40;</span><span style="color: #008000;">bool</span><span style="color: black;">&#40;</span>failures<span style="color: black;">&#41;</span><span style="color: black;">&#41;</span></pre></div></div>

<p>This then needs to live somewhere in an a management dir of one of your installed apps&#8230;</p>
<blockquote><p>yourproject/yourapp/management/commands/coverage.py</p></blockquote>
<p>&#8230;and you&#8217;ll need to </p>
<blockquote><p>$ <a href="http://pypi.python.org/pypi/setuptools">easy_install</a> django-test-coverage</p></blockquote>
<p>So that the test runner is there in your environment.</p>
<p>Grab the <a href="https://github.com/davidmiller/Deadpansincerity-Code-Samples/raw/master/django/commands/coverage.py">raw file</a> here.</p>
<p>Alternatively you <em>could</em> <a href="http://ericholscher.com/blog/2009/nov/13/django-testing-code-coverage/">patch django itself</a>. Until they merge those changes though, I&#8217;ll be sticking with the seperate command.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.deadpansincerity.com/2011/02/coverage-command-for-seperate-test-runner-in-django/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>howto: Enable Last.fm integration for Listen Music Player in Xubuntu/Xfce</title>
		<link>http://blog.deadpansincerity.com/2008/12/howto-enable-lastfm-integration-for-listen-music-player-in-xubuntuxfce/</link>
		<comments>http://blog.deadpansincerity.com/2008/12/howto-enable-lastfm-integration-for-listen-music-player-in-xubuntuxfce/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 15:53:11 +0000</pubDate>
		<dc:creator>david miller</dc:creator>
				<category><![CDATA[technical]]></category>
		<category><![CDATA[howto]]></category>
		<category><![CDATA[last.fm]]></category>
		<category><![CDATA[linux]]></category>
		<category><![CDATA[Listen]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[scrobble]]></category>
		<category><![CDATA[xfce]]></category>
		<category><![CDATA[xubuntu]]></category>

		<guid isPermaLink="false">http://blog.deadpansincerity.com/?p=191</guid>
		<description><![CDATA[Notice: This is a technical post. If you don&#8217;t have this problem, you probably want to skip this one. I have just started using the Listen music player, which is a very nice lightweight little python program that comes shipped with xubuntu. As of the time of writing the version included in the xubuntu-desktop package [...]]]></description>
			<content:encoded><![CDATA[<p>Notice: This is a technical post. If you don&#8217;t have this problem, you probably want to skip this one.</p>
<p>I have just started using the <a href="http://www.listen-project.org/">Listen</a> music player, which is a very nice lightweight little <a href="http://www.python.org">python</a> program that comes shipped with <a href="http://www.xubuntu.org">xubuntu</a>. As of the time of writing the version included in the xubuntu-desktop package has not been updated so that it integrates with <a href="http://www.last.fm">last.fm</a> properly. </p>
<p>The following fixes the problem, and will happily allow you to broadcast your terrible taste to the rest of the world without sitting you down &#038; asking why you really want to do so. </p>
<p><code><small><br />
wget http://www.listen-project.org/raw-attachment/ticket/826/audioscrobbler_manager.py</p>
<p>sudo cp audioscrobbler_manager.py /usr/lib/listen/</p>
<p>rm audioscrobbler_manager.py<br />
</small></code></p>
<p>You can see this in action on <a href="http://www.last.fm/user/thatdavidmiller">my last.fm profile</a> should you have the inclination.</p>
<p>Love regards etc</p>
<p>Notice: The next post will almost certainly be of a less niche nature. Look forward to it. Or something.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.deadpansincerity.com/2008/12/howto-enable-lastfm-integration-for-listen-music-player-in-xubuntuxfce/feed/</wfw:commentRss>
		<slash:comments>28</slash:comments>
		</item>
	</channel>
</rss>

