Is it possible to configure setup.py so that package data are included recursively?
For example, is there an equivalent of this:
setup(...,
packages=['mypkg'],
package_data={'mypkg': ['data/*.dat']},
)
which just specifies the folder (perhaps with some extra option)?
setup(...,
packages=['mypkg'],
package_data={'mypkg': ['data']},
)
Examples taken from:
https://docs.python.org/2/distutils/setupscript.html#installing-package-data
As pointed out by @AndriiZymohliad in the comments, the recursive globs are not supported by setuptools. You have to resolve the files programmatically. Example using pathlib:
from pathlib import Path
datadir = Path(__file__).parent / 'mypkg' / 'data'
files = [str(p.relative_to(datadir)) for p in datadir.rglob('*.dat')]
setup(
...,
packages=['mypkg'],
package_data={'mypkg': files},
)
Use shell globs:
setup(
...,
packages=['mypkg'],
package_data={'mypkg': ['data/*.dat', 'data/**/*.dat']},
)
data/*.dat will include all .dat files placed directly in data, but not in subdirectories. data/**/*.dat will include all .dat files placed in any of the subdirectories of data (so it will include data/spam/file.dat and data/spam/eggs/other.dat etc), but it will not include any .dat files placed directly in data. Both globs are thus mutually exclusive; this is why you always need to provide both globs if you want to include any .dat file under data.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With