|
| 1 | +# Complex Python package builds |
| 2 | + |
| 3 | + |
| 4 | +* link to ralf's blog and book on complex builds |
| 5 | +* keep this page high level so we don't get weight downsides |
| 6 | +* can use the examplePy repo stefan and I are working on that will test various build combinations |
| 7 | + |
| 8 | + |
| 9 | + |
| 10 | + |
| 11 | +* pdm, hatch and poetry all have "ways" of supporting c extensions via pdm-build, hatchling and poetry's build back end. |
| 12 | +* poetry's support for C extensions is not fully developed and documented (yet). * Poetry doesn't offer a way to facilitate "communication" between poetry front end and another back end like meson to build via a build hook. so while some have used it with other back end builds it's not ideal for this application |
| 13 | +* pdm and poetry both rely on setuptools for C extensions. pdm's support claims to be fully developed and documented. poetry claims nothing, and doesn't document it. |
| 14 | +* hatch both offers a plugin type approach to support custom build steps |
| 15 | +PDM (right now) is the only tool that supports other back ends (hatch is working on this - 2 minor releases away) |
| 16 | +At some point a build becomes so complex that you need to use a tool like scikit or meson to support that complexity. |
| 17 | + |
| 18 | + |
| 19 | + |
| 20 | +**Setuptools** is the oldest tool in the above list. While it doesn't have a |
| 21 | +friendly user front end, because "OG" tool that has been used for Python packaging for over a decade, we discuss it here. |
| 22 | + |
| 23 | +**Hatch** and PDM are newer, more modern tool that support customization of any |
| 24 | +part of your packaging steps. These tools also support some C and C++ |
| 25 | +extensions. |
| 26 | + |
| 27 | + |
| 28 | + |
| 29 | +<!-- TODO: add - compatible with other build back ends eg pdm can work with hatchling |
| 30 | +
|
| 31 | +Eli: |
| 32 | +poetry: supports it, but is undocumented and uses setuptools under the hood, they plan to change how this works and then document it |
| 33 | +pdm-backend: supports it, and documents it -- and also uses setuptools under the hood |
| 34 | +hatchling: permits you to define hooks for you to write your own custom build steps, including to build C++ extensions |
| 35 | +
|
| 36 | +--> |
| 37 | + |
| 38 | + |
| 39 | + |
| 40 | +<!-- from eli about pdm |
| 41 | +It would be more accurate to say that PDM supports using PDM and setuptools at the same time, so you run setuptools to produce the C extensions and then PDM receives the compiled extension files (.so, .pyd) and packages it up alongside the pure Python files. |
| 42 | +
|
| 43 | +Comment about hatch. |
| 44 | +https://github.com/pyOpenSci/python-package-guide/pull/23#discussion_r1081108118 |
| 45 | +
|
| 46 | +From ralf: There are no silver bullets here yet, no workflow tool is complete. Both Hatch and PDM are single-author tools, which is another concern. @eli-schwartz's assessment is unfortunately correct here I believe (at a high level at least, not sure about details). Hatch has the worst take on building compiled code by some distance. Unless its author starts developing an understanding of build systems / needs, and implements support for PEP 517 build backend hooks in pyproject.toml, it's pretty much a dead end. |
| 47 | +
|
| 48 | +--> |
| 49 | + |
| 50 | +<!--TODO Add examples of builds using each of the tools below? |
| 51 | +
|
| 52 | +pdm, hatch and poetry all have "ways" of supporting c extensions via pdm-build, hatchling and poetry's build back end. |
| 53 | +poetry's support for C extensions is not fully developed and documented (yet). Poetry doesn't offer a way to facilitate "communication" between poetry front end and another back end like meson to build via a build hook. |
| 54 | +PDM and hatch both offer a plugin type approach to support custom build steps |
| 55 | +PDM (right now) is the only tool that supports other back ends (hatch is working on this - 2 minor releases away) |
| 56 | +At some point a build becomes so complex that you need to use a tool like scikit or meson to support that complexity. |
| 57 | +
|
| 58 | +CORRECTIONS: |
| 59 | +pdm doesn't use plugins. Hatch does. |
| 60 | +pdm and poetry both rely on setuptools for C extensions. pdm's support claims to be fully developed and documented. poetry claims nothing, and doesn't document it. |
| 61 | +
|
| 62 | +--> |
| 63 | + |
| 64 | +```{note} |
| 65 | +?? |
| 66 | +Poetry supports extensions written in other languages but this functionality is |
| 67 | +currently undocumented. |
| 68 | +
|
| 69 | +Tools such as Setuptools, PDM, Hatch and Poetry all have some level of support |
| 70 | +for C and C++ extensions. |
| 71 | +Some Python packaging tools, |
| 72 | +such as **Flit** and the **flit-core** build back-end only support pure-Python |
| 73 | +package builds. |
| 74 | +Some front-end packaging tools, such as PDM, allow you to use other |
| 75 | +build back-ends such as **meson** and **scikit-build**. |
| 76 | +
|
| 77 | +``` |
0 commit comments