Python package data¶
Further down is a minimal example showing how to achieve both:
packaging a data file
file.srcinsdistonly;and packaging another data file
file.bininbdistonly;additionally it shows how
file.allis packaged in both distribution packages andfile.notin none of them.
The gist of it is:
first and foremost, always thoroughly clean up the working directory between two packaging attempts while tweaking these packaging options (in particular empty the
src/Thing.egg-infodirectory containing theSOURCES.txtfile as well as thebuild, anddistdirectories) or the results will be inconsistent;set the
include_package_dataoption toTrue;file.alland files that belong in bothsdistandbdistare specified inMANIFEST.in;file.binand files that belong inbdistonly are specified inpackage_data;file.srcand files that belong insdistonly are specified in bothMANIFEST.inandexclude_package_data;file.notand files that do not belong in any distribution package are not specified anywhere.
The directory structure for our example:
.
├ MANIFEST.in
├ setup.py
└ src
└ thing
├ __init__.py
└ data
├ file.all
├ file.bin
├ file.not
└ file.src
In MANIFEST.in:
recursive-include src/thing *.all
recursive-include src/thing *.src
In setup.py:
#!/usr/bin/env python3
import setuptools
setuptools.setup(
exclude_package_data={'thing': ['data/*.src']},
include_package_data=True,
package_data={'thing': ['data/*.bin']},
#
name='Thing',
version='1.0.0',
#
package_dir={'': 'src'},
packages=setuptools.find_packages(where='src'),
)
This has been tested with:
Python 3.6.7
setuptools 39.0.1
wheel 0.33.1