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 <mgor…@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