You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: package-structure-code/complex-python-package-builds.md
+31-3Lines changed: 31 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,12 +8,40 @@ In the future, we want to provide resources for packaging workflows that require
8
8
## Pure Python Packages vs. packages with extensions in other languages
9
9
10
10
You can classify Python package complexity into three general categories. These
11
-
categories can in turn help you select the correct package front-end and
12
-
back-end tools.
11
+
categories can in turn help you select the correct package frontend and
12
+
backend tools.
13
13
14
14
1.**Pure-python packages:** these are packages that only rely on Python to function. Building a pure Python package is simpler. As such, you can chose a tool below that has the features that you want and be done with your decision!
15
15
16
-
2.**Python packages with non-Python extensions:** These packages have additional components called extensions written in other languages (such as C or C++). If you have a package with non-python extensions, then you need to select a build back-end tool that allows you to add additional build steps needed to compile your extension code. Further, if you wish to use a front-end tool to support your workflow, you will need to select a tool that supports additional build setups. In this case, you could use setuptools. However, we suggest that you chose build tool that supports custom build steps such as Hatch with Hatchling or PDM. PDM is an excellent choice as it allows you to also select your build back-end of choice. We will discuss this at a high level on the complex builds page.
16
+
2.**Python packages with non-Python extensions:** These packages have additional components called extensions written in other languages (such as C or C++). If you have a package with non-Python extensions, then you need to select a build backend tool that allows additional build steps needed to compile your extension code. Further, if you wish to use a frontend tool to support your workflow, you will need to select a tool that supports additional build setups. We suggest that you chose build tool that supports custom build steps like Hatch.
17
17
18
18
3.**Python packages that have extensions written in different languages (e.g. Fortran and C++) or that have non Python dependencies that are difficult to install (e.g. GDAL)** These packages often have complex build steps (more complex than a package with just a few C extensions for instance). As such, these packages require tools such as [scikit-build](https://scikit-build.readthedocs.io/en/latest/)
19
19
or [meson-python](https://mesonbuild.com/Python-module.html) to build. NOTE: you can use meson-python with PDM.
20
+
21
+
## Mixing frontend and backend projects
22
+
23
+
It is sometimes necessary or desirable to use a build frontend with an alternative build-backend.
24
+
This is because some frontends do not have a default backend (`build`), and this choice is placed on the maintainer.
25
+
Other backends (`hatch`) have a preferred backend (`hatchling`) but allow the maintainer to migrate to another, while
26
+
some backends (`poetry`) only work with a single backend (`poetry-core`). Refer to (#python-package-build-tools) for
27
+
more information about frontend and backend compatibility.
28
+
29
+
In this packaging guide we recommend using `hatch` along with its preferred backend `hatchling`. While this will be
30
+
suitable for most packages, an alternate backend may be used with Hatch if needed when creating an extension module.
31
+
A Python extension module is one that is made up, either in part or entirely, of compiled code. In this case the
32
+
backend chosen (such as `meson-python`) must know how to compile the extension language and bind it to Python.
33
+
`hatchling` does not know how to do this all on its own and must either make use of
34
+
[plugins](https://hatch.pypa.io/1.9/plugins/about/) or be replaced by a backend that is already capable of building
35
+
extension modules.
36
+
37
+
In order to use a different backend you will need to edit your project's `pyproject.toml`. If you have a
38
+
`pyproject.toml` generated by the `hatch` command, or from following the packaging tutorial, you may have
Copy file name to clipboardExpand all lines: package-structure-code/python-package-build-tools.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -344,7 +344,7 @@ as building your documentation locally. This means that you could potentially dr
344
344
:widths: 20,5,50
345
345
:delim: "|"
346
346
347
-
Use Other Build Backends|✅ | Switching out build back-ends is not currently an option with Hatch. However, this feature is planned for a future release.
347
+
Use Other Build Backends|✅ | Hatch is used with the backend Hatchling by default, but allows you to use another backend by switching the declaration in pyproject.toml.
348
348
Dependency management|✖| Currently you have to add dependencies manually with Hatch. However a feature to support dependencies management may be added in a future release.
349
349
Environment Management |✅ | Hatch supports Python virtual environments. If you wish to use other types of environments such as Conda, you will need to [install a plugin such as hatch-conda for conda support](https://github.com/OldGrumpyViking/hatch-conda).
350
350
Publish to PyPI and test PyPI|✅|Hatch supports publishing to both test PyPI and PyPI
@@ -355,7 +355,7 @@ Install your package in editable mode|✅| Hatch will install your package into
355
355
Build your sdist and wheel distributions|✅| Hatch will build the sdist and wheel distributions
356
356
✨Matrix environment creation to support testing across Python versions✨|✅| The matrix environment creation is a feature that is unique to Hatch in the packaging ecosystem. This feature is useful if you wish to test your package locally across Python versions (instead of using a tool such as tox).
357
357
✨[Nox / MAKEFILE like functionality](https://hatch.pypa.io/latest/environment/#selection)✨| ✅| This feature is also unique to Hatch. This functionality allows you to create workflows in the **pyproject.toml** configuration to do things like serve docs locally and clean your package build directory. This means you may have one less tool in your build workflow.
358
-
✨A flexible build back-end: **hatchling**✨| ✅| **The hatchling build back-end offered by the maintainer of Hatch allows developers to easily build plugins to support custom build steps when packaging.
358
+
✨A flexible build backend: **hatchling**✨| ✅| **The hatchling build backend offered by the maintainer of Hatch allows developers to easily build plugins to support custom build steps when packaging.
0 commit comments