setuptools troubles — excluding packages, including data files

烂漫一生 提交于 2019-11-29 03:05:08

You should create a new file called MANIFEST.in in the root level of your package, then follow these instructions:

  1. To control which files end up in your tar file, create a new file called MANIFEST.in in the root level of your package. For example, you can exclude whole directories from your distribution, using recursive-exclude in the MANIFEST.in file. In your case, you need your MANIFEST.in file to contain:

    recursive-exclude tests *
    
  2. It's not common to include README and other files in the site-packages directory, but if you really want to, then go inside package1 and create symbolic links to the files you want to include:

    cd package1
    ln -s ../LICENSE
    ln -s ../README.md
    ln -s ../RELEASE
    

    Then change the following line in your setup.py:

    package_data = {
        '': ['LICENSE', 'README.md', 'RELEASE']
    

    to:

    package_data = {
        'package1': ['LICENSE', 'README.md', 'RELEASE']
    
oby1

find_packages uses fnmatchcase for its exclude filtering. You can test if your exclusion pattern matches a package name as follows:

>>> from fnmatch import fnmatchcase
>>> fnmatchcase('my.package.name.tests', 'tests')
False

Assuming all the tests in your project live in package names ending in tests or subpackages of those packages, the following should suffice to exclude all the test code:

setup(
    name='package1',
    version='1.1',
    packages=find_packages(exclude=['tests', '*.tests', '*.tests.*']),    
)

To also exclude the tests folder from source distributions, add the following to MANIFEST.in:

recursive-exclude tests *
ornoone

if your structure is true:

  1. the tests folder is not a package (it doesn't have the init.py file), so find_package don't exclude it.
  2. include_package_data=True mean that all versionned files will be included if not explicitly excluded .

so : try an exclude tests/* in your MANIFEST.in

I Hope it had helped

MANIFEST.in would take care of it.

prune tests/
include LICENSE  README.md RELEASE

if you have static files to be added, add them with

...
recursive-include package1/static *

I was trying everything and nothing seemed to work, until I deleted the build directory (after seeing another answer mentioning *.egg-info/ directory) and it finally worked. python setup.py clean --all should also do the job.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!