setuptools icon indicating copy to clipboard operation
setuptools copied to clipboard

Automatically include headers in sdist

Open anntzer opened this issue 8 years ago • 3 comments

Currently, sdists do not automatically include headers for extension modules. However, the information of headers is in fact already present and could easily be added: it is (or rather, should be) included in the depends field of the Extension objects (https://docs.python.org/3.6/distutils/apiref.html?highlight=depends#distutils.core.Extension), as one will usually want to recompile the extension if one of the headers is changed (just as one wants to recompile the extension if one of the source files is changed).

Adding

            self.filelist.extend(depend
                                 for ext in build_ext.extensions
                                 for depend in ext.depends)

in py36compat's _add_defaults_ext is sufficient to obtain the desired behavior.

Note the comment in the docstring of add_defaults:

          - all C sources listed as part of extensions or C libraries
            in the setup script (doesn't catch C headers!)

anntzer avatar Oct 01 '17 23:10 anntzer

In the docstring for that class, it mentions "Do not edit the code in this class except to update functionality as implemented in distutils. Instead, override in the subclass." That class is there to provide forward compatibility on older Pythons.

So the question is - should setuptools provide this additional functionality on its own, or should the additional functionality first be added to CPython and then back-ported by setuptools?

My preference would be the latter.

jaraco avatar Oct 25 '17 16:10 jaraco

Lots of people have trouble with this issue.

  • https://stackoverflow.com/questions/6633624/how-to-specify-header-files-in-setup-py-script-for-python-extension-module

  • https://bitbucket.org/blais/beancount/src/ccb3721a7811a042661814a6778cca1c42433d64/setup.py?fileviewer=file-view-default#setup.py-36

  • https://github.com/pypa/packaging-problems/issues/84

I think the community would greatly appreciate a fix to this, in setuptools rather than waiting for distutils to do something about it.

jbarlow83 avatar Nov 08 '17 07:11 jbarlow83

adding MANIFEST.in file helps, I also struggled with this a lot

ionutmodo avatar Jun 12 '24 23:06 ionutmodo