public inbox for gentoo-dev@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Michał Górny" <mgorny@gentoo.org>
To: gentoo-dev@lists.gentoo.org
Cc: "Michał Górny" <mgorny@gentoo.org>
Subject: [gentoo-dev] [PATCH 08/11] distutils-r1.eclass: Invert DISTUTILS_USE_PEP517 - backend mapping
Date: Tue, 25 Mar 2025 21:16:13 +0100	[thread overview]
Message-ID: <20250325202258.261756-9-mgorny@gentoo.org> (raw)
In-Reply-To: <20250325202258.261756-1-mgorny@gentoo.org>

Invert the eclass logic to map DISTUTILS_USE_PEP517 values to backends
rather than the other way around.  This is in preparation for making
it possible to override the backend used.  One side effect of this
is that in case of DISTUTILS_USE_PEP517 mismatch, we no longer provide
the "correct" value, and only indicate the backend used upstream.

Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
 eclass/distutils-r1.eclass | 122 +++++++++++++++++--------------------
 1 file changed, 56 insertions(+), 66 deletions(-)

diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index 2eb6e3208082..0ab42eba1f24 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -1064,58 +1064,57 @@ _distutils-r1_copy_egg_info() {
 	find -name '*.egg-info' -type d -exec cp -R -p {} "${BUILD_DIR}"/ ';' || die
 }
 
-# @FUNCTION: _distutils-r1_backend_to_key
-# @USAGE: <backend>
+# @FUNCTION: _distutils-r1_key_to_backend
+# @USAGE: <key>
 # @INTERNAL
 # @DESCRIPTION:
-# Print the DISTUTILS_USE_PEP517 value corresponding to the backend
-# passed as the only argument.
-_distutils-r1_backend_to_key() {
+# Print the backend corresponding to the DISTUTILS_USE_PEP517 value.
+_distutils-r1_key_to_backend() {
 	debug-print-function ${FUNCNAME} "$@"
 
-	local backend=${1}
-	case ${backend} in
-		flit_core.buildapi|flit.buildapi)
-			echo flit
+	local key=${1}
+	case ${key} in
+		flit)
+			echo flit_core.buildapi
 			;;
-		flit_scm:buildapi)
-			echo flit_scm
+		flit_scm)
+			echo flit_scm:buildapi
 			;;
-		hatchling.build)
-			echo hatchling
+		hatchling)
+			echo hatchling.build
 			;;
-		jupyter_packaging.build_api)
-			echo jupyter
+		jupyter)
+			echo jupyter_packaging.build_api
 			;;
 		maturin)
 			echo maturin
 			;;
-		mesonpy)
-			echo meson-python
+		meson-python)
+			echo mesonpy
 			;;
-		pbr.build)
-			echo pbr
+		pbr)
+			echo pbr.build
 			;;
-		pdm.backend|pdm.pep517.api)
-			echo pdm-backend
+		pdm-backend)
+			echo pdm.backend
 			;;
-		poetry.core.masonry.api|poetry.masonry.api)
-			echo poetry
+		poetry)
+			echo poetry.core.masonry.api
 			;;
-		scikit_build_core.build)
-			echo scikit-build-core
+		scikit-build-core)
+			echo scikit_build_core.build
 			;;
-		setuptools.build_meta|setuptools.build_meta:__legacy__)
-			echo setuptools
+		setuptools)
+			echo setuptools.build_meta
 			;;
-		sipbuild.api)
-			echo sip
+		sip)
+			echo sipbuild.api
 			;;
-		uv_build|uv)
-			echo uv-build
+		uv-build)
+			echo uv_build
 			;;
 		*)
-			die "Unknown backend: ${backend}"
+			die "Unknown DISTUTILS_USE_PEP517 key: ${key}"
 			;;
 	esac
 }
