Python 打包:从 bdist_wheel 中排除目录

Python packaging: exclude directory from bdist_wheel

我有以下项目结构:

.
├── docs
├── examples
├── MANIFEST.in
├── README.rst
├── setup.cfg
├── setup.py
└── myproject

我想将我的项目打包成一个轮子。为此,我使用以下 setup.py:

#!/usr/bin/env python

from setuptools import setup, find_packages

setup(name='myproject',
      version='1.0',
      description='Great project'
      long_description=open('README.rst').read(),
      author='Myself'
      packages=find_packages(exclude=['tests','test','examples'])
     )

当运行python setup.py bdist_wheel时,examples目录包含在轮子中。我该如何防止这种情况?

根据

Excluding a top-level directory from a setuptools package

我希望 examples 被排除在外。

我通过使用后缀星 examples* 解决了这个问题,即:

find_packages(exclude=['*tests','examples*'])

(注意我写的是'*tests'带星号,因为我在每个代码包里都有测试包,如myproject.mypackage.tests。不知何故后缀的星号似乎没有必要,如果有的话已经是前缀了)