diff options
author | Michał Górny <mgorny@gentoo.org> | 2023-06-12 21:51:51 +0200 |
---|---|---|
committer | Michał Górny <mgorny@gentoo.org> | 2023-06-15 14:19:25 +0200 |
commit | 9640490da48c35124a6f2e27c46931cf1db718f6 (patch) | |
tree | a2b4b47f3801d055c84eef902bbde36e9800d2cb /eclass | |
parent | pypi.eclass: Translate version without subshell in common case (diff) | |
download | gentoo-9640490da48c35124a6f2e27c46931cf1db718f6.tar.gz gentoo-9640490da48c35124a6f2e27c46931cf1db718f6.tar.bz2 gentoo-9640490da48c35124a6f2e27c46931cf1db718f6.zip |
pypi.eclass: Replace pypi_sdist_url in global scope
Introduce an internal helper for _pypi_sdist_url that doesn't require
subshell, and therefore eliminate all subshells from global scope.
We're nearing 952 ops / s, further 39% speedup.
Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'eclass')
-rw-r--r-- | eclass/pypi.eclass | 53 |
1 files changed, 33 insertions, 20 deletions
diff --git a/eclass/pypi.eclass b/eclass/pypi.eclass index 04fe5e51bcee..8911628994eb 100644 --- a/eclass/pypi.eclass +++ b/eclass/pypi.eclass @@ -124,6 +124,31 @@ pypi_translate_version() { echo "${_PYPI_TRANSLATED_VERSION}" } +# @FUNCTION: _pypi_sdist_url +# @INTERNAL +# @USAGE: [--no-normalize] [<project> [<version> [<suffix>]]] +# @DESCRIPTION: +# Internal sdist generated, returns the result via _PYPI_SDIST_URL +# variable. +_pypi_sdist_url() { + local normalize=1 + if [[ ${1} == --no-normalize ]]; then + normalize= + shift + fi + + if [[ ${#} -gt 3 ]]; then + die "Usage: ${FUNCNAME} [--no-normalize] <project> [<version> [<suffix>]]" + fi + + local project=${1-"${PYPI_PN}"} + local version=${2-"$(pypi_translate_version "${PV}")"} + local suffix=${3-.tar.gz} + local _PYPI_NORMALIZED_NAME=${project} + [[ ${normalize} ]] && _pypi_normalize_name "${_PYPI_NORMALIZED_NAME}" + _PYPI_SDIST_URL="https://files.pythonhosted.org/packages/source/${project::1}/${project}/${_PYPI_NORMALIZED_NAME}-${version}${suffix}" +} + # @FUNCTION: pypi_sdist_url # @USAGE: [--no-normalize] [<project> [<version> [<suffix>]]] # @DESCRIPTION: @@ -146,23 +171,9 @@ pypi_translate_version() { # If <format> is unspecified, it defaults to ".tar.gz". Another valid # value is ".zip" (please remember to add a BDEPEND on app-arch/unzip). pypi_sdist_url() { - local normalize=1 - if [[ ${1} == --no-normalize ]]; then - normalize= - shift - fi - - if [[ ${#} -gt 3 ]]; then - die "Usage: ${FUNCNAME} [--no-normalize] <project> [<version> [<suffix>]]" - fi - - local project=${1-"${PYPI_PN}"} - local version=${2-"$(pypi_translate_version "${PV}")"} - local suffix=${3-.tar.gz} - local _PYPI_NORMALIZED_NAME=${project} - [[ ${normalize} ]] && _pypi_normalize_name "${_PYPI_NORMALIZED_NAME}" - printf "https://files.pythonhosted.org/packages/source/%s" \ - "${project::1}/${project}/${_PYPI_NORMALIZED_NAME}-${version}${suffix}" + local _PYPI_SDIST_URL + _pypi_sdist_url "${@}" + echo "${_PYPI_SDIST_URL}" } # @FUNCTION: pypi_wheel_name @@ -249,18 +260,20 @@ pypi_wheel_url() { # @DESCRIPTION: # Set global variables, SRC_URI and S. _pypi_set_globals() { - local _PYPI_TRANSLATED_VERSION + local _PYPI_SDIST_URL _PYPI_TRANSLATED_VERSION _pypi_translate_version "${PV}" if [[ ${PYPI_NO_NORMALIZE} ]]; then - SRC_URI="$(pypi_sdist_url --no-normalize "${PYPI_PN}" "${_PYPI_TRANSLATED_VERSION}")" + _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}" "${_PYPI_TRANSLATED_VERSION}")" + _pypi_sdist_url "${PYPI_PN}" "${_PYPI_TRANSLATED_VERSION}" S="${WORKDIR}/${_PYPI_NORMALIZED_NAME}-${_PYPI_TRANSLATED_VERSION}" fi + + SRC_URI=${_PYPI_SDIST_URL} } _pypi_set_globals |