1 |
Signed-off-by: Michał Górny <mgorny@g.o> |
2 |
--- |
3 |
eclass/pypi.eclass | 23 +++++++++++++++++++---- |
4 |
eclass/tests/pypi.sh | 27 ++++++++++++++++++++++++--- |
5 |
2 files changed, 43 insertions(+), 7 deletions(-) |
6 |
|
7 |
diff --git a/eclass/pypi.eclass b/eclass/pypi.eclass |
8 |
index a3c38aa5f3ec..dd24b8337e62 100644 |
9 |
--- a/eclass/pypi.eclass |
10 |
+++ b/eclass/pypi.eclass |
11 |
@@ -55,26 +55,41 @@ pypi_normalize_name() { |
12 |
} |
13 |
|
14 |
# @FUNCTION: pypi_sdist_url |
15 |
-# @USAGE: [<project> [<version> [<suffix>]]] |
16 |
+# @USAGE: [--no-normalize] [<project> [<version> [<suffix>]]] |
17 |
# @DESCRIPTION: |
18 |
# Output the URL to PyPI sdist for specified project/version tuple. |
19 |
# |
20 |
-# If <package> is unspecified, it defaults to ${PN}. |
21 |
+# The `--no-normalize` option disables project name normalization |
22 |
+# for sdist filename. This may be necessary when dealing with distfiles |
23 |
+# generated using build systems that did not follow PEP 625 |
24 |
+# (i.e. the sdist name contains uppercase letters, hyphens or dots). |
25 |
+# |
26 |
+# If <package> is unspecified, it defaults to ${PN}. The package name |
27 |
+# is normalized according to the specification unless `--no-normalize` |
28 |
+# is passed. |
29 |
# |
30 |
# If <version> is unspecified, it defaults to ${PV}. |
31 |
# |
32 |
# If <format> is unspecified, it defaults to ".tar.gz". Another valid |
33 |
# value is ".zip" (please remember to add a BDEPEND on app-arch/unzip). |
34 |
pypi_sdist_url() { |
35 |
+ local normalize=1 |
36 |
+ if [[ ${1} == --no-normalize ]]; then |
37 |
+ normalize= |
38 |
+ shift |
39 |
+ fi |
40 |
+ |
41 |
if [[ ${#} -gt 3 ]]; then |
42 |
- die "Usage: ${FUNCNAME} <project> [<version> [<suffix>]]" |
43 |
+ die "Usage: ${FUNCNAME} [--no-normalize] <project> [<version> [<suffix>]]" |
44 |
fi |
45 |
|
46 |
local project=${1-"${PN}"} |
47 |
local version=${2-"${PV}"} |
48 |
local suffix=${3-.tar.gz} |
49 |
+ local fn_project=${project} |
50 |
+ [[ ${normalize} ]] && fn_project=$(pypi_normalize_name "${project}") |
51 |
printf "https://files.pythonhosted.org/packages/source/%s" \ |
52 |
- "${project::1}/${project}/${project}-${version}${suffix}" |
53 |
+ "${project::1}/${project}/${fn_project}-${version}${suffix}" |
54 |
} |
55 |
|
56 |
# @FUNCTION: pypi_wheel_name |
57 |
diff --git a/eclass/tests/pypi.sh b/eclass/tests/pypi.sh |
58 |
index 111b61380fe4..385b1c028bce 100755 |
59 |
--- a/eclass/tests/pypi.sh |
60 |
+++ b/eclass/tests/pypi.sh |
61 |
@@ -5,6 +5,9 @@ |
62 |
EAPI=8 |
63 |
source tests-common.sh || exit |
64 |
|
65 |
+PN=Foo.Bar |
66 |
+PV=1.2.3 |
67 |
+ |
68 |
inherit pypi |
69 |
|
70 |
test-eq() { |
71 |
@@ -29,9 +32,6 @@ test-eq "pypi_normalize_name foo___bar" foo_bar |
72 |
test-eq "pypi_normalize_name Flask-BabelEx" flask_babelex |
73 |
test-eq "pypi_normalize_name jaraco.context" jaraco_context |
74 |
|
75 |
-PN=Foo.Bar |
76 |
-PV=1.2.3 |
77 |
- |
78 |
test-eq "pypi_wheel_name" foo_bar-1.2.3-py3-none-any.whl |
79 |
test-eq "pypi_wheel_name Flask-BabelEx" flask_babelex-1.2.3-py3-none-any.whl |
80 |
test-eq "pypi_wheel_name Flask-BabelEx 4" flask_babelex-4-py3-none-any.whl |
81 |
@@ -62,4 +62,25 @@ test-eq "pypi_wheel_url --unpack Flask-BabelEx 4 py2.py3" \ |
82 |
test-eq "pypi_wheel_url --unpack cryptography 39.0.1 cp36 abi3-manylinux_2_28_x86_64" \ |
83 |
"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" |
84 |
|
85 |
+test-eq "pypi_sdist_url" \ |
86 |
+ https://files.pythonhosted.org/packages/source/F/Foo.Bar/foo_bar-1.2.3.tar.gz |
87 |
+test-eq "pypi_sdist_url Flask-BabelEx" \ |
88 |
+ https://files.pythonhosted.org/packages/source/F/Flask-BabelEx/flask_babelex-1.2.3.tar.gz |
89 |
+test-eq "pypi_sdist_url Flask-BabelEx 4" \ |
90 |
+ https://files.pythonhosted.org/packages/source/F/Flask-BabelEx/flask_babelex-4.tar.gz |
91 |
+test-eq "pypi_sdist_url Flask-BabelEx 4 .zip" \ |
92 |
+ https://files.pythonhosted.org/packages/source/F/Flask-BabelEx/flask_babelex-4.zip |
93 |
+ |
94 |
+test-eq "pypi_sdist_url --no-normalize" \ |
95 |
+ https://files.pythonhosted.org/packages/source/F/Foo.Bar/Foo.Bar-1.2.3.tar.gz |
96 |
+test-eq "pypi_sdist_url --no-normalize Flask-BabelEx" \ |
97 |
+ https://files.pythonhosted.org/packages/source/F/Flask-BabelEx/Flask-BabelEx-1.2.3.tar.gz |
98 |
+test-eq "pypi_sdist_url --no-normalize Flask-BabelEx 4" \ |
99 |
+ https://files.pythonhosted.org/packages/source/F/Flask-BabelEx/Flask-BabelEx-4.tar.gz |
100 |
+test-eq "pypi_sdist_url --no-normalize Flask-BabelEx 4 .zip" \ |
101 |
+ https://files.pythonhosted.org/packages/source/F/Flask-BabelEx/Flask-BabelEx-4.zip |
102 |
+ |
103 |
+test-eq 'declare -p SRC_URI' \ |
104 |
+ 'declare -- SRC_URI="https://files.pythonhosted.org/packages/source/F/Foo.Bar/foo_bar-1.2.3.tar.gz"' |
105 |
+ |
106 |
texit |
107 |
-- |
108 |
2.39.1 |