Skip to content
Advertisement

How can I include package_data without a MANIFEST.in file?

How can I include package_data for sdist without a MANIFEST.in file?

My setup.py looks like this:

import setuptools

setuptools.setup(
    name='foo',
    version='2015.3',
    license='commercial',
    packages=setuptools.find_packages(),

    package_data={'': ['foo/bar.txt']},
)

Versions:

user@host> python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
>>> import setuptools
>>> setuptools.version.__version__
'3.6'

I just can’t get foo/bar.txt included.

Or is this blog post still true? http://blog.codekills.net/2011/07/15/lies,-more-lies-and-python-packaging-documentation-on–package_data-/

Over the last hour, though, I’ve learned that these statements are somewhere between “dangerously misleading” and “damn lies”. This is because the primary type of Python package is a source package, and the canonical method for creating a source package is by using setup.py sdist. However, the data specified in package_data are not included in source distributions — they are only included in binary (setup.py bdist) distributions and installs (setup.py install).

How can I include package_data for sdist without a MANIFEST.in file?

Advertisement

Answer

TL;DR: The keys in the package_data dictionaries are packages; the values are lists of globs. '' is not a valid name for any Python package.

If you want to have bar.txt be installed next to the __init__.py of package foo, use

 package_data={'foo': ['bar.txt']}

I have the layout:

foo/
        __init__.py
        bar.txt
setup.py

Now, if foo is a package like above, do:

import setuptools

setuptools.setup(
    name='foo',
    version='2015.3',
    license='commercial',
    packages=setuptools.find_packages(),
    package_data={'foo': ['bar.txt']},
)

And after python setup.py sdist, I check the contents of dist/foo-2015.3.tar.gz

% tar tfz dist/foo-2015.3.tar.gz
...
foo-2015.3/foo/bar.txt
...

However, if I run your setup.py with package_data={'': ['foo/bar.txt']}, I can concur that the foo/bar.txt will not be added to the source distribution, except if the foo-2015.3.egg-info/SOURCES.txt already has the line for foo/bar.txt – in that case the file will pop up in the source distribution too

No manifest was used; the setuptools version was 3.6 (I deliberately installed the same, old version that you were using):

>>> import setuptools
>>> setuptools.__version__
'3.6'

The behaviour above also works in standard distutils: 2.6 Installing package data of the “legacy” distutils documentation; with a comment for 2.7, 3.1:

Changed in version [2.7, 3.1]: All the files that match package_data will be added to the MANIFEST file if no template is provided.

Advertisement