Just a note: from now on some posts will be in English. I just want to make sure some of them are worlwide readable.
During DebConf8 I met John Wright, who works in HP. He packages a couple
of python things, like trac-mercurial (currently in sid only), and he
offered to teach me how to package python things.
I've been trying to do that for a couple of years, but Debian's Python Policy is just too much for me. Call me lazy, $DEITY knows I know I am, but I just can't cope with so much and dense info.
So, I tried to look for automatical tools to do it. Two years ago the
only thing I could find was (WARNING: ugly colors ahead)
packer, but its vitality is rather
low: according to FreshMeat, it was added on Dec 2005 and last updated
on Feb 2006. I started using it, but its interface is not very good, so
realeasing further versions was not an easy task. Also, I think now it's
very out-of-date to Debian Policy.
This week I tried again, now trying to find something that could use
either python-support or python-central to manage the python
package, and also that it used the info from setuptool's setup.py,
but I only could find some incomplete tutorials.
So John explained it to me. It really comes down to using dh_make, the
starting point of debhelper. Before you run it you have to make sure
everything's in place for it. That means to put the code in a directory
which name is the name of the program, followed by a dash, followed by
the version, like psync-0.4.1.
Now you just run dh_make --createorig, who asks what kind of package
you're about to build. Normaly a 'single binary' is enough. It will show
you some info it has gathered from your environment, about who you are
and what package you're building. This will also create a .orig
directory in the parent directory (making if a sibling of the current
one) from the current directory, so make sure no cruft goes in. Here is
the point were if there is no setup.py file, you just add it with the
proper info.
This creates the debian directory with a lot of files on it. Those who
already read about Debian packaging will find familiar files. If you're
not, the best way to figuring out what goes where is the proper Debian
Policy.
The first file you have to edit is
control;
just make sure that you add python and python-support as BuildDeps
and ${python:Depends} as Deps.
The
rules
file is a little more complicated. It's a Makefile with several
targets. configure must have the commands needed to configure the
project prior to building it. Most python programs don't need this or
the next one, which is the build target. This one obviously should
have the commands needed to build the program. The third one is clean,
where you usualy just neet to replace the boilerplate $(MAKE) clean
with python setup.py clean. The install target will need a python
setup.py install --prefix=$(CURDIR)/debian/psync/usr. Just check out
the $(MAKE) invocation and you'll figure it out.
The last one is the binary-arch target. This one has lots of calls to
debhelper functions. If you read it carefully, you'll see a
dh_python call, commented out. Don't use it, use dh_pysupport. This
is the hook for python-support support. This is the part that does all
the magic to make sure that you don't break the Debian Python Policy.
And that's mostly it. You can comment out a couple of dh_ functions,
like dh_strip or dh_shlibdeps (shared libs deps).
Another file to edit, and this might be the last one, is
changelog.
This one has a particular format, so I suggest to use dch from the
devscripts package. The one you'll find is a template the dh_make
left for you to fill. You just need to put the bug number of the
ITP bug. What, you
haven't send an ITP but yet? Well, do
it! Then you can use dch -a to
add new entries to the current version's entries, dch -i to increment
the Debian version and maybe dch -r to update the date at the bottom
of the current version. See its manpage for further options.
Last, there is some junk in the debian directory, most of them the
*.ex files, which are just examples. You can safely get rid of them,
or read them to see if they suit you.
The next step is to build it. This is as easy-peasy as running
dpkg-buildpackage. This will build a .deb file, a .dsc file, a
.orig.tar.gz file, a .diff.gz and a .changes file in the parent
directory. This is the outcome of all the work you've done so far, but
is not finished yet. You better run lintian on the .dsc file and the
.deb file. If you add the -i option you'll get some explanation on
why you failed to give a proper, no-lint package.
So, that's it. It's a longish post, but should get you up packaging
python apps in a few minutes. The are still a few problems: you end up
dup'ing info: in the setup.py file and in various files in the
debian directory. Maybe I'll hack something to workaround this.