make distutils in Python automatically find packages

Solution 1:

I would recommend using the find_packages() function available with setuptools such as:

from setuptools import setup, find_packages

and then do

packages=find_packages()

Solution 2:

The easiest way (that I know of) is to use pkgutil.walk_packages to yield the packages:

from distutils.core import setup
from pkgutil import walk_packages

import mypackage

def find_packages(path=__path__, prefix=""):
    yield prefix
    prefix = prefix + "."
    for _, name, ispkg in walk_packages(path, prefix):
        if ispkg:
            yield name

setup(
    # ... snip ...
    packages = list(find_packages(mypackage.__path__, mypackage.__name__)),
    # ... snip ...
)