stdeb - Python to Debian source package conversion utility
stdeb ("setuptools debian") produces Debian source packages from
Python packages via a new distutils command,
defaults are provided for the Debian package, but many aspects of the
resulting package can be customized via a configuration file.
- 2009-09-27: Version 0.4 Released. See the download page. This version switches to debhelper 7, and thus requires Ubuntu Intrepid or Debian Lenny at a minimum (unless you use backports). See the Changelog for 0.4
- 2009-09-27: Version 0.3.1 Released. See the download page. See the Changelog for 0.3.1
- 2009-03-21: Version 0.3 Released. See the download page. See the Changelog for 0.3
- 2009-02-17: Version 0.2.3 Released. See the download page. See the Changelog for 0.2.3
- 2009-01-29: Version 0.2.2 Released. See the download page. See the Changelog for 0.2.2
- 2008-04-26: Version 0.2.1 Released. See the download page. See the Changelog for 0.2.1
- 2008-04-26: Version 0.2 Released. See the download page. See the Changelog for 0.2
- 2007-04-02: Version 0.2.a1 Released. See the old download page.
- 2006-06-19: Version 0.1 Released. See the old download page.
All methods eventually result in a call to the
command. You may prefer to do so directly:
python -c "import stdeb; execfile('setup.py')" sdist_dsc
Alternatively, two scripts are provided:
stdeb_run_setup [options] # calls "python setup.py sdist_dsc [options]" py2dsc [options] mypackage-0.1.tar.gz # uses pre-built Python source package
In all cases, a Debian source package is produced from unmodified
Python packages. The following files are produced in a newly created
These can then be compiled into binary packages using the standard Debian machinery (e.g. dpkg-buildpackage).
bdist_deb distutils command is installed. This calls the
sdist_dsc command and then runs dpkg-buildpackage on the result.
Quickstart 1: Just tell me the fastest way to make a .deb
Do this from the directory with your setup.py file:
python -c "import stdeb; execfile('setup.py')" bdist_deb
This will make a Debian source package (.dsc, .orig.tar.gz and
.diff.gz files) and then compile it to a Debian binary package (.deb)
for your current system. The result will be in
Note: installing the .deb file on other versions of Ubuntu or Debian than the one on which it was compiled will result in undefined behavior. If you have extension modules, they will be very likely to break. Even in the absence of extension modules, bad stuff could happen.
For this reason, it is much better to build the Debian source package and then compile that (e.g. using Ubuntu's PPA) for each target version of Debian or Ubuntu.
Quickstart 2: I read the warning, so show me how to make a source package, then compile it
This generates a source package:
wget http://pypi.python.org/packages/source/R/Reindent/Reindent-0.1.0.tar.gz py2dsc Reindent-0.1.0.tar.gz
This turns it into a .deb:
cd deb_dist/reindent-0.1.0/ dpkg-buildpackage -rfakeroot -uc -us
This installs it:
cd .. sudo dpkg -i python-reindent_0.1.0-1_all.deb
Another example, with more explanation
This example is more useful if you don't have a Python source package
(.tar.gz file generated by
python setup.py sdist). For the sake of
illustration, we do download such a tarball, but immediately unpack it
(alternatively, use a version control system to grab the unpacked
source of a package):
wget http://pypi.python.org/packages/source/R/Reindent/Reindent-0.1.0.tar.gz tar xzf Reindent-0.1.0.tar.gz cd Reindent-0.1.0
The following will generate a directory
deb_dist containing the
reindent_0.1.0-1.diff.gz, which, together, are a debian source
python setup.py sdist_dsc
(For packages that don't use setuptools, you need to get the stdeb
monkeypatch for the sdist_dsc distutils command. So, do this:
-c "import stdeb; execfile('setup.py')" sdist_dsc, or use the
stdeb_run_setup, which does just this.)
The source generated in the above way is also extracted (using
dpkg-source -x) and placed in the
deb_dist subdirectory. To
continue the example above:
cd deb_dist/reindent-0.1.0 dpkg-buildpackage -rfakeroot -uc -us
Finally, the generated package can be installed:
cd .. sudo dpkg -i python-reindent_0.1.0-1_all.deb
For yet another example of use, with still more explanation, see allmydata-tahoe ticket 251.
The git repository is available at http://github.com/astraw/stdeb
For the average Python package, its source distribution
(python_package.tar.gz created with
python setup.py sdist)
contains nearly everything necessary to make a Debian source
package. This near-equivalence encouraged me to write this distutils
extension, which executes the setup.py file to extract relevant
information. This process is made significantly easier through the use
setuptools is used because of some nice features. For example, setuptools makes the job of "Debianizing" python console and gui scripts much easier.
I wrote this initially to Debianize several Python packages of my own, but I have the feeling it could be generally useful. It appears similar, at least in theory, to easydeb, Logilab's Devtools, bdist_dpkg and bdist_deb.
- Create a package for all Python versions supported by
pycentral. (Limiting this range is possible with the
- Automatic conversion of Python package names into valid Debian package names.
- Attempt to automatically convert version numbers such that ordering
is maintained. (The setuptools version sorting is different than the
Debian version sorting.) See also the config option
- Fine grained control of version numbers. (
- Install .desktop files. (
- Install .mime and .sharedmimeinfo files. (
- Install copyright files. (
- Apply patches to upstream sources. (
- Pass environment variables to setup.py script. (
Customizing the produced Debian source package (config options)
stdeb will attempt to provide reasonable defaults, but these are only guesses.
To customize the Debian source package produced, you may write config
files of the format understood by ConfigParser. When building each
package, stdeb looks for the existance of a
stdeb.cfg file in the
.egg-info directory. You may specify an additional config file
with the command-line option --extra-cfg-file.
For an example configuration file I use to build several packages, please see http://stdeb.python-hosting.com/wiki/stdeb_all.cfg
|Debian-Version||Set Debian version|
|Forced-Upstream-Version||Force upstream version number|
|Upstream-Version-Prefix||Force upstream version prefix (e.g. epoch)|
|Upstream-Version-Suffix||Force upstream version suffix|
|Build-Depends||Add entry to debian/control|
|Depends||Add entry to debian/control|
|Package||Name of (binary) package|
|Source||Nome of source package|
|XS-Python-Version||Add to debian/control (limits Python versions)|
|MIME-Desktop-Files||Filename of .desktop file(s) to install|
|MIME-File||Filename of .mime file(s) to install|
|Shared-MIME-File||Filename of .sharedmimeinfo file(s) to install|
|Copyright-File||Filename of copyright file to install|
|Stdeb-Patch-File||Patches to apply|
|Setup-Env-Vars||Environment variables to set on call to setup.py|
- Python 2.5 or higher (older python OK if you use subprocess.py with backports from Python 2.5)
- Standard Debian utilities (e.g.
Using stdeb on stdeb
There is a chicken-and-egg problem when trying to make a Debian package of stdeb with stdeb. Here's a recipe to avoid it:
# in the stdeb distribution directory (with setup.py) python setup.py sdist python setup.py build PYTHONPATH="build/lib" python stdeb/py2dsc.py dist/stdeb-VERSION.tar.gz
- Make output meet Debian Python Policy specifications or the new
python policy. This will include several things, among which are:
- the ability to make custom changelogs
- the ability to include project-supplied documentation as a -doc package
- include license information in debian/copyright
- the ability to include project-supplied examples, tests, and data as a separate package
- much more not listed
- Create (better) documentation
- Log output using standard distutils mechanisms
- Refactor the source code to have a simpler, more sane design
Call for volunteers
I don't have a lot of time for this. This project stands a very real chance of being only a shadow of its potential self unless people step up and contribute. There are numerous ways in which people could help. In particular, I'd be interested in finding a co-maintainer or maintainer if the project generates any interest. Secondarily, I would appreciate advice from Debian developers or Ubuntu MOTUs about the arcane details of Python packaging.
Please address all questions to the distutils-SIG
MIT-style license. Copyright (c) 2006-2009 stdeb authors.
See the LICENSE.txt file provided with the source distribution for full details.
- Andrew Straw <firstname.lastname@example.org>
- Pedro Algarvio, aka, s0undt3ch <email@example.com>
- Gerry Reno (initial bdist_deb implementation)