Easter python eggs


Wed 26 April 2006 By nuxeo

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:


#!/usr/bin/env python

from setuptools import setup

setup(name='calcore',
package_dir={'': 'src'},
packages=['calcore'],
version='2.0.1',
install_requires=['zope.interfaces >= 3.0',
'zope.schema >= 3.0',
'zope.i18nmessageid >= 3.0'],
dependency_links=['http://download.zope.org/distribution/',],

# metadata for upload to PyPI
author='Martijn Faassen, Infrae;Lennart Regebro, Nuxeo',
author_email='[email protected]',
description='Calendaring system',
license='GPL2',
keywords='calendar icalendar',
url='http://www.cps-project.org/sections/projects/calendar_server ',
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
calendar servers.

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,
invitation workflow,
meeting support, including helper functions to look for free time,
recurring event support (thanks to SchoolTools recurrence
implementation, http://www.schooltool.org),
etc.

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
CalCore calendaring.""",
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'],
platforms='All',
)

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