1 |
Signed-off-by: Michał Górny <mgorny@g.o> |
2 |
--- |
3 |
eclass/pypi.eclass | 20 ++++++++++++++++++++ |
4 |
eclass/tests/pypi.sh | 32 ++++++++++++++++++++++++++++++++ |
5 |
2 files changed, 52 insertions(+) |
6 |
create mode 100755 eclass/tests/pypi.sh |
7 |
|
8 |
diff --git a/eclass/pypi.eclass b/eclass/pypi.eclass |
9 |
index d00b1171fd16..3a37214f8977 100644 |
10 |
--- a/eclass/pypi.eclass |
11 |
+++ b/eclass/pypi.eclass |
12 |
@@ -34,6 +34,26 @@ esac |
13 |
if [[ ! ${_PYPI_ECLASS} ]]; then |
14 |
_PYPI_ECLASS=1 |
15 |
|
16 |
+# @FUNCTION: pypi_normalize_name |
17 |
+# @USAGE: <name> |
18 |
+# @DESCRIPTION: |
19 |
+# Normalize the project name according to sdist/wheel normalization |
20 |
+# rules. That is, convert to lowercase and replace runs of [._-] |
21 |
+# with a single underscore. |
22 |
+# |
23 |
+# Based on the spec, as of 2023-02-10: |
24 |
+# https://packaging.python.org/en/latest/specifications/#package-distribution-file-formats |
25 |
+pypi_normalize_name() { |
26 |
+ [[ ${#} -ne 1 ]] && die "Usage: ${FUNCNAME} <name>" |
27 |
+ |
28 |
+ local name=${1} |
29 |
+ local shopt_save=$(shopt -p extglob) |
30 |
+ shopt -s extglob |
31 |
+ name=${name//+([._-])/_} |
32 |
+ ${shopt_save} |
33 |
+ echo "${name,,}" |
34 |
+} |
35 |
+ |
36 |
# @FUNCTION: pypi_sdist_url |
37 |
# @USAGE: [<project> [<version> [<suffix>]]] |
38 |
# @DESCRIPTION: |
39 |
diff --git a/eclass/tests/pypi.sh b/eclass/tests/pypi.sh |
40 |
new file mode 100755 |
41 |
index 000000000000..67b2c3c481fb |
42 |
--- /dev/null |
43 |
+++ b/eclass/tests/pypi.sh |
44 |
@@ -0,0 +1,32 @@ |
45 |
+#!/bin/bash |
46 |
+# Copyright 2023 Gentoo Authors |
47 |
+# Distributed under the terms of the GNU General Public License v2 |
48 |
+ |
49 |
+EAPI=8 |
50 |
+source tests-common.sh || exit |
51 |
+ |
52 |
+inherit pypi |
53 |
+ |
54 |
+test-eq() { |
55 |
+ local call=${1} |
56 |
+ local exp=${2} |
57 |
+ |
58 |
+ tbegin "${call} -> ${exp}" |
59 |
+ local ret=0 |
60 |
+ local have=$(${call}) |
61 |
+ if [[ ${have} != ${exp} ]]; then |
62 |
+ eindent |
63 |
+ eerror "incorrect result: ${have}" |
64 |
+ eoutdent |
65 |
+ ret=1 |
66 |
+ fi |
67 |
+ tend "${ret}" |
68 |
+} |
69 |
+ |
70 |
+test-eq "pypi_normalize_name foo" foo |
71 |
+test-eq "pypi_normalize_name foo_bar" foo_bar |
72 |
+test-eq "pypi_normalize_name foo___bar" foo_bar |
73 |
+test-eq "pypi_normalize_name Flask-BabelEx" flask_babelex |
74 |
+test-eq "pypi_normalize_name jaraco.context" jaraco_context |
75 |
+ |
76 |
+texit |
77 |
-- |
78 |
2.39.1 |