summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2023-06-12 21:41:31 +0200
committerMichał Górny <mgorny@gentoo.org>2023-06-15 14:19:24 +0200
commit78cb7a0709eea188d764b9ac77d120414e07e7b5 (patch)
treeeaf35ef0d64665fbb422f17d2d96532bc8d92fb9
parentpypi.eclass: Normalize names without subshell (diff)
downloadgentoo-78cb7a0709eea188d764b9ac77d120414e07e7b5.tar.gz
gentoo-78cb7a0709eea188d764b9ac77d120414e07e7b5.tar.bz2
gentoo-78cb7a0709eea188d764b9ac77d120414e07e7b5.zip
pypi.eclass: Translate version without subshell in common case
Provide an internal helper to translate versions without a subshell, and use it in the common case. Now the benchmark gives 685 ops / s, which means it's another 28% speedup. Signed-off-by: Michał Górny <mgorny@gentoo.org>
-rw-r--r--eclass/pypi.eclass33
1 files changed, 22 insertions, 11 deletions
diff --git a/eclass/pypi.eclass b/eclass/pypi.eclass
index d79e6f06fc1b..04fe5e51bcee 100644
--- a/eclass/pypi.eclass
+++ b/eclass/pypi.eclass
@@ -95,6 +95,19 @@ pypi_normalize_name() {
echo "${_PYPI_NORMALIZED_NAME}"
}
+# @FUNCTION: _pypi_translate_version
+# @USAGE: <version>
+# @DESCRIPTION:
+# Internal version translation function, returns the result
+# via _PYPI_TRANSLATED_VERSION variable.
+_pypi_translate_version() {
+ local version=${1}
+ version=${version/_alpha/a}
+ version=${version/_beta/b}
+ version=${version/_rc/rc}
+ _PYPI_TRANSLATED_VERSION=${version/_p/.post}
+}
+
# @FUNCTION: pypi_translate_version
# @USAGE: <version>
# @DESCRIPTION:
@@ -106,12 +119,9 @@ pypi_normalize_name() {
pypi_translate_version() {
[[ ${#} -ne 1 ]] && die "Usage: ${FUNCNAME} <version>"
- local version=${1}
- version=${version/_alpha/a}
- version=${version/_beta/b}
- version=${version/_rc/rc}
- version=${version/_p/.post}
- echo "${version}"
+ local _PYPI_TRANSLATED_VERSION
+ _pypi_translate_version "${@}"
+ echo "${_PYPI_TRANSLATED_VERSION}"
}
# @FUNCTION: pypi_sdist_url
@@ -239,16 +249,17 @@ pypi_wheel_url() {
# @DESCRIPTION:
# Set global variables, SRC_URI and S.
_pypi_set_globals() {
- local version=$(pypi_translate_version "${PV}")
+ local _PYPI_TRANSLATED_VERSION
+ _pypi_translate_version "${PV}"
if [[ ${PYPI_NO_NORMALIZE} ]]; then
- SRC_URI="$(pypi_sdist_url --no-normalize "${PYPI_PN}" "${version}")"
- S="${WORKDIR}/${PYPI_PN}-${version}"
+ SRC_URI="$(pypi_sdist_url --no-normalize "${PYPI_PN}" "${_PYPI_TRANSLATED_VERSION}")"
+ S="${WORKDIR}/${PYPI_PN}-${_PYPI_TRANSLATED_VERSION}"
else
local _PYPI_NORMALIZED_NAME
_pypi_normalize_name "${PYPI_PN}"
- SRC_URI="$(pypi_sdist_url "${PYPI_PN}" "${version}")"
- S="${WORKDIR}/${_PYPI_NORMALIZED_NAME}-${version}"
+ SRC_URI="$(pypi_sdist_url "${PYPI_PN}" "${_PYPI_TRANSLATED_VERSION}")"
+ S="${WORKDIR}/${_PYPI_NORMALIZED_NAME}-${_PYPI_TRANSLATED_VERSION}"
fi
}