Setup.py - Add data files inside package in setuptools

Viewed 623

everyone! Jumping to my issue, I have this file structure, in Python 3.7:

mypackage/
 |- config/
 |---- config.json
 |- mypackage/
 |---- __init__.py
 |---- main.py
 |- docs/
 |---- __init__.py
 |---- doc_folder/
 |--------- text_file.txt
 |- setup.py
 |- MANIFEST.in

My setup.py is using setuptools and has, of relevance:

setup(
    name='mypackage',
    version='1.0',
    packages=find_packages(),
    include_package_data=True
)

And my MANIFEST.in has:

recursive-include config *
recursive-include docs *

When I either run pip install . or python setup.py sdist & pip install dist/mypackage-1.0, the same thing happens:

  • When the distribution is built, the logs say both docs and config are copied into mypackage-1.0;
  • When installed, I can't find config;
  • When installed, docs is found in the site-packages folder (site-packages/docs).
  • If i add an __init__.py to config, it also appears in the site-packages folder. My objective would be to have docs and config inside of the mypackage directory, because I'm afraid if I pip install different projects with config folders, they're going to override each other. It'll also be more useful to do relative imports, I assume.

What do you guys think?

1 Answers

Moving both config and doc dirs under mypackage (the one that is actually a package, containing an __init__.py) should fix the issue. The changed directory structure from the question:

mypackage/
├── mypackage/
│   ├── __init__.py
|   ├── config/
|   |   └── config.json
|   ├── docs/
|   |   ├── __init__.py
|   |   └── doc_folder/
|   |       └── text_file.txt
|   └── main.py
├── setup.py
└── MANIFEST.in
Related