<?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>Milton Soares Filho &#187; python</title>
	<atom:link href="http://blog.msoares.pro.br/tags/python/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.msoares.pro.br</link>
	<description>Random rants and SW developers' stuff</description>
	<lastBuildDate>Mon, 08 Aug 2011 16:02:28 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Python-Debian Packaging for Maemo</title>
		<link>http://blog.msoares.pro.br/archives/python-debian-packaging-for-maemo</link>
		<comments>http://blog.msoares.pro.br/archives/python-debian-packaging-for-maemo#comments</comments>
		<pubDate>Tue, 28 Apr 2009 23:23:05 +0000</pubDate>
		<dc:creator>milton</dc:creator>
				<category><![CDATA[Planet INdT]]></category>
		<category><![CDATA[CDBS]]></category>
		<category><![CDATA[debian]]></category>
		<category><![CDATA[devel]]></category>
		<category><![CDATA[Maemo]]></category>
		<category><![CDATA[Make]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://msoares.dreamhosters.com/?p=41</guid>
		<description><![CDATA[Packaging a software component made using python to a Maemo device could be easier, if CDBS cared about hand-held devices and their limitations. Knowing that using setup.py was the Right Way of Doing It&#8482; for python applications I tried to push myself into making CDBS work together, but not without a little harassment. First of [...]]]></description>
			<content:encoded><![CDATA[<p>Packaging a software component made using python to a <a href="http://maemo.org/">Maemo</a> device could be easier, if <a href="http://build-common.alioth.debian.org/cdbs-doc.html"><span class="caps">CDBS</span></a> cared about hand-held devices and their limitations.</p>

<p>Knowing that using <strong>setup.py</strong> was the <em>Right Way of Doing It</em>&trade; for python applications I tried to push myself into making <span class="caps">CDBS </span>work together, but not without a little harassment.</p>

<p>First of all, such scope-limited distributions tend to gather components in customized places as to promote integration between them or just in sake of a plain different organization. This difficulty can be overcome by using <code>pycentral</code> and including the following line at <code>debian/rules</code> file.<br />
<pre><code>export DH_PYCENTRAL=nomove</code></pre><br />
Just as the manpage says, this will prevent the build-system from moving the files from the selected install prefix to a central place (like <code>/usr/share/pycentral</code>).</p>

<p>Secondly, because of limited storage capacity and speed-up necessities, usually python components install just their <code>.pyo</code> files. This requirement made me struggle trough <span class="caps">CDBS&#8217; </span><strong>python-distutils.mk</strong> source code in hope for a simple fix. The answer I&#8217;ve found was to overrule the python-install target with the following commands (look <a href="http://blog.msoares.pro.br/wp-content/uploads/2009/04/python-distutils.diff">here</a> for the diff).<br />
<pre><code>define FIXUP_DIST
    -find $(DEB_DESTDIR) -name '*.py' -exec rm -f {} \;
    -find $(DEB_DESTDIR) -name '*.pyc' -exec rm -f {} \;
    -find $(DEB_DESTDIR) -name '*.egg-info' -type d -exec rm -rf {} \;
endef

ifeq (all, $(cdbs_python_module_arch))
common-install-arch common-install-indep:: python-install-py
python-install-py:
    cd $(DEB_SRCDIR) &amp;&amp; $(call cdbs_python_binary,python$(cdbs_python_compile_version)) $(DEB_PYTHON_SETUP_CMD) install --root=$(DEB_DESTDIR) $(DEB_PYTHON_INSTALL_ARGS_ALL)
    $(call FIXUP_DIST)
else
common-install-arch common-install-indep:: $(addprefix python-install-, $(cdbs_python_build_versions))
python-install-%:
    cd $(DEB_SRCDIR) &amp;&amp; $(call cdbs_python_binary,python$*) $(DEB_PYTHON_SETUP_CMD) install --root=$(DEB_DESTDIR) $(DEB_PYTHON_INSTALL_ARGS_ALL)
    $(call FIXUP_DIST)
endif # archall detection</code></pre><br />
Let&#8217;s say it&#8217;s inside a file named <strong>debian/fixup.mk</strong>, then my complete <strong>debian/rules</strong> file would be like this.<br />
<pre><code>#!/usr/bin/make -f

DEB_PYTHON_SYSTEM=pycentral

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/python-distutils.mk
include debian/fixup.mk

export DH_PYCENTRAL=nomove</code></pre><br />
And this is the beauty of <span class="caps">CDBS, </span>a file which would be several lines long gets resumed to a few lines.</p>

<p>I&#8217;m still trying to find a way to make this code available for all my components without installing it to a globally reachable path, but did not find a thing such as a <span class="caps">MAKEFILEPATH </span>variable untill now. I guess a package like <strong>cdbs-maemo-dev.deb</strong> would be an appropriate place for stuff like this, but pushing it there is for another post.</p>]]></content:encoded>
			<wfw:commentRss>http://blog.msoares.pro.br/archives/python-debian-packaging-for-maemo/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Vim Scripting Using Python</title>
		<link>http://blog.msoares.pro.br/archives/vim-scripting-using-python</link>
		<comments>http://blog.msoares.pro.br/archives/vim-scripting-using-python#comments</comments>
		<pubDate>Fri, 10 Apr 2009 01:15:12 +0000</pubDate>
		<dc:creator>milton</dc:creator>
				<category><![CDATA[Planet INdT]]></category>
		<category><![CDATA[devel]]></category>
		<category><![CDATA[python]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[vim]]></category>

		<guid isPermaLink="false">http://msoares.dreamhosters.com/?p=39</guid>
		<description><![CDATA[Trying to solve a colleague&#8217;s problem when editing Edje files, I pushed myself into learning how to do scripting inside Vim. Scripting wasn&#8217;t ever my choice for reasonably complex editing tasks since I refused to learn Yet Another Scripting Language just because my favorite editor wanted me to. But, for the sake of all lazy [...]]]></description>
			<content:encoded><![CDATA[<p>Trying to solve a colleague&#8217;s problem when editing Edje files, I pushed myself into learning how to do scripting inside Vim.</p>

<p>Scripting wasn&#8217;t ever my choice for reasonably complex editing tasks since I refused to learn <em>Yet Another Scripting Language</em> just because my favorite editor wanted me to. But, for the sake of all lazy guys like me, Vim started to add python support, and python was a <strong>must learn</strong> bullet in my language listing.</p>

<p>However, not everything are flowers and the entry point must be configured using common vim script. Well, at least until vim supports python from its core, which &#8211; I believe &#8211; is not far from possible, since python integration <a href="http://www.vim.org/sponsor/vote_results.php">has been voted</a> as top priority for a long time.</p>

<p>To successfully import your python script inside vim context, one can wrap it into a vim function in an external file. Let&#8217;s call it <code>extras.vim</code>.</p>

<p><pre><code>&quot; Title-ize sentences using python str methods
function! PyMakeTitle() &quot; the ! erases previous definitions
python &amp;lt;&amp;lt; END &quot; here-document (bash-style), read 'till given word
import vim
w = vim.current.window
b = vim.current.buffer
line, col = w.cursor
line -= 1
b[line] = b[line].title() # str.title() method
END
endfunction</code></pre></p>

<p>After using <code>:source extras.vim</code> command to load it, one can call this function by typing <code>:call PyMakeTitle()</code>. Remember repeating the <code>:source</code> step every time the script gets updated.</p>

<p>The net effect of this function is to turn all initial word letters in the current line into capitals. It proved me to be useful when editing a large LaTeX document where all section titles were small letters only.</p>

<p>If it comes to be a very useful function, you may map it to a key-stroke by using <code>:nmap \t :call PyMakeTitle()&amp;lt;CR&amp;gt;</code> inside your vimrc script.</p>

<p>A more complex example accessing internal vim properties. Ok, it&#8217;s a bit useless, but it demonstrates well such features.</p>

<p><pre><code>&quot; Auto Documentation (example code)
function! PyCreateDoc()
python &amp;lt;&amp;lt; END
import vim
name = vim.eval(&quot;expand(\&quot;&amp;lt;cword&amp;gt;\&quot;)&quot;) # expand word under cursor
ts = int(vim.eval(&quot;&amp;amp;ts&quot;)) # tab space property
il = int(vim.eval(&quot;indent(\&quot;.\&quot;)&quot;)) # indentation on current line
w = vim.current.window
l, c = w.cursor
docstr = '%s# @brief %s - write description' % (' ' * il, name)
b = vim.current.buffer
b[l-1:l-1] = [ docstr ]
print 'Indent set is %d, cursor at (%d, %d)' % (ts, l, c)
END
endfunction</code></pre></p>

<p>With the cursor over a function name, type <code>:call PyCreateDoc()</code> and watch it insert a line above containing doxygen-like formatting.</p>

<p>For more examples, there is an excellent material at vim&#8217;s online help (see <code>:h python</code>). Furthermore, there are some plugins being made using only python, take a look at <strong>Omni Completion for Python</strong> (<a href="http://www.vim.org/scripts/script.php?script_id=1542">pythoncomplete.vim</a>) for a good reference on the power of using python inside vim.</p>

<p>Happy Easter Vim&#8217;ing!</p>]]></content:encoded>
			<wfw:commentRss>http://blog.msoares.pro.br/archives/vim-scripting-using-python/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

