Как указать заголовочные файлы в скрипте setup.py для модуля расширения Python? - PullRequest
21 голосов
/ 09 июля 2011

Как мне указать заголовочные файлы в скрипте setup.py для модуля расширения 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'))]
)

Ответы [ 4 ]

15 голосов
/ 13 июля 2011

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

graft relative/path/to/directory/of/your/headers/
5 голосов
/ 15 февраля 2016

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

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

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

    # A note about setuptools: It's 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()'s "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 голосов
/ 24 января 2012

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

setup(name='mypkg', ..., headers=['src/includes/header.h'])
3 голосов
/ 09 июля 2011

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

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

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

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

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

...