🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: linux.gentoo.dev
2 messages
2 total messages Started by Michał Górny Fri, 27 Nov 2026 17:20
[gentoo-dev] [PATCH 1/2] python-utils-r1.eclass: Verify EPYTEST_PLUGINS
#224
Author: 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
[gentoo-dev] [PATCH 2/2] python-utils-r1.eclass: Combine pytest plugin helpers
#225
Author: Michał Górny
Date: Fri, 27 Nov 2026 17:20
121 lines
5110 bytes
Signed-off-by: Michał Górny <mgorny@gentoo.org>
---
 eclass/python-utils-r1.eclass | 94 +++++++++++++++++------------------
 1 file changed, 47 insertions(+), 47 deletions(-)

diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index 39d4c490731ce..4f3f7575eab68 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -1418,6 +1418,47 @@ _set_epytest_plugins() {
 # are useful here), rather than globally.  It must not be set
 # in ebuilds.
 
+# @ECLASS_VARIABLE: _EPYTEST_PLUGIN_SCRIPT
+# @INTERNAL
+# @DESCRIPTION:
+# Script used to obtain -p flags or PYTEST_PLUGINS value for specified
+# plugins.
+_EPYTEST_PLUGIN_SCRIPT='
+import os
+import sys
+from importlib.metadata import distribution, entry_points
+
+# -a for -p args; -e for PYTEST_PLUGINS envvar
+mode = sys.argv[1]
+assert mode in ("-a", "-e")
+
+env_plugins = os.environ.get("PYTEST_PLUGINS", "").split(",")
+packages = {distribution(x).name for x in sys.argv[2:]}
+packages_found = set()
+# In packages defining multiple entry points, we must
+# list them in the same order (for PYTEST_PLUGINS)!
+plugins = []
+for ep in entry_points(group="pytest11"):
+	if ep.dist.name in packages:
+		packages_found.add(ep.dist.name)
+		if mode == "-e":
+			plugins.append(ep.value)
+		elif mode == "-a" and 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?"
+	)
+
+if mode == "-e":
+	sys.stdout.write(",".join(plugins))
+elif mode == "-a":
+	sys.stdout.write("\0".join(sorted(plugins)))
+'
+
 # @FUNCTION: epytest
 # @USAGE: [<args>...]
 # @DESCRIPTION:
@@ -1485,57 +1526,16 @@ epytest() {
 		if [[ ${EPYTEST_PLUGINS[@]} ]]; then
 			if [[ ${EPYTEST_PLUGIN_LOAD_VIA_ENV} ]]; then
 				local -x PYTEST_PLUGINS=$(
-					"${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
+					"${EPYTHON}" - -e "${EPYTEST_PLUGINS[@]}" \
+							<<<${_EPYTEST_PLUGIN_SCRIPT} ||
+						die "Failed getting pytest entry points"
 				)
 			else
 				local plugin_args=()
 				readarray -t -d '' plugin_args < <(
-					"${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
+					"${EPYTHON}" - -a "${EPYTEST_PLUGINS[@]}" \
+							<<<${_EPYTEST_PLUGIN_SCRIPT} ||
+						die "Failed getting pytest plugin names"
 				)
 				args+=( "${plugin_args[@]}" )
 			fi
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads