I have the following project structure I would like to package:
├── doc
│ └── source
├── src
│ ├── core
│ │ ├── config
│ │ │ └── log.tmpl
│ │ └── job
│ ├── scripts
│ └── test
└── tools
I would like to package core
under src
but exclude test
. Here is what I tried unsuccessfully:
setup(name='core',
version=version,
package_dir = {'': 'src'}, # Our packages live under src but src is not a package itself
packages = find_packages("src", exclude=["test"]), # I also tried exclude=["src/test"]
install_requires=['xmltodict==0.9.0',
'pymongo==2.7.2',
'ftputil==3.1',
'psutil==2.1.1',
'suds==0.4',
],
include_package_data=True,
)
I know I can exclude test
using the MANIFEST.in file, but I would be happy if you could show me how to do this with setup
and find_packages
.
After some more playing around, I realized that building the package with python setup.py install
does what I expected (that is, it excludes test
). However, issuing python setup.py sdist
causes everything to be included (that is, it ignores my exclude directive). I don't know whether it is a bug or a feature, but there is still the possibility of excluding files in sdist
using MANIFEST.in
.
find_packages("src", exclude=["test"])
works.
The trick is to remove stale files such as core.egg-info
directory. In your case you need to remove src/core.egg-info
.
Here's setup.py
I've used:
from setuptools import setup, find_packages
setup(name='core',
version='0.1',
package_dir={'':'src'},
packages=find_packages("src", exclude=["test"]), # <- test is excluded
####packages=find_packages("src"), # <- test is included
author='J.R. Hacker',
author_email='jr@example.com',
url='http://stackoverflow.com/q/26545668/4279',
package_data={'core': ['config/*.tmpl']},
)
To create distributives, run:
$ python setup.py sdist bdist bdist_wheel
To enable the latter command, run: pip install wheel
.
I've inspected created files. They do not contain test
but contain core/__init__.py
, core/config/log.tmpl
files.