summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichał Górny <mgorny@gentoo.org>2023-02-10 14:18:54 +0100
committerMichał Górny <mgorny@gentoo.org>2023-02-12 20:00:42 +0100
commitbe152335ee2cf11dc33378c2903873ad742e8116 (patch)
tree6b0702b5a776c440f837e8bd0663bfff1f4f17f9 /eclass/pypi.eclass
parentpypi.eclass: Use pypi_sdist_url to generate the default SRC_URI (diff)
downloadgentoo-be152335ee2cf11dc33378c2903873ad742e8116.tar.gz
gentoo-be152335ee2cf11dc33378c2903873ad742e8116.tar.bz2
gentoo-be152335ee2cf11dc33378c2903873ad742e8116.zip
pypi.eclass: Add a name normalization function
Signed-off-by: Michał Górny <mgorny@gentoo.org>
Diffstat (limited to 'eclass/pypi.eclass')
-rw-r--r--eclass/pypi.eclass20
1 files changed, 20 insertions, 0 deletions
diff --git a/eclass/pypi.eclass b/eclass/pypi.eclass
index d00b1171fd16..3a37214f8977 100644
--- a/eclass/pypi.eclass
+++ b/eclass/pypi.eclass
@@ -34,6 +34,26 @@ esac
if [[ ! ${_PYPI_ECLASS} ]]; then
_PYPI_ECLASS=1
+# @FUNCTION: pypi_normalize_name
+# @USAGE: <name>
+# @DESCRIPTION:
+# Normalize the project name according to sdist/wheel normalization
+# rules. That is, convert to lowercase and replace runs of [._-]
+# with a single underscore.
+#
+# Based on the spec, as of 2023-02-10:
+# https://packaging.python.org/en/latest/specifications/#package-distribution-file-formats
+pypi_normalize_name() {
+ [[ ${#} -ne 1 ]] && die "Usage: ${FUNCNAME} <name>"
+
+ local name=${1}
+ local shopt_save=$(shopt -p extglob)
+ shopt -s extglob
+ name=${name//+([._-])/_}
+ ${shopt_save}
+ echo "${name,,}"
+}
+
# @FUNCTION: pypi_sdist_url
# @USAGE: [<project> [<version> [<suffix>]]]
# @DESCRIPTION: