Add a PEP517 mode to the distutils-r1.eclass in order to facilitate
building packages via PEP517 backends. In order to use it, set
DISTUTILS_USE_PEP517 to the appropriate build system name. The eclass
will take care of setting BDEPEND, then invoke the backend to build
a wheel and then install its contents in python_compile(). The install
phase is limited to merging the staging area into the image directory.
In PEP517 mode, the test phase is automatically provided with venv-style
install tree that should suffice the vast majority of test suites.
As a result, distutils_install_for_testing should no longer be necessary
and is not available in this mode.
The new mode can also be used to install pre-PEP517 distutils
and setuptools packages. To do so, just specify setuptools backend.
If pyproject.toml is missing, the eclass assumes legacy setuptools
backend that invokes setup.py. It also enables setuptools-vendored
distutils, effectively carrying the migration from deprecated stdlib
version.
The PEP517 support effectively deprecates the legacy eclass mode.
This follows upstream deprecation of distutils and install commands
in setuptools.
Signed-off-by: Michał Górny
---
eclass/distutils-r1.eclass | 388 -
1 file changed, 298 insertions(+), 90 deletions(-)
Changes in v3: improve esetup.py to work when there's no setup.py
diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index ba0226f8fed3..9e8e566e7d02 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -78,7 +78,35 @@ esac
# to be exported. It must be run in order for the eclass functions
# to function properly.
+# @ECLASS-VARIABLE: DISTUTILS_USE_PEP517
+# @PRE_INHERIT
+# @DEFAULT_UNSET
+# @DESCRIPTION:
+# Enable experimental PEP 517 mode for the specified build system.
+# In this mode, the complete build and install is done
+# in python_compile(), venv-style install tree is provided
+# to python_test() and python_install() just merges the temporary
+# install tree into real fs.
+#
+# The variable specifies the build system used. Currently,
+# the following values are supported:
+#
+# - flit - flit_core backend
+#
+# - pdm - pdm.pep517 backend
+#
+# - poetry - poetry-core backend
+#
+# - setuptools - distutils or setuptools (incl. legacy mode)
+#
+# - standalone - standalone build systems without external deps
+#(used for bootstrapping).
+#
+# The variable needs to be set before the inherit line. The eclass
+# adds appropriate build-time dependencies and verifies the value.
+
# @ECLASS-VARIABLE: DISTUTILS_USE_SETUPTOOLS
+# @DEFAULT_UNSET
# @PRE_INHERIT
# @DESCRIPTION:
# Controls adding dev-python/setuptools dependency. The allowed values
@@ -97,13 +125,13 @@ esac
# (assumes you will take care of doing it correctly)
#
# This variable is effective only if DISTUTILS_OPTIONAL is disabled.
-# It needs to be set before the inherit line.
-: ${DISTUTILS_USE_SETUPTOOLS:=bdepend}
+# It is available only in non-PEP517 mode. It needs to be set before
+# the inherit line.
if [[ ! ${_DISTUTILS_R1} ]]; then
[[ ${EAPI} == 6 ]] && inherit eutils xdg-utils
-inherit multiprocessing toolchain-funcs
+inherit multibuild multiprocessing toolchain-funcs
if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
inherit python-r1
@@ -121,25 +149,61 @@ if [[ ! ${_DISTUTILS_R1} ]]; then
_distutils_set_globals() {
local rdep bdep
- local setuptools_dep='>=dev-python/setuptools-42.0.2[${PYTHON_USEDEP}]'
+ if [[ ${DISTUTILS_USE_PEP517} ]]; then
+ if [[ ${DISTUTILS_USE_SETUPTOOLS} ]]; then
+ die "DISTUTILS_USE_SETUPTOOLS is not used in PEP517
mode"
+ fi
- case ${DISTUTILS_USE_SETUPTOOLS} in
- no|manual)
- ;;
- bdepend)
- bdep+=" ${setuptools_dep}"
- ;;
- rdepend)
- bdep+=" ${setuptools_dep}"
- rdep+=" ${setuptools_dep}"
- ;;
- pyproject.toml)
- bdep+='
>=dev-python/pyproject2setuppy-22[${PYTHON_USEDEP}]'
- ;;
- *)
- die "Invalid
DISTUTILS_USE_SETUPTOOLS=${DISTUTILS_USE_SETUPTOOLS}"
- ;;
- esac
+ # installer is used to install the wheel
+ # tomli is used to read build-backend from pyproject.toml
+ bdep+='
+ >=dev-python/installer-0.4.0_p20220115[${PYTHON_USEDEP}]
+ dev-python/tomli[${PYTHON_USEDEP}]'
+ case ${DISTUTILS_USE_PEP517} in
+ flit)
+ bdep+='
+ dev-python/flit_core[${PYTHON_USEDEP}]'
+ ;;
+ pdm)
+ bdep+='
+