Package: pybuild-header-dependency
pybuild-header-dependencypybuild-header-dependencyis a helper package to resolve C/C++ header-only libraries for Python build with native extensions.Why this project?Are you developing a Python project with C/C++ extensions? You are likely to have some dependencies on C/C++ libraries. Managing C/C++ dependencies can be tricky in this case becausesetuptools, the standard build system for Python extension module, does not have a proper package management for C/C++ libraries.In many cases, your C/C++ dependencies are header-only libraries. You need to then tellsetuptoolsthe path to the needed header files. Some header-only libraries, e.g.pybind11, are directly installable from PyPI and you can resolve the header location by calling the functionget_include. This is however not universally applicable for all header-only libraries.This project is a helper package aiming to facilitate the build process by automatically downloading the needed C/C++ header-only libraries and providing a include path to the build system (setuptools).Alternatives to this projectpybind11also provides a way to build C/C++ extensions using fullcmakebuild system. In this way, all the C/C++ dependencies can be resolved incmake. Please refer to theirdocumentation. This project, however, aims at the developers usingsetuptoolsto build the extensions.InstallationYou rarely need to install it manually. If you do, you can directly install it from PyPI:pipinstallpybuild-header-dependencyUsageThe usage below is under the assumption that you develop your project according toPEP518withpyproject.toml.Build dependencySpecifypybuild-header-dependencyas a build dependency in yourpyproject.toml. It should include something like below:[build-system]requires=["setuptools","wheel","pybuild-header-dependency"# your other Python build dependencies]build-backend="setuptools.build_meta"Get headersTo resolve your needed headers in build time, callpybuild-header-dependencyin yoursetup.py. See below for some clues:fromsetuptoolsimportExtensionfromsetuptoolsimportsetupfrompybuild_header_dependencyimportHeaderResolver# resolve your C/C++ header-only dependenciesresolver=HeaderResolver({"eigen":None,# None as latest version"boost":"1.78"# pinned version})# define an extension moduleext=Extension(include_dirs=[str(resolver.get_include())],# your other extension configurations)# begin buildsetup(ext_modules=[ext],# your other package configurations)You can look atpkg.jsonfor supported header-only libraries.BuildOnce you configure your project as above, you should be able to build it without any C/C++ packages or packages managers installed.pipwheel-wdist--no-deps.The build process will download the necessary header files automatically.LimitationAs the name of this project suggests, this project supports header-only C/C++ libraries.
If you project depends on some static/dynamic libraries, you need to use a full build system likecmake.The default way of downloading packages from GitLab/GitHub is based on releases. You can of course make a custom downloader.LicenseThis project is licensed under the BSD-3-Clause license, seeLICENSEfor details.Licenses of the librariesEach supported head-only library is licensed under its own terms. Please consult them individually.ContributionYou are more than welcome to make contributions to this project.
Please have a look at thepkg.jsonfor
some examples about how to add new packages.
Also refer toboost.pyfor
an example of custom downloader.