Signed-off-by: Michał Górny <[email protected]>
---
 eclass/pypi.eclass   | 23 +++++++++++++++++++----
 eclass/tests/pypi.sh | 27 ++++++++++++++++++++++++---
 2 files changed, 43 insertions(+), 7 deletions(-)

diff --git a/eclass/pypi.eclass b/eclass/pypi.eclass
index a3c38aa5f3ec..dd24b8337e62 100644
--- a/eclass/pypi.eclass
+++ b/eclass/pypi.eclass
@@ -55,26 +55,41 @@ pypi_normalize_name() {
 }
 
 # @FUNCTION: pypi_sdist_url
-# @USAGE: [<project> [<version> [<suffix>]]]
+# @USAGE: [--no-normalize] [<project> [<version> [<suffix>]]]
 # @DESCRIPTION:
 # Output the URL to PyPI sdist for specified project/version tuple.
 #
-# If <package> is unspecified, it defaults to ${PN}.
+# The `--no-normalize` option disables project name normalization
+# for sdist filename.  This may be necessary when dealing with distfiles
+# generated using build systems that did not follow PEP 625
+# (i.e. the sdist name contains uppercase letters, hyphens or dots).
+#
+# If <package> is unspecified, it defaults to ${PN}.  The package name
+# is normalized according to the specification unless `--no-normalize`
+# is passed.
 #
 # If <version> is unspecified, it defaults to ${PV}.
 #
 # 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} <project> [<version> [<suffix>]]"
+               die "Usage: ${FUNCNAME} [--no-normalize] <project> [<version> 
[<suffix>]]"
        fi
 
        local project=${1-"${PN}"}
        local version=${2-"${PV}"}
        local suffix=${3-.tar.gz}
+       local fn_project=${project}
+       [[ ${normalize} ]] && fn_project=$(pypi_normalize_name "${project}")
        printf "https://files.pythonhosted.org/packages/source/%s"; \
-               "${project::1}/${project}/${project}-${version}${suffix}"
+               "${project::1}/${project}/${fn_project}-${version}${suffix}"
 }
 
 # @FUNCTION: pypi_wheel_name
diff --git a/eclass/tests/pypi.sh b/eclass/tests/pypi.sh
index 111b61380fe4..385b1c028bce 100755
--- a/eclass/tests/pypi.sh
+++ b/eclass/tests/pypi.sh
@@ -5,6 +5,9 @@
 EAPI=8
 source tests-common.sh || exit
 
+PN=Foo.Bar
+PV=1.2.3
+
 inherit pypi
 
 test-eq() {
@@ -29,9 +32,6 @@ test-eq "pypi_normalize_name foo___bar" foo_bar
 test-eq "pypi_normalize_name Flask-BabelEx" flask_babelex
 test-eq "pypi_normalize_name jaraco.context" jaraco_context
 
-PN=Foo.Bar
-PV=1.2.3
-
 test-eq "pypi_wheel_name" foo_bar-1.2.3-py3-none-any.whl
 test-eq "pypi_wheel_name Flask-BabelEx" flask_babelex-1.2.3-py3-none-any.whl
 test-eq "pypi_wheel_name Flask-BabelEx 4" flask_babelex-4-py3-none-any.whl
@@ -62,4 +62,25 @@ test-eq "pypi_wheel_url --unpack Flask-BabelEx 4 py2.py3" \
 test-eq "pypi_wheel_url --unpack cryptography 39.0.1 cp36 
abi3-manylinux_2_28_x86_64" \
        
"https://files.pythonhosted.org/packages/cp36/c/cryptography/cryptography-39.0.1-cp36-abi3-manylinux_2_28_x86_64.whl
 -> cryptography-39.0.1-cp36-abi3-manylinux_2_28_x86_64.whl.zip"
 
+test-eq "pypi_sdist_url" \
+       
https://files.pythonhosted.org/packages/source/F/Foo.Bar/foo_bar-1.2.3.tar.gz
+test-eq "pypi_sdist_url Flask-BabelEx" \
+       
https://files.pythonhosted.org/packages/source/F/Flask-BabelEx/flask_babelex-1.2.3.tar.gz
+test-eq "pypi_sdist_url Flask-BabelEx 4" \
+       
https://files.pythonhosted.org/packages/source/F/Flask-BabelEx/flask_babelex-4.tar.gz
+test-eq "pypi_sdist_url Flask-BabelEx 4 .zip" \
+       
https://files.pythonhosted.org/packages/source/F/Flask-BabelEx/flask_babelex-4.zip
+
+test-eq "pypi_sdist_url --no-normalize" \
+       
https://files.pythonhosted.org/packages/source/F/Foo.Bar/Foo.Bar-1.2.3.tar.gz
+test-eq "pypi_sdist_url --no-normalize Flask-BabelEx" \
+       
https://files.pythonhosted.org/packages/source/F/Flask-BabelEx/Flask-BabelEx-1.2.3.tar.gz
+test-eq "pypi_sdist_url --no-normalize Flask-BabelEx 4" \
+       
https://files.pythonhosted.org/packages/source/F/Flask-BabelEx/Flask-BabelEx-4.tar.gz
+test-eq "pypi_sdist_url --no-normalize Flask-BabelEx 4 .zip" \
+       
https://files.pythonhosted.org/packages/source/F/Flask-BabelEx/Flask-BabelEx-4.zip
+
+test-eq 'declare -p SRC_URI' \
+       'declare -- 
SRC_URI="https://files.pythonhosted.org/packages/source/F/Foo.Bar/foo_bar-1.2.3.tar.gz";'
+
 texit
-- 
2.39.1


Reply via email to