[Distutils] setuptools, eggs, and setup.py in the root of a package - how?

Jeff Shell eucci.group at gmail.com
Wed Aug 8 03:23:35 CEST 2007

So we've never done much with eggs or distutils up until now at my
company. We've generally worked in Zope. We generally check out Python
packages directly into a directory where Zope would automatically pick
them up. So we've never gotten into any convention of having a layout
that I commonly see these days:

      - setup.py
      + src
         + ourlib
           - __init__.py
           - etc...

Fearing that we'd have to dramatically change our source code around,
and shake up existing checkouts, I've avoided trying to add any
distutils/setuptools support to these packages. But I was told
recently that I could have `setup.py` in the package root (`ourlib` in
the example above). I've seen this work in a plain distutils system
(Chris McDonough's BuildIt), but I've had a nightmare of a time
getting it to work with setuptools and zc.buildout and on and on.

Some code lies below that tries to explain the dilemma and shows my
best guess efforts so far. Has anyone had any success with this

I was trying to use this as a 'develop' egg(?) using `zc.buildout`,
and it doesn't work. In a generated 'virtual-python' kind of thing, it
sets up this in sys.path (when specifying ``develop=src/ourlib`` in

    sys.path[0:0] = [

This seems like an uphill battle. Any tips? My fallback plan is to
have a separate 'releases' area of our repository which houses
setup.py and such for each of these packages along with a script to
check out the main source before building an distribution or using as
a develop-egg-thing.

Is there anything, specific to this problem, that I can be doing
better with this setup.py?

    from setuptools import setup, find_packages

    def list_packages():
        packages = [
            'ourlib.%s' % subpackage
            for subpackage in find_packages()
        packages.insert(0, 'ourlib')
        return packages

        name = 'ourlib',
        version = "1.0a1",

        packages = list_packages(),
        package_dir = {'ourlib': '.'},
        include_package_data = True,

        extras_require = dict(
            test = ['zope.testing'],

        zip_safe = False,

Without that 'list_packages', the results of `find_packages` would
return 'toolkit' instead of 'ourlib.toolkit': the package head that
would normally be there is off.

Jeff Shell

More information about the Distutils-SIG mailing list