Add Folders And Subfolders Outside Of Main Module Using Setuptools(setup.py)
So it is yet another similar looking but different question than setuptools: adding additional files outside package and Including non-Python files with setup.py. I have structure
Solution 1:
I believe something like the following could get you there:
.
├── data
│ ├── file.txt
│ └── foo
│ ├── bar
│ │ └── file.txt
│ └── file.txt
├── MANIFEST.in
├── setup.cfg
├── setup.py
└── src
└── thing
├── __init__.py
└── nothing
└── __init__.py
MANIFEST.in
# ...
recursive-include data *.txt
setup.py
#!/usr/bin/env python3import pathlib
import setuptools
defmain():
data_packages = [
'thing/{}'.format(p).replace('/', '.')
for p
in pathlib.Path('data').glob('**')
]
packages = setuptools.find_packages(where='src')
package_dir = {
'thing': 'src/thing',
'thing.data': 'data'
}
setuptools.setup(
# see 'setup.cfg'
packages=packages + data_packages,
package_dir=package_dir,
include_package_data=True,
)
if __name__ == '__main__':
main()
The *.txt
are packaged as package data under the thing.data
package of the Python project. The data can be read for example like this:
python3 -c "import pkgutil; print(pkgutil.get_data('thing', 'data/foo/bar/file.txt').decode())"
Post a Comment for "Add Folders And Subfolders Outside Of Main Module Using Setuptools(setup.py)"