Article View: linux.gentoo.dev
Article #225[gentoo-dev] [PATCH 2/2] python-utils-r1.eclass: Combine pytest plugin helpers
From: Michał Górny
Date: Fri, 27 Nov 2026 17:20
Date: Fri, 27 Nov 2026 17:20
121 lines
5110 bytes
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
Technical Details
Message-ID:
<O47M5-evaD-5@gated-at.bofh.it>Path:
mbox-mo1.pugleaf.net!news-fra.pugleaf.net!news.tcpreset.net!newsfeed.bofh.team!news.samoylyk.net!gothmog.csi.it!bofh.it!news.nic.it!robomodReferences:
<O47M5-evaD-1@gated-at.bofh.it>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-fra.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 2/2] python-utils-r1.eclass: Combine pytest plugin helpers Date: Fri, 27 Nov 2026 18:20:01 +0100 Message-ID: <O47M5-evaD-5@gated-at.bofh.it> References: <O47M5-evaD-1@gated-at.bofh.it> X-Original-To: gentoo-dev@lists.gentoo.org 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: 121 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:22 +0100 X-Original-Message-ID: <20261127171722.76288-2-mgorny@gentoo.org> X-Original-References: <20261127171722.76288-1-mgorny@gentoo.org>