How do you add additional files to a wheel?
Have you tried using package_data
in your setup.py
? MANIFEST.in
seems targetted for python versions <= 2.6, I'm not sure if higher versions even look at it.
After exploring https://github.com/pypa/sampleproject, their MANIFEST.in
says:
# If using Python 2.6 or less, then have to include package data, even though
# it's already declared in setup.py
include sample/*.dat
which seems to imply this method is outdated. Meanwhile, in setup.py
they declare:
setup(
name='sample',
...
# If there are data files included in your packages that need to be
# installed, specify them here. If using Python 2.6 or less, then these
# have to be included in MANIFEST.in as well.
include_package_data=True,
package_data={
'sample': ['package_data.dat'],
},
...
)
(I'm not sure why they chose a wildcard in MANIFEST.in
and a filename in setup.py
. They refer to the same file)
Which, along with being simpler, again seems to imply that the package_data
route is superior to the MANIFEST.in
method. Well, unless you have to support 2.6 that is, in which case my prayers go out to you.
Before you make any changes in MANIFEST.in
or setup.py
you must remove old output directories. Setuptools is caching some of the data and this can lead to unexpected results.
rm -rf build *.egg-info
If you don't do this, expect nothing to work correctly.
Now that is out of the way.
If you are building a source distribution (
sdist
) then you can use any method below.If you are building a wheel (
bdist_wheel
), theninclude_package_data
andMANIFEST.in
are ignored and you must usepackage_data
anddata_files
.
INCLUDE_PACKAGE_DATA
This is a good option, but bdist_wheel
does not honor it.
setup(
...
include_package_data=True
)
# MANIFEST.in
include package/data.json
DATA_FILES for non-package data
This is most flexible option because you can add any file from your repo to a sdist
or bdist_wheel
setup(
....
data_files=[
('output_dir',['conf/data.json']),
]
# For sdist, output_dir is ignored!
#
# For bdist_wheel, data.json from conf dir in root of your repo
# and stored at `output_dir/` inside of the sdist package.
)
PACKAGE_DATA for non-python files inside of the package
Similar to above, but for a bdist_wheel
let's you put your data files inside of the package. It is identical for sdist
but has more limitations than data_files
because files can only source from your package subdir.
setup(
...
package_data={'package':'data.json'},
# data.json must be inside of your actual package
)