stdeb (original) (raw)

stdeb - Python to Debian source package conversion utility

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. The install_debcommand installs this .deb file. The debianize command builds adebian/ directory directly alongside your setup.py.

Several convenience utilities are also provided:

Contents

Python 3

No attempt had been yet made to get stdeb to work with Python 3.

News

master branch

This branch is recommended for all users. It is currently tested on Ubuntu 12.04.

old-stable branch (0.3 and earlier)

This branch is recommended if you are operating on older Debian/Ubuntu distributions. It is compatible with Ubuntu Hardy.

The commands

pypi-download, command-line command

pypi-download takes a package name, queries PyPI for it and downloads it:

pypi-download [options] mypackage

pypi-install, command-line command

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, command-line command

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

py2dsc-deb, command-line command

py2dsc-deb takes a .tar.gz source package and build a Debian source package and then a .deb file from it:

py2dsc-deb [options] mypackage-0.1.tar.gz # uses pre-built Python source package

sdist_dsc, distutils command

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:

These can then be compiled into binary packages using the standard Debian machinery (e.g. dpkg-buildpackage).

bdist_deb, distutils command

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

install_deb, distutils command

The install_deb distutils command calls the bdist_deb command and then installs the result. You need to run this with superuser privilege:

sudo python setup.py --command-packages=stdeb.command install_deb

debianize, distutils command

The debianize distutils command builds the same debian/directory as used in the previous command, but the output is placed directly in the project’s root folder (alongside setup.py). This is useful for customizing the Debian package directly (rather than using the various stdeb options to tune the generated package).

python setup.py --command-packages=stdeb.command debianize

A note about telling distutils to use the stdeb distutils commands

Distutils command packages can also be specified in distutils configuration files (rather than using the --command-packagescommand 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

Examples

These all assume you have stdeb installed in your system Python path. stdeb also works from a non-system Python path (e.g. avirtualenv).

Quickstart 1: Install something from PyPI now, I don’t care about anything else

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.

Quickstart 2: Just tell me the fastest way to make a .deb

(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.

Quickstart 3: 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 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

Quickstart 4: Install from a Python package direct to a debian system package

(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 install_deb

This will make a Debian source package (.dsc, .orig.tar.gz and .diff.gz files), compile it to a Debian binary package (.deb) for your current system and then install it using dpkg.

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 files reindent_0.1.0-1.dsc, reindent_0.1.0.orig.tar.gz andreindent_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 (usingdpkg-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, seeallmydata-tahoe ticket 251.

Download

Files are available at the download page (for ancient releases, see the old download page).

The git repository is available athttp://github.com/astraw/stdeb

Install (or, using stdeb to create an stdeb installer)

For a bit of fun, here’s how to install stdeb using stdeb. Note that stdeb is also in Debian and Ubuntu, so this recipe is only necessary to install a more recent stdeb.

STDEB_VERSION="0.7.1"

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

Background

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.

Features

Customizing the produced Debian source package (config options)

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.

stdeb distutils command options

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.cfgfile 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
–dist-dir (-d) directory to put final built distributions in (default=’deb_dist’)
–patch-already-applied (-a) patch was already applied (used when py2dsc calls sdist_dsc)
–default-distribution deprecated (see –suite)
–suite (-z) distribution name to use if not specified in .cfg (default=’unstable’)
–default-maintainer deprecated (see –maintainer)
–maintainer (-m) maintainer name and email to use if not specified in .cfg (default from setup.py)
–extra-cfg-file (-x) additional .cfg file (in addition to stdeb.cfg if present)
–patch-file (-p) patch file applied before setup.py called (incompatible with file specified in .cfg)
–patch-level (-l) patch file applied before setup.py called (incompatible with file specified in .cfg)
–patch-posix (-q) apply the patch with –posix mode
–remove-expanded-source-dir (-r) remove the expanded source directory
–ignore-install-requires (-i) ignore the requirements from requires.txt in the egg-info directory
–force-buildsystem If True (the default), set ‘DH_OPTIONS= –buildsystem=python_distutils’
–no-backwards-compatibility This option has no effect, is here for backwards compatibility, and may be removed someday.
–guess-conflicts-provides-replaces If True, attempt to guess Conflicts/Provides/Replaces in debian/control based on apt-cache output. (Default=False).
–use-premade-distfile (-P) use .zip or .tar.gz file already made by sdist command
–source debian/control Source: (Default: )
–package debian/control Package: (Default: python-)
–suite suite (e.g. stable, lucid) in changelog (Default: unstable)
–maintainer debian/control Maintainer: (Default: )
–debian-version debian version (Default: 1)
–section debian/control Section: (Default: python)
–epoch version epoch
–forced-upstream-version forced upstream version
–upstream-version-prefix upstream version prefix
–upstream-version-suffix upstream version suffix
–uploaders uploaders
–copyright-file copyright file
–build-depends debian/control Build-Depends:
–build-conflicts debian/control Build-Conflicts:
–stdeb-patch-file file containing patches for stdeb to apply
–stdeb-patch-level patch level provided to patch command
–depends debian/control Depends:
–suggests debian/control Suggests:
–recommends debian/control Recommends:
–xs-python-version debian/control XS-Python-Version:
–dpkg-shlibdeps-params parameters passed to dpkg-shlibdeps
–conflicts debian/control Conflicts:
–provides debian/control Provides:
–replaces debian/control Replaces:
–mime-desktop-files MIME desktop files
–mime-file MIME file
–shared-mime-file shared MIME file
–setup-env-vars environment variables passed to setup.py
–udev-rules file with rules to install to udev

You may also pass any arguments described below for the stdeb.cfg file via distutils options. Passing the arguments this way (either on the command line, or in the [sdist_dsc] section of a distutils .cfg file) will take precedence. The option name should be given in lower case.

stdeb.cfg configuration file

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
Source debian/control Source: (Default: )
Package debian/control Package: (Default: python-)
Suite suite (e.g. stable, lucid) in changelog (Default: unstable)
Maintainer debian/control Maintainer: (Default: )
Debian-Version debian version (Default: 1)
Section debian/control Section: (Default: python)
Epoch version epoch
Forced-Upstream-Version forced upstream version
Upstream-Version-Prefix upstream version prefix
Upstream-Version-Suffix upstream version suffix
Uploaders uploaders
Copyright-File copyright file
Build-Depends debian/control Build-Depends:
Build-Conflicts debian/control Build-Conflicts:
Stdeb-Patch-File file containing patches for stdeb to apply
Stdeb-Patch-Level patch level provided to patch command
Depends debian/control Depends:
Suggests debian/control Suggests:
Recommends debian/control Recommends:
XS-Python-Version debian/control XS-Python-Version:
Dpkg-Shlibdeps-Params parameters passed to dpkg-shlibdeps
Conflicts debian/control Conflicts:
Provides debian/control Provides:
Replaces debian/control Replaces:
MIME-Desktop-Files MIME desktop files
MIME-File MIME file
Shared-MIME-File shared MIME file
Setup-Env-Vars environment variables passed to setup.py
Udev-Rules file with rules to install to udev

The option names in stdeb.cfg files are not case sensitive.

Prerequisites

TODO

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.

Mailing list

Please address all questions to the distutils-SIG

License

MIT-style license. Copyright (c) 2006-2014 stdeb authors.

See the LICENSE.txt file provided with the source distribution for full details.

Authors

Additional Credits