Be distutils2-ready

Publié le sam. 06 octobre 2012 par Julien Miotte

TL;DR

The best setup.py file of the world consists of very little copy pasteable boilerplate, that will enable the d2to1 tool. You'll be proud and comfortably happy because you can start using the nextgen packaging tool from the future: distutils2 and its setup.cfg files everywhere!

Abstract

Distutils 2 is awesome, here's how you can prepare your project (without installing distutils2).

Packaging is a delicate issue

It's complicated for Pythonistas, and it's even more complicated for newcomers.

Pythonistas may be familiar with the packaging situation, and the reasons behind the distutils2 project, but many others just want something that works (tm), and all they'll see with distutils2 is : "Not in the standard library". So they'll use other packaging tools, build complicated setup.py scripts, and will learn that packaging in Python is done with a dynamic script. This could make them reluctant to do the jump to metadata packaging, whereas they could be users of distutils2 and lobbyists for its integration in the standard library.

One bridge to the future

Erik M. Bray's d2to1 project aims at providing a compatibility between distutils2 metadata formalism (PEP345) and current packaging tools. It parses the setup.cfg file to provide arguments to setuptools.setup().

The good news is, you don't need it to be installed, as we can require setuptools to download it prior to the setup, as shown below.

Be ready for distutils2

Complying with distutils2 is the easiest step that will make a modern developer out of you. Copy paste the following code in a setup.py file:

#!/usr/bin/env python
from setuptools import setup

setup(setup_requires=['d2to1'],
      d2to1=True,

      # This ensures that the MANIFEST.in is read, but it
      # will become the default in distutils2.
      include_package_data=True,)

All that is left to do now is write your own setup.cfg file. Here is the best place (as of writing) to learn about the syntax of setup.cfg: http://alexis.notmyidea.org/distutils2/setupcfg.html.

Profit!

For installations not using distutils2, running setup.py will quite automagically setup your package using the informations supplied in the setup.cfg file!

You can spread the news! Why wait for distutils2 to be mainstream, for you can start using it right now?