How does setuptools decide which files to keep for sdist/bdist?

大憨熊 提交于 2019-12-08 21:42:32

问题


I'm working on a Python package that uses namespace_packages and find_packages() like so in setup.py:

from setuptools import setup, find_packages
setup(name="package",
    version="1.3.3.7",
    package=find_packages(),
    namespace_packages=['package'], ...)

It isn't in source control because it is a bundle of upstream components. There is no MANIFEST.

When I run python setup.py sdist I get a tarball of most of the files under the package/ directory but any directories that don't contain .py files are left out.

What are the default rules for what setup.py includes and excludes from built distributions? I've fixed my problem by adding a MANIFEST.in with

recursive-include package *

but I would like to understand what setuptools and distutils are doing by default.


回答1:


You need to add a package_data directive. For example, if you want to include files with .txt or .rst extensions:

from setuptools import setup, find_packages
setup(name="package",
    version="1.3.3.7",
    package=find_packages(),
    include_package_data=True,
    namespace_packages=['package'], 
     package_data = {
        # If any package contains *.txt or *.rst files, include them:
        '': ['*.txt', '*.rst']...

)


来源:https://stackoverflow.com/questions/894323/how-does-setuptools-decide-which-files-to-keep-for-sdist-bdist

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