Easter python eggs
It's easter, and only fitting that I play with eggs, so today I have been
looking at making python eggs. Eggs are a new way of distributing python
software that gets more and more popular. This is mainly because installing
it is simple, and because an egg can contain a list of requirements, and the
installer will check if these requirements are installed, and if not, it
will look them up in the standard Python module library (known as the Cheese
Shop), and download and install them.
This means the end of long hours of downloading, compiling and installing
all those modules you need to get your python software working. You download
just the module you want as an egg and install it, and all requirements will
be installed with it, if they have been eggyfied too.
Making eggs is unfortunately a bit tricky. This is because there is no good
examples of how to do it, so you have to read through all the documentation,
and experiment a lot. This is a shame, because in the end, it turns out to
be very easy.
All you need is to install the python module setuptools, and create a a
setup.py for your package. Creating it can be slightly tricky, if your
package layout is complicated. Also, there is not always clear what the
parameters in it should be, and there is quite a lot of searching and trying
out (and for my finally some honest debugging of setupttools too figure out
what was going on, really).
The parameters are for the most part the same as for making a package with
distutils, so if you have a distutils package, all you need to do is to
switch out the "from distutils.core import setup" to "from setuptools import
setup" and you are done.
Here is an an example of a full setup.py, for the CalCore module:
from setuptools import setup
install_requires=['zope.interfaces >= 3.0',
'zope.schema >= 3.0',
'zope.i18nmessageid >= 3.0'],
# metadata for upload to PyPI
author='Martijn Faassen, Infrae;Lennart Regebro, Nuxeo',
long_description="""CalCore is an advanced, flexible calendaring component for Python. It
allows the Python developer do write advanced calendaring applications
either using their own event storage or integrating with external
Features of the CalCore include among others:
Support for making private calendars, shared calendars, resource
booking and more.
integration with iCalendar clients (Apple iCal, Mozilla Sunbird,
KOrganizer...) using the iCalendar protocol,
meeting support, including helper functions to look for free time,
recurring event support (thanks to SchoolTools recurrence
CalCore is being used as the core of Nuxeos CalZope and
CPSSharedCalendar products, products for integrating with Zope and CPS.
These products provide a complete web-based user interface to the
classifiers=['Development Status :: 5 - Production/Stable',
'Intended Audience :: Developers',
'License :: OSI Approved :: GNU General Public License (GPL)',
'Operating System :: OS Independent',
'Topic :: Office/Business :: Groupware'],
You'll note the install_requires parameter, that list the requirements. You can also use ==, of course, and you can list requirements that are only used for testing, and lots of other stuff. Also note the dependency_links parameter, which enables downloads from other places than the Cheeze Shop, in this case Zope.orgs repository of Zope3 eggs.
(Post originally written by Lennart Regebro on the old Nuxeo blogs.)
Category: Product & Development