🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: linux.gentoo.dev
Article #224

[gentoo-dev] [PATCH 1/2] python-utils-r1.eclass: Verify EPYTEST_PLUGINS

#224
From: Michał Górny
Date: Fri, 27 Nov 2026 17:20
97 lines
4413 bytes
Check whether we collected entry points for all packages listed
in EPYTEST_PLUGINS, and throw an error if any of them is missing.

Closes: https://bugs.gentoo.org/987133
Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
 eclass/python-utils-r1.eclass | 73 ++++++++++++++++++++++-------------
 1 file changed, 47 insertions(+), 26 deletions(-)

diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index 8e60d0485252f..39d4c490731ce 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -1485,36 +1485,57 @@ epytest() {
 		if [[ ${EPYTEST_PLUGINS[@]} ]]; then
 			if [[ ${EPYTEST_PLUGIN_LOAD_VIA_ENV} ]]; then
 				local -x PYTEST_PLUGINS=$(
-					"${EPYTHON}" - "${EPYTEST_PLUGINS[@]}" <<-EOF || die
-						import sys
-						from importlib.metadata import distribution, entry_points
-
-						packages = {distribution(x).name for x in sys.argv[1:]}
-						# In packages defining multiple entry points, we must
-						# list them in the same order!
-						plugins = (
-							x.value for x in entry_points(group="pytest11")
-							if x.dist.name in packages
-						)
-						sys.stdout.write(",".join(plugins))
-					EOF
+					"${EPYTHON}" - "${EPYTEST_PLUGINS[@]}" <<EOF || die "Failed getting pytest entry points"
+import sys
+from importlib.metadata import distribution, entry_points
+
+packages = {distribution(x).name for x in sys.argv[1:]}
+# In packages defining multiple entry points, we must
+# list them in the same order!
+packages_found = set()
+plugins = []
+for ep in entry_points(group="pytest11"):
+	if ep.dist.name in packages:
+		plugins.append(ep.value)
+		packages_found.add(ep.dist.name)
+
+packages_left = packages - packages_found
+if packages_left:
+	raise RuntimeError(
+		f"Packages {packages_left} have no pytest11 "
+		"entry points. Is EPYTEST_PLUGINS valid?"
+	)
+
+sys.stdout.write(",".join(plugins))
+EOF
 				)
 			else
 				local plugin_args=()
 				readarray -t -d '' plugin_args < <(
-					"${EPYTHON}" - "${EPYTEST_PLUGINS[@]}" <<-EOF || die
-						import os
-						import sys
-						from importlib.metadata import distribution, entry_points
-
-						env_plugins = os.environ.get("PYTEST_PLUGINS", "").split(",")
-						packages = {distribution(x).name for x in sys.argv[1:]}
-						eps = {
-							f"-p{x.name}" for x in entry_points(group="pytest11")
-							if x.dist.name in packages and x.value not in env_plugins
-						}
-						sys.stdout.write("\\0".join(sorted(eps)))
-					EOF
+					"${EPYTHON}" - "${EPYTEST_PLUGINS[@]}" <<EOF || die "Failed getting pytest plugin names"
+import os
+import sys
+from importlib.metadata import distribution, entry_points
+
+env_plugins = os.environ.get("PYTEST_PLUGINS", "").split(",")
+packages = {distribution(x).name for x in sys.argv[1:]}
+packages_found = set()
+plugins = []
+for ep in entry_points(group="pytest11"):
+	if ep.dist.name in packages:
+		packages_found.add(ep.dist.name)
+		if ep.value not in env_plugins:
+			plugins.append(f"-p{ep.name}")
+
+packages_left = packages - packages_found
+if packages_left:
+	raise RuntimeError(
+		f"Packages {packages_left} have no pytest11 "
+		"entry points. Is EPYTEST_PLUGINS valid?"
+	)
+
+sys.stdout.write("\\0".join(sorted(plugins)))
+EOF
 				)
 				args+=( "${plugin_args[@]}" )
 			fi
Technical Details
Message-ID: <O47M5-evaD-1@gated-at.bofh.it>
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!news.tcpreset.net!newsfeed.bofh.team!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomod

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-lon.pugleaf.net!news.tcpreset.net!newsfeed.bofh.team!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomod
From: Michał Górny <mgorny@gentoo.org>
Newsgroups: linux.gentoo.dev
Subject: [gentoo-dev] [PATCH 1/2] python-utils-r1.eclass: Verify EPYTEST_PLUGINS
Date: Fri, 27 Nov 2026 18:20:01 +0100
Message-ID: <O47M5-evaD-1@gated-at.bofh.it>
X-Mailer: git-send-email 2.56.1
List-ID: Gentoo Linux mail <gentoo-dev.gentoo.org>
Reply-To: gentoo-dev@lists.gentoo.org
X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Approved: robomod@news.nic.it
Lines: 97
Organization: linux.* mail to news gateway
Sender: robomod@news.nic.it
X-Original-Cc: Michał Górny <mgorny@gentoo.org>
X-Original-Date: Fri, 27 Nov 2026 18:17:21 +0100
X-Original-Message-ID: <20261127171722.76288-1-mgorny@gentoo.org>