Random thoughts shooting out of volatile mind
Tutorial: Python module packaging for Debian
In this post I would like to share my experience on packaging my first python module for Debian. Its still waiting in the new queue to enter experimental branch of Debian. I would like to give a brief overview of the python module packaging here. I assume the reader knows basics of python module packaging and has gone through the Debian New Maintainers guide.
For Python module packaging first step is to get the source from the pypi . In my case since I was one of the developer for pypdflib, I just ran the below command to get tar.gz file for pypdflib
python setup.py sdist
The archive will be created under dist folder. In my case archive name was pypdflib-0.1.a2.tar.gz. Now copy that to a folder where you want to create the package.

Now we need to install a tool called python-stdeb - Python to Debian source package conversion utility. Run the below command to get the package installed
sudo aptitude install python-stdeb
 Now run the below command to create a .dsc and module source with debian folder template inside it.
py2dsc -m 'Your Name ' package-version.tar.gz
 Replace the fields appropriately it will create a folder deb_dist in the same directory and the extracted source with debian folder template will be placed under it.
deb_dist
  |
  |___ package-version
Now enter debian directory and edit the control changelog and copyright files to suit your needs. Make the copyright file in  dep5 machine readable format. Also I noted that for some reason source/format file under debian directory contained 1.0 (native format). If so please change it to contain the following lines
3.0 (quilt)
That is almost it now running the following command will create the package for your module
debuild
If lintian complaints about issue please fix them, one important thing in Debian packaging is your package should always be lintian clean.

Now for some special cases there is chance that when you may have to do some extra work. In my case following where happening.
1. Original source (package-version.orig.tar.gz) was getting modified mainly because of packagename.egg.info folder which is created during compilation.
2. I had some samples for my module which should be installed as examples.

For the first problem solution was to override dh_clean section. I added the following lines to my rules file

override_dh_clean:
        dh_clean
        rm -rf setuptools_git-0.3.4-*
        rm -rf src/pypdflib.egg-info
What it does is it executes the remove command on 2 folder which were not cleaned automatically by dh_clean.

For second problem the solution was overriding dh_installexamples section to install my examples manually.

override_dh_installexamples:
        dh_installexamples -p python-pypdflib samples/*
I didn't put those under /usr/bin/ folder since those examples are not a fully featured tools during the creation. I'll be adding them as tools under /usr/bin using link file in the next release.

Below is my complete rule file for your reference.



I thank Praveen A  for guiding me and teaching Debian packaging and Kartik Mistry for helping me in packaging pypdflib and sponsoring it in Debian. My package source now lies in Debian-IN team svn repository. If there are any mistakes please do comment about them :).

Reference: Debian Woman Python packaging session
Posted by: copyninja on Sunday, 20 February 2011

blog comments powered by Disqus
Fork me on GitHub