python setup.py sdist only including .py source from top level module

Question:

I have a setup.py:

from setuptools import setup

setup(
      ...
      packages=['mypackage'],
      test_suite='mypackage.tests',
      ...
    )

python setup.py sdist creates a file that includes only the source modules from top-level mypackage and not mypackage.tests nor any other submodules.

What am I doing wrong?

Using python 2.7

Asked By: user1561108

||

Answers:

Use the find_packages() function:

from setuptools import setup, find_packages

setup(
    # ...
    packages=find_packages(),
)

The function will search for python packages (directories with a __init__.py file) and return these as a properly formatted list. It’ll start in the same dir as the setup.py script but can be given an explicit starting directory instead, as well as exclusion patterns if you need it to skip some things.

Answered By: Martijn Pieters

For people using pure distutils instead of setuptools: you have to pass the list of all packages and subpackages (but not all submodules, they are detected) in the packages parameter.

Answered By: merwok

Just include all your submodules in the packages list:

from setuptools import setup

setup(
      ...
      packages=['mypackage', 'mypackage.tests', 'mypackage.submodules'],
      ...
     )
Answered By: Shengwei Hou
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.