From 2dff49c420b27baf6a6dce30891237b9485bfd81 Mon Sep 17 00:00:00 2001 From: "Andrew J. Hesford" Date: Wed, 2 Dec 2020 22:20:18 -0500 Subject: [PATCH] build-style/python3-pep517: new style for PEP517 Python packages --- Manual.md | 27 +++++++++++----- common/build-style/python3-pep517.sh | 31 +++++++++++++++++++ .../environment/build-style/python3-pep517.sh | 2 ++ 3 files changed, 52 insertions(+), 8 deletions(-) create mode 100644 common/build-style/python3-pep517.sh create mode 100644 common/environment/build-style/python3-pep517.sh diff --git a/Manual.md b/Manual.md index 7647f957129..0a3c759f59b 100644 --- a/Manual.md +++ b/Manual.md @@ -561,17 +561,22 @@ phase if `${build_style}` is set to `configure`, `gnu-configure` or `gnu-makefile` build methods. By default set to `PREFIX=/usr DESTDIR=${DESTDIR}`. -- `make_build_target` The target to be passed in to `${make_cmd}` at the build phase if -`${build_style}` is set to `configure`, `gnu-configure` or `gnu-makefile` -build methods. Unset by default (`all` target). +- `make_build_target` The build target. If `${build_style}` is set to `configure`, `gnu-configure` +or `gnu-makefile`, this is the target passed to `${make_cmd}` in the build phase; when unset, it +defaults to `all`. If `${build_style}` is `python3-pep517`, this is the path of the package +directory that should be built as a Python wheel; when unset, defaults to `.` (the current +directory with respect to the build). - `make_check_target` The target to be passed in to `${make_cmd}` at the check phase if `${build_style}` is set to `configure`, `gnu-configure` or `gnu-makefile` build methods. By default set to `check`. -- `make_install_target` The target to be passed in to `${make_cmd}` at the `install-destdir` phase -if `${build_style}` is set to `configure`, `gnu-configure` or `gnu-makefile` -build methods. By default set to `install`. +- `make_install_target` The installation target. When `${build_style}` is set to `configure`, +`gnu-configure` or `gnu-makefile`, this is the target passed to `${make_command}` in the install +phase; when unset, it defaults to `install`. If `${build_style}` is `python-pep517`, this is the +path of the Python wheel produced by the build phase that will be installed; when unset, the +`python-pep517` build style will look for a wheel matching the package name and version in the +current directory with respect to the install. - `patch_args` The arguments to be passed in to the `patch(1)` command when applying patches to the package sources during `do_patch()`. Patches are stored in @@ -952,8 +957,8 @@ via `make_install_target`. via `configure_args`, the meson command can be overridden by `meson_cmd` and the location of the out of source build by `meson_builddir` -For packages that use the Python module build method (`setup.py`), you -can choose one of the following: +For packages that use the Python module build method (`setup.py` or +[PEP 517](https://www.python.org/dev/peps/pep-0517/)), you can choose one of the following: - `python-module` to build *both* Python 2.x and 3.x modules @@ -961,6 +966,9 @@ can choose one of the following: - `python3-module` to build Python 3.x only modules +- `python3-pep517` to build Python 3.x only modules that provide a PEP 517 build description without +a `setup.py` script + Environment variables for a specific `build_style` can be declared in a filename matching the `build_style` name, Example: @@ -1482,6 +1490,9 @@ be your guidance to decide whether or not to split off a `-doc` subpackage. Python packages should be built with the `python{,2,3}-module` build style, if possible. This sets some environment variables required to allow cross compilation. Support to allow building a python module for multiple versions from a single template is also possible. +The `python3-pep517` build style provides means to build python packages that provide a build-system +definition compliant with [PEP 517](https://www.python.org/dev/peps/pep-0517/) without a traditional +`setup.py` script. Python packages that rely on `python3-setuptools` should generally map `setup_requires` dependencies in `setup.py` to `hostmakedepends` in the template and `install_requires` diff --git a/common/build-style/python3-pep517.sh b/common/build-style/python3-pep517.sh new file mode 100644 index 00000000000..1a3c6d31eed --- /dev/null +++ b/common/build-style/python3-pep517.sh @@ -0,0 +1,31 @@ +# +# This style is for templates installing python3 modules adhering to PEP517 +# + +do_build() { + # No PEP517 build tool currently supports compiled extensions + # Thus, there is no need to accommodate cross compilation here + : ${make_build_target:=.} + + mkdir -p build + TMPDIR=build python3 -m pip wheel --no-deps --use-pep517 --no-clean \ + --no-build-isolation ${make_build_args} ${make_build_target} +} + +do_check() { + if python3 -m pytest --help >/dev/null 2>&1; then + python3 -m pytest ${make_check_args} ${make_check_target} + else + msg_warn "Unable to determine tests for PEP517 Python templates" + return 0 + fi +} + +do_install() { + # As with do_build, no need to accommodate cross compilation here + : ${make_install_target:=${pkgname#python3-}-${version}-*-*-*.whl} + + TMPDIR=build python3 -m pip install --use-pep517 --prefix /usr \ + --root ${DESTDIR} --no-deps --no-build-isolation \ + --no-clean ${make_install_args} ${make_install_target} +} diff --git a/common/environment/build-style/python3-pep517.sh b/common/environment/build-style/python3-pep517.sh new file mode 100644 index 00000000000..48f0c1b17f4 --- /dev/null +++ b/common/environment/build-style/python3-pep517.sh @@ -0,0 +1,2 @@ +hostmakedepends+=" python3-pip" +lib32disabled=yes