summaryrefslogtreecommitdiff
path: root/eclass
diff options
context:
space:
mode:
Diffstat (limited to 'eclass')
-rw-r--r--eclass/Manifest.gzbin37827 -> 37992 bytes
-rw-r--r--eclass/pypi.eclass14
-rw-r--r--eclass/python-utils-r1.eclass15
-rwxr-xr-xeclass/tests/python-utils-bench.sh53
4 files changed, 70 insertions, 12 deletions
diff --git a/eclass/Manifest.gz b/eclass/Manifest.gz
index 4c81b9206712..d37a8e591fb8 100644
--- a/eclass/Manifest.gz
+++ b/eclass/Manifest.gz
Binary files differ
diff --git a/eclass/pypi.eclass b/eclass/pypi.eclass
index 8a842c450ebc..594216a7fd96 100644
--- a/eclass/pypi.eclass
+++ b/eclass/pypi.eclass
@@ -70,14 +70,12 @@ _PYPI_ECLASS=1
# Internal normalization function, returns the result
# via _PYPI_NORMALIZED_NAME variable.
_pypi_normalize_name() {
- local name=${1}
- if shopt -p -q extglob; then
- name=${name//+([._-])/_}
- else
- shopt -s extglob
- name=${name//+([._-])/_}
- shopt -u extglob
- fi
+ # NB: it's fine to alter it unconditionally since this function is
+ # always called from a subshell or in global scope
+ # (via _pypi_set_globals)
+ shopt -s extglob
+ local name=${1//+([._-])/_}
+ shopt -u extglob
_PYPI_NORMALIZED_NAME="${name,,}"
}
diff --git a/eclass/python-utils-r1.eclass b/eclass/python-utils-r1.eclass
index 52e9e061d6bd..7a1be381f596 100644
--- a/eclass/python-utils-r1.eclass
+++ b/eclass/python-utils-r1.eclass
@@ -114,11 +114,18 @@ _python_verify_patterns() {
_python_set_impls() {
local i
- if ! declare -p PYTHON_COMPAT &>/dev/null; then
- die 'PYTHON_COMPAT not declared.'
+ # TODO: drop BASH_VERSINFO check when we require EAPI 8
+ if [[ ${BASH_VERSINFO[0]} -ge 5 ]]; then
+ [[ ${PYTHON_COMPAT@a} == *a* ]]
+ else
+ [[ $(declare -p PYTHON_COMPAT) == "declare -a"* ]]
fi
- if [[ $(declare -p PYTHON_COMPAT) != "declare -a"* ]]; then
- die 'PYTHON_COMPAT must be an array.'
+ if [[ ${?} -ne 0 ]]; then
+ if ! declare -p PYTHON_COMPAT &>/dev/null; then
+ die 'PYTHON_COMPAT not declared.'
+ else
+ die 'PYTHON_COMPAT must be an array.'
+ fi
fi
local obsolete=()
diff --git a/eclass/tests/python-utils-bench.sh b/eclass/tests/python-utils-bench.sh
new file mode 100755
index 000000000000..7f27adef5509
--- /dev/null
+++ b/eclass/tests/python-utils-bench.sh
@@ -0,0 +1,53 @@
+#!/bin/bash
+# Copyright 2023 Gentoo Authors
+# Distributed under the terms of the GNU General Public License v2
+
+EAPI=8
+source tests-common.sh || exit
+
+export LC_ALL=C
+
+ITERATIONS=10000
+RUNS=3
+
+doit() {
+ local i
+ for (( i = 0; i < ITERATIONS; i++ )); do
+ "${@}"
+ done
+}
+
+timeit() {
+ local real=()
+ local user=()
+ local x vr avg
+
+ einfo "Timing ${*}"
+ for (( x = 0; x < RUNS; x++ )); do
+ while read tt tv; do
+ case ${tt} in
+ real) real+=( ${tv} );;
+ user) user+=( ${tv} );;
+ esac
+ done < <( ( time -p doit "${@}" ) 2>&1 )
+ done
+
+ [[ ${#real[@]} == ${RUNS} ]] || die "Did not get ${RUNS} real times"
+ [[ ${#user[@]} == ${RUNS} ]] || die "Did not get ${RUNS} user times"
+
+ local xr avg
+ for x in real user; do
+ xr="${x}[*]"
+ avg=$(dc -S 3 -e "${ITERATIONS} ${RUNS} * ${!xr} + + / p")
+
+ printf '%s %4.0f it/s\n' "${x}" "${avg}"
+ done
+}
+
+PYTHON_COMPAT=( python3_{10..12} pypy3 )
+
+inherit python-utils-r1
+
+timeit _python_set_impls
+
+texit