Signed-off-by: Michał Górny <mgor…@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
[gentoo-dev] [PATCH 2/2] python-utils-r1.eclass: Combine pytest plugin helpers
- From
- Michał Górny <mgor…@gentoo.org>
- Reply-To
- gent…@lists.gentoo.org
- Sender
- robo…@news.nic.it
- Organization
- linux.* mail to news gateway
- Message-ID
- <O47M…@gated-at.bofh.it>
- Date
- Newsgroups
- linux.gentoo.dev
Moderated This group is moderated.