stdeb produces Debian source packages from Python packages via a new distutils command, sdist_dsc
. Automatic defaults are provided for the Debian package, but many aspects of the resulting package can be customized (see the customizing section, below). An additional command, bdist_deb
, creates a Debian binary package, a .deb file.
Two convenience utilities are also provided. pypi-install
will query the Python Package Index (PyPI) for a package, download it, create a .deb from it, and then install the .deb. py2dsc
will convert a distutils-built source tarball into a Debian source package.
This branch is recommended for all users. It requires Debhelper 7, and thus requires Ubuntu Intrepid or Debian Lenny (unless you use backports).
- 2009-12-30: Version 0.5.0. See the download page. Highlights for this release (you may also wish to consult the full changelog):
- A new
pypi-install
script will automatically download, make a .deb, and install packages from the Python Package Index (PyPI).- Removal of the setuptools dependency.
- New option (--guess-conflicts-provides-replaces) to query original Debian packages for Conflicts/Provides/Replaces information.
- As a result of these changes and to fix a couple bugs/warts, some minor backwards incompatible changes and deprecations were made. Please check the release notes.
- 2009-12-28: Version 0.4.3 Released. See the download page. See the changelog and release notes.
- 2009-11-02: Version 0.4.2 Released. See the download page. See the changelog and release notes.
- 2009-10-04: Version 0.4.1 Released. See the download page. See the changelog and release notes.
- 2009-09-27: Version 0.4 Released. See the download page. This version switches to debhelper 7. See the Changelog for 0.4.
This branch is recommended if you are operating on older Debian/Ubuntu distributions. It is compatible with Ubuntu Hardy.
- 2009-10-04: Version 0.3.2 Released. See the download page. See the Changelog for 0.3.2
- 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.
pypi-install
takes a package name, queries PyPI for it, downloads it, builds a Debian source package and then .deb from it, and this installs it:
pypi-install [options] mypackage
py2dsc
takes a .tar.gz source package and build a Debian source package from it:
py2dsc [options] mypackage-0.1.tar.gz # uses pre-built Python source package
All methods eventually result in a call to the sdist_dsc
distutils command. You may prefer to do so directly:
python setup.py --command-packages=stdeb.command sdist_dsc
A Debian source package is produced from unmodified Python packages. The following files are produced in a newly created subdirectory deb_dist
:
packagename_versionname.orig.tar.gz
packagename_versionname-debianversion.dsc
packagename_versionname-debianversion.diff.gz
These can then be compiled into binary packages using the standard Debian machinery (e.g. dpkg-buildpackage).
Also, a bdist_deb
distutils command is installed. This calls the sdist_dsc command and then runs dpkg-buildpackage on the result:
python setup.py --command-packages=stdeb.command bdist_deb
Distutils command packages can also be specified in distutils configuration files (rather than using the --command-packages
command line argument to setup.py
), as specified in the distutils documentation. Specifically, you could include this in your ~/.pydistutils.cfg
file:
[global]
command-packages: stdeb.command
These all assume you have stdeb installed in your system Python path. stdeb also works from a non-system Python path (e.g. a virtualenv).
Do this from the command line:
pypi-install mypackage
Warning: Despite doing its best, there is absolutely no way stdeb can guarantee all the Debian package dependencies will be properly fulfilled without manual intervention. Using pypi-install bypasses your ability to customize stdeb's behavior. Read the rest of this document to understand how to make better packages.
(First, install stdeb as you normally install Python packages.)
Do this from the directory with your setup.py file:
python setup.py --command-packages=stdeb.command 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 deb_dist
.
Warning: 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 probably break. Even in the absence of extension modules, bad stuff will likely 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.
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 using the standard Debian tools. (Do this on the same source package for each target distribution):
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
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 files reindent_0.1.0-1.dsc
, reindent_0.1.0.orig.tar.gz
and reindent_0.1.0-1.diff.gz
, which, together, are a debian source package:
python setup.py --command-packages=stdeb.command sdist_dsc
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.
Files are available at the download page (for ancient releases, see the old download page).
The git repository is available at http://github.com/astraw/stdeb
For a bit of fun, here's how to install stdeb using stdeb. Note that stdeb is also in Debian, so this recipe is only necessary to install a more recent stdeb.
STDEB_VERSION="0.5.0"
# Download stdeb
wget http://pypi.python.org/packages/source/s/stdeb/stdeb-$STDEB_VERSION.tar.gz
# Extract it
tar xzf stdeb-$STDEB_VERSION.tar.gz
# Enter extracted source package
cd stdeb-$STDEB_VERSION
# Build .deb (making use of stdeb package directory in sys.path).
python setup.py --command-packages=stdeb.command bdist_deb
# Install it
sudo dpkg -i deb_dist/python-stdeb_$STDEB_VERSION-1_all.deb
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. setuptools may optionally be used.
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 python-support. (Limiting this range is possible with the
XS-Python-Version:
config option.) - 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
Forced-Upstream-Version
. - Fine grained control of version numbers. (
Debian-Version
,Forced-Upstream-Version
,Upstream-Version-Prefix
,Upstream-Version-Suffix
config options.) - Install .desktop files. (
MIME-Desktop-Files
config option.) - Install .mime and .sharedmimeinfo files. (
MIME-File
andShared-MIME-File
config options.) - Install copyright files. (
Copyright-File
config option.) - Apply patches to upstream sources. (
Stdeb-Patch-File
config option.) - Pass environment variables to setup.py script. (
Setup-Env-Vars
config option.)
stdeb will attempt to provide reasonable defaults, but these are only guesses.
There are two ways to customize the Debian source package produced by stdeb. First, you may provide options to the distutils commands. Second, you may provide an stdeb.cfg
file.
The sdist_dsc command takes command-line options to the distutils command. For example:
python setup.py --command-packages=stdeb.command sdist_dsc --debian-version 0MyName1
This creates a Debian package with the Debian version set to "0MyName1".
These options can also be set via distutils configuration files. (These are the setup.cfg
file alongside setup.py
and the ~/.pydistutils.cfg file.) In that case, put the arguments in the [sdist_dsc]
section. For example, a project's ~/.setup.cfg
file might have this:
[sdist_dsc]
force-buildsystem: False
To pass these commands to sdist_dsc when calling bdist_deb, do this:
python setup.py sdist_dsc --debian-version 0MyName1 bdist_deb
Command line option | Effect |
---|---|
|
directory to put final built distributions in (default='deb_dist') |
|
patch was already applied (used when py2dsc calls sdist_dsc) |
|
distribution name to use if not specified in .cfg (default='unstable') |
|
maintainer name and email to use if not specified in .cfg (default from setup.py) |
|
additional .cfg file (in addition to .egg-info/stdeb.cfg if present) |
|
patch file applied before setup.py called (incompatible with file specified in .cfg) |
|
patch file applied before setup.py called (incompatible with file specified in .cfg) |
|
apply the patch with --posix mode |
|
remove the expanded source directory |
|
ignore the requirements from requires.txt in the egg-info directory |
|
debian version |
|
If True (currently the default), enable migration from old stdeb that used pycentral |
|
If True (currently the default), limit binary package to single Python version, working around Debian bug 548392 of debhelper |
|
If True (the default), set 'DH_OPTIONS= --buildsystem=python_distutils' |
|
If True, set --pycentral-backwards-compatibility=False and --workaround-548392=False. (Default=False). |
|
If True, attempt to guess Conflicts/Provides/Replaces in debian/control based on apt-cache output. (Default=False). |
|
use .zip or .tar.gz file already made by sdist command |
You may write config files of the format understood by ConfigParser. When building each package, stdeb looks for the existance of a stdeb.cfg
in the directory with setup.py
. You may specify an additional config file with the command-line option --extra-cfg-file. The section should should either be [DEFAULT] or [package_name], which package_name is specified as the name argument to the setup() command. An example stdeb.cfg file is:
[DEFAULT]
Depends: python-numpy
XS-Python-Version: >= 2.6
All available options:
Config file option | Effect |
---|---|
Debian-Version | Set Debian version |
Maintainer | Set Debian maintainer |
Section | Add entry to Section in debian/control |
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
- Standard Debian utilities such as
date
,dpkg-source
and Debhelper 7 (use stdeb 0.3.x if you need to support older distributions without dh7)
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
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 <strawman@astraw.com>
- Pedro Algarvio, aka, s0undt3ch <ufs@ufsoft.org>
- Gerry Reno (initial bdist_deb implementation)
- Zooko O'Whielacronx for the autofind-depends patch
- Brett (last name unknown) for the --ignore-install-requires patch
- Ximin Luo for a bug fix
- Alexander D. Sedov for bug fixes and suggestions
- Michele Mattioni for bug fix
- Alexander V. Nikolaev for the debhelper buildsystem specification
- GitHub for hosting services.
- WebFaction (aka python-hosting) for previous hosting services.