Search code examples
pythondjangosetuptoolspypidistribute

How to include package sub-folders in my project distribution?


I have a project with this structure:

SomeProject/
    bin/
    CHANGES.txt
    docs/
    LICENSE.txt
    MANIFEST.in
    README.txt
    setup.py
    someproject/
        __init__.py
        location.py
        utils.py
        static/
            javascript/
                somescript.js

And a "setup.py" as follows:

#!/usr/bin/env python

import someproject
from os.path import exists
try:
    from setuptools import setup, find_packages
except ImportError:
    from distutils.core import setup, find_packages

setup(
    name='django-some-project',
    version=someproject.__version__,
    maintainer='Some maintainer',
    maintainer_email='[email protected]',
    packages=find_packages(),
    include_package_data=True,
    scripts=[],
    url='https://github.com/xxx/some-project',
    license='LICENSE',
    description='Some project description.',
    long_description=open('README.markdown').read() if exists("README.markdown") else "",
    install_requires=[
        "Django >= 1.4.0"
    ],
)

Then, when I upload it using the command:

python setup.py sdist upload

It seems ok, but there is no "static" folder with this "javascript" subfolder in the package. My "setup.py" was inspired on github.com/maraujop/django-crispy-forms that has a similar structure. Any hint on what is wrong on uploading this subfolders?


Solution

  • You should be able to add those files to source distributions by editing the MANIFEST.in file to add a line like:

    recursive-include someproject/static *.js
    

    or just:

    include someproject/static/javascript/*.js
    

    This will be enough to get the files included in source distributions. If the setuptools include_package_data option you're using isn't enough to get the files installed, you can ask for them to be installed explicitly with something like this in your setup.py:

    package_data={'someproject': ['static/javascript/*.js']},