[PATCH 2/5] distutils-r1.eclass: Match tags precisely in the wheel reuse logic

Michał Górny <[email protected]>
Newsgroups gmane.linux.gentoo.devel
Message-ID <[email protected]>
Modify the wheel reuse logic to split the tags from the wheel filename,
and match them precisely rather than applying a broad match.  Notably,
this fixes handling compressed tag sets, and therefore enables us to
reuse *-abi3.abi3t-* wheels on Python 3.15.

Note that this currently does not strictly following the installer
behavior, as earlier wheels are preferred over later wheels.
For example, for cryptography the *-cp312-abi3-*.whl will be used rather
than the *-cp315-abi3.abi3t-*.whl, if built.  In other words, this will
currently make a difference only if you're building for 3.15+3.15t with
no earlier implementations.

Signed-off-by: Michał Górny <[email protected]>
---
 eclass/distutils-r1.eclass | 41 ++++++++++++++++++++++++++------------
 1 file changed, 28 insertions(+), 13 deletions(-)

diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
index 9141ec8e76be7..39d63601e3020 100644
--- a/eclass/distutils-r1.eclass
+++ b/eclass/distutils-r1.eclass
@@ -1237,23 +1237,38 @@ distutils-r1_python_compile() {
 				continue
 			fi
 
-			# 1. Use pure Python wheels only if we're not expected
-			# to build extensions.  Otherwise, we may end up
-			# not building the extension at all when e.g. PyPy3
-			# is built without one.
-			#
-			# 2. For CPython, we can reuse stable ABI wheels.  Note
-			# that this relies on the assumption that we're building
-			# from the oldest to the newest implementation,
-			# and the wheels are forward-compatible.
+			local whl_fn=${whl##*/}
+			# This technically omits the build tag, but we're
+			# not greedy, so we're only checking for the minimum number
+			# of components.
+			[[ ${whl_fn} != *-*-*-*-*.whl ]] &&
+				die "Invalid wheel filename: ${whl}"
+			whl_fn=${whl_fn%.whl}
+			local platform_tag=${whl_fn##*-}
+			whl_fn=${whl_fn%-*}
+			local abi_tag=${whl_fn##*-}
+			whl_fn=${whl_fn%-*}
+			local python_tag=${whl_fn##*-}
+
 			if [[
-				( ! ${DISTUTILS_EXT} && ${whl} == *py3-none* ) ||
+				# Use pure Python wheels only if we're not expected to
+				# build extensions.  Otherwise, we may end up not
+				# building the extension at all when e.g. PyPy3 is built
+				# without one.
+				(
+					! ${DISTUTILS_EXT} &&
+					.${python_tag}. == *.py3.* &&
+					.${abi_tag}. == *.none.*
+				) ||
+				# For GIL-enabled CPython, we can reuse ABI3 wheels.
+				# Note that we do not check the Python tag (yet),
+				# and instead rely on the assumption that we're building
+				# from the oldest to the newest implementation,
+				# and the wheels are forward-compatible.
 				(
 					${EPYTHON} == python* &&
-					# freethreading does not support stable ABI
-					# at the moment
 					${EPYTHON} != *t &&
-					${whl} == *-abi3-*
+					.${abi_tag}. == *.abi3.*
 				)
 			]]; then
 				distutils_wheel_install "${BUILD_DIR}/install" "${whl}"
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.