Как указать файлы заголовков в setup.py script для модуля расширения Python?

Как указать файлы заголовков в файле setup.py script для модуля расширения Python? Листинг с исходными файлами, как показано ниже, не работает. Но я не могу понять, где еще их перечислять.

from distutils.core import setup, Extension
from glob import glob

setup(
    name = "Foo",
    version = "0.1.0",
    ext_modules = [Extension('Foo', glob('Foo/*.cpp') + glob('Foo/*.h'))]
)

Ответы

Ответ 1

Добавьте файл MANIFEST.in, кроме setup.py со следующим содержимым:

graft relative/path/to/directory/of/your/headers/

Ответ 2

У меня было так много проблем с setuptools, это даже не смешно. Здесь, как мне пришлось использовать обходной путь для создания рабочего дистрибутива источника с файлами заголовков: я использовал package_data.

Я делюсь этим, чтобы потенциально спасти кого-то еще от обострения. Если вы знаете лучшее рабочее решение, сообщите мне.

Подробнее см. здесь: https://bitbucket.org/blais/beancount/src/ccb3721a7811a042661814a6778cca1c42433d64/setup.py?fileviewer=file-view-default#setup.py-36

    # A note about setuptools: It profoundly BROKEN.
    #
    # - The header files are needed in order to distribution a working
    #   source distribution.
    # - Listing the header files under the extension "sources" fails to
    #   build; distutils cannot make out the file type.
    # - Listing them as "headers" makes them ignored; extra options to
    #   Extension() appear to be ignored silently.
    # - Listing them under setup() "headers" makes it recognize them, but
    #   they do not get included.
    # - Listing them with "include_dirs" of the Extension fails as well.
    #
    # The only way I managed to get this working is by working around and
    # including them as "packaged data" (see {63fc8d84d30a} below). That
    # includes the header files in the sdist, and a source distribution can
    # be installed using pip3 (and be built locally). However, the header
    # files end up being installed next to the pure Python files in the
    # output. This is the sorry situation we're living in, but it works.

В моем проекте OSS есть соответствующий билет: https://bitbucket.org/blais/beancount/issues/72

Ответ 3

Попробуйте заголовки kwarg для настройки(). Я не знаю, что он документирован где угодно, но он работает.

setup(name='mypkg', ..., headers=['src/includes/header.h'])

Ответ 4

Если я правильно помню, вам нужно только указать исходные файлы, и он должен найти/использовать заголовки.

В руководстве по настройкам я вижу что-то в этом уверенном.

"Например, если вашему расширению требуются файлы заголовков в каталоге include под вашим корнем распространения, используйте параметр include_dirs"

Extension('foo', ['foo.c'], include_dirs=['include'])

http://docs.python.org/distutils/setupscript.html#preprocessor-options