@@ -1150,48 +1149,39 @@ _distutils-r1_get_backend() {
 		return
 	fi
 
-	# verify whether DISTUTILS_USE_PEP517 was set correctly
-	local expected_value=$(_distutils-r1_backend_to_key "${build_backend}")
-	if [[ ${DISTUTILS_USE_PEP517} != ${expected_value} ]]; then
-		eerror "DISTUTILS_USE_PEP517 does not match pyproject.toml!"
-		eerror "    have: DISTUTILS_USE_PEP517=${DISTUTILS_USE_PEP517}"
-		eerror "expected: DISTUTILS_USE_PEP517=${expected_value}"
-		eerror "(backend: ${build_backend})"
-		die "DISTUTILS_USE_PEP517 value incorrect"
-	fi
-
-	# fix deprecated backends up
-	local new_backend=
-	case ${build_backend} in
-		flit.buildapi)
-			new_backend=flit_core.buildapi
-			;;
-		pdm.pep517.api)
-			new_backend=pdm.backend
-			;;
-		poetry.masonry.api)
-			new_backend=poetry.core.masonry.api
-			;;
-		setuptools.build_meta:__legacy__)
-			# this backend should only be used as implicit fallback
-			new_backend=setuptools.build_meta
-			;;
-		uv)
-			new_backend=uv_build
-			;;
-	esac
+	# get the preferred backend from the eclass
+	local backend_to_use=$(_distutils-r1_key_to_backend "${DISTUTILS_USE_PEP517}")
+	if [[ ${backend_to_use} != ${build_backend} ]]; then
+		# special-case deprecated backends
+		case ${build_backend} in
+			flit.buildapi)
+				;;
+			pdm.pep517.api)
+				;;
+			poetry.masonry.api)
+				;;
+			setuptools.build_meta:__legacy__)
+				;;
+			uv)
+				;;
+			*)
+				eerror "DISTUTILS_USE_PEP517 does not match pyproject.toml!"
+				eerror "  DISTUTILS_USE_PEP517=${DISTUTILS_USE_PEP517}"
+				eerror "  implies backend: ${backend_to_use}"
+				eerror "   pyproject.toml: ${build_backend}"
+				die "DISTUTILS_USE_PEP517 value incorrect"
+		esac
 
-	if [[ -n ${new_backend} ]]; then
+		# if we didn't die, we're dealing with a deprecated backend
 		if [[ ! -f ${T}/.distutils_deprecated_backend_warned ]]; then
 			eqawarn "${build_backend} backend is deprecated.  Please see:"
 			eqawarn "https://projects.gentoo.org/python/guide/qawarn.html#deprecated-pep-517-backends"
-			eqawarn "The eclass will be using ${new_backend} instead."
+			eqawarn "The eclass will be using ${backend_to_use} instead."
 			> "${T}"/.distutils_deprecated_backend_warned || die
 		fi
-		build_backend=${new_backend}
 	fi
 
-	echo "${build_backend}"
+	echo "${backend_to_use}"
 }
 
 # @FUNCTION: distutils_wheel_install


  parent reply	other threads:[~2025-03-25 20:35 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-25 20:16 [gentoo-dev] [PATCH 00/11] distutils-r1.eclass: uv-build support, setuptools build dir fixes, PEP517 backend override support Michał Górny
2025-03-25 20:16 ` [gentoo-dev] [PATCH 01/11] distutils-r1.eclass: Bump build system lower bounds Michał Górny
2025-03-25 20:16 ` [gentoo-dev] [PATCH 02/11] distutils-r1.eclass: Set FLIT_ALLOW_INVALID Michał Górny
2025-03-25 20:16 ` [gentoo-dev] [PATCH 03/11] dev-python/uv-build: New package, v0.6.9 Michał Górny
2025-03-25 20:16 ` [gentoo-dev] [PATCH 04/11] distutils-r1.eclass: Support uv-build backend Michał Górny
2025-03-25 20:16 ` [gentoo-dev] [PATCH 05/11] distutils-r1.eclass: Support the legacy "uv" backend too Michał Górny
2025-03-25 20:16 ` [gentoo-dev] [PATCH 06/11] distutils-r1.eclass: Use unique setuptools build directories Michał Górny
2025-03-25 20:16 ` [gentoo-dev] [PATCH 07/11] distutils-r1.eclass: Reflow _distutils-r1_backend_to_key() Michał Górny
2025-03-25 20:16 ` Michał Górny [this message]
2025-03-25 20:16 ` [gentoo-dev] [PATCH 09/11] distutils-r1.eclass: Support overriding PEP517 build backend Michał Górny
2025-03-25 20:16 ` [gentoo-dev] [PATCH 10/11] dev-python/uv-build: Use DISTUTILS_UPSTREAM_PEP517 Michał Górny
2025-03-25 20:16 ` [gentoo-dev] [PATCH 11/11] distutils-r1.eclass: Reflow distutils-r1_python_compile() Michał Górny
2025-03-26  8:27 ` [gentoo-dev] [PATCH 00/11] distutils-r1.eclass: uv-build support, setuptools build dir fixes, PEP517 backend override support Ulrich Müller
2025-03-26  8:30   ` Michał Górny
2025-03-26  8:37     ` Ulrich Müller
2025-03-26  8:41       ` Michał Górny
2025-03-26 11:34 ` [gentoo-dev] [PATCH 12/12] distutils-r1.eclass: Add a safety check for wheel install done Michał Górny

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250325202258.261756-9-mgorny@gentoo.org \
    --to=mgorny@gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox