Gentoo Archives: gentoo-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-dev] [PATCH 1/2] pypi.eclass: Introduce PYPI_PN to override the default project name
Date: Sat, 18 Mar 2023 15:25:55
Message-Id: 20230318152543.89554-1-mgorny@gentoo.org
1 Introduce a convenience PYPI_PN variable that can be used to override
2 the default project name. This is meant to be used primarily when
3 upstream project name does not conform to Gentoo package naming rules,
4 e.g. contains dots or uppercase letters.
5
6 For example, instead of:
7
8 SRC_URI="$(pypi_sdist_url --no-normalize "${PN/-/.}")"
9 S=${WORKDIR}/${P/-/.}
10
11 one can now specify:
12
13 PYPI_NO_NORMALIZE=1
14 PYPI_PN=${PN/-/.}
15
16 For PEP 625-conformant packages, instead of:
17
18 SRC_URI="$(pypi_sdist_url "${PN/-/.}")"
19
20 one can use:
21
22 PYPI_PN=${PN/-/.}
23
24 There's not much gain space-wise but it avoids having to specify
25 the name twice. This can particularly be helpful for package names
26 using PascalCase.
27
28 Signed-off-by: Michał Górny <mgorny@g.o>
29 ---
30 eclass/pypi.eclass | 35 ++++++++++++++++++++++++-----------
31 eclass/tests/pypi.sh | 3 ++-
32 2 files changed, 26 insertions(+), 12 deletions(-)
33
34 diff --git a/eclass/pypi.eclass b/eclass/pypi.eclass
35 index 79007a2ad0ed..ca3b6f67803d 100644
36 --- a/eclass/pypi.eclass
37 +++ b/eclass/pypi.eclass
38 @@ -50,6 +50,19 @@ _PYPI_ECLASS=1
39 # When set to a non-empty value, disables project name normalization
40 # for the default SRC_URI and S values.
41
42 +# @ECLASS_VARIABLE: PYPI_PN
43 +# @PRE_INHERIT
44 +# @DESCRIPTION:
45 +# The PyPI project name. This should be overriden scarcely, generally
46 +# when upstream project name does not conform to Gentoo naming rules,
47 +# e.g. when it contains dots or uppercase letters.
48 +#
49 +# Example use:
50 +# @CODE
51 +# PYPI_PN=${PN/-/.}
52 +# @CODE
53 +: ${PYPI_PN:=${PN}}
54 +
55 # @FUNCTION: pypi_normalize_name
56 # @USAGE: <name>
57 # @DESCRIPTION:
58 @@ -99,9 +112,9 @@ pypi_translate_version() {
59 # generated using build systems that did not follow PEP 625
60 # (i.e. the sdist name contains uppercase letters, hyphens or dots).
61 #
62 -# If <package> is unspecified, it defaults to ${PN}. The package name
63 -# is normalized according to the specification unless `--no-normalize`
64 -# is passed.
65 +# If <package> is unspecified, it defaults to ${PYPI_PN}. The package
66 +# name is normalized according to the specification unless
67 +# `--no-normalize` is passed.
68 #
69 # If <version> is unspecified, it defaults to ${PV} translated
70 # via pypi_translate_version. If it is specified, then it is used
71 @@ -121,7 +134,7 @@ pypi_sdist_url() {
72 die "Usage: ${FUNCNAME} [--no-normalize] <project> [<version> [<suffix>]]"
73 fi
74
75 - local project=${1-"${PN}"}
76 + local project=${1-"${PYPI_PN}"}
77 local version=${2-"$(pypi_translate_version "${PV}")"}
78 local suffix=${3-.tar.gz}
79 local fn_project=${project}
80 @@ -135,8 +148,8 @@ pypi_sdist_url() {
81 # @DESCRIPTION:
82 # Output the wheel filename for the specified project/version tuple.
83 #
84 -# If <package> is unspecified, it defaults to ${PN}. The package name
85 -# is normalized according to the wheel specification.
86 +# If <package> is unspecified, it defaults to ${PYPI_PN}. The package
87 +# name is normalized according to the wheel specification.
88 #
89 # If <version> is unspecified, it defaults to ${PV} translated
90 # via pypi_translate_version. If it is specified, then it is used
91 @@ -154,7 +167,7 @@ pypi_wheel_name() {
92 die "Usage: ${FUNCNAME} <project> [<version> [<python-tag> [<abi-platform-tag>]]]"
93 fi
94
95 - local project=$(pypi_normalize_name "${1-"${PN}"}")
96 + local project=$(pypi_normalize_name "${1-"${PYPI_PN}"}")
97 local version=${2-"$(pypi_translate_version "${PV}")"}
98 local pytag=${3-py3}
99 local abitag=${4-none-any}
100 @@ -172,7 +185,7 @@ pypi_wheel_name() {
101 # the wheel contents will be unpacked straight into ${WORKDIR}.
102 # You need to add a BDEPEND on app-arch/unzip.
103 #
104 -# If <package> is unspecified, it defaults to ${PN}.
105 +# If <package> is unspecified, it defaults to ${PYPI_PN}.
106 #
107 # If <version> is unspecified, it defaults to ${PV} translated
108 # via pypi_translate_version. If it is specified, then it is used
109 @@ -197,7 +210,7 @@ pypi_wheel_url() {
110 fi
111
112 local filename=$(pypi_wheel_name "${@}")
113 - local project=${1-"${PN}"}
114 + local project=${1-"${PYPI_PN}"}
115 local version=${2-"$(pypi_translate_version "${PV}")"}
116 local pytag=${3-py3}
117 printf "https://files.pythonhosted.org/packages/%s" \
118 @@ -210,10 +223,10 @@ pypi_wheel_url() {
119
120 if [[ ${PYPI_NO_NORMALIZE} ]]; then
121 SRC_URI="$(pypi_sdist_url --no-normalize)"
122 - S="${WORKDIR}/${PN}-$(pypi_translate_version "${PV}")"
123 + S="${WORKDIR}/${PYPI_PN}-$(pypi_translate_version "${PV}")"
124 else
125 SRC_URI="$(pypi_sdist_url)"
126 - S="${WORKDIR}/$(pypi_normalize_name "${PN}")-$(pypi_translate_version "${PV}")"
127 + S="${WORKDIR}/$(pypi_normalize_name "${PYPI_PN}")-$(pypi_translate_version "${PV}")"
128 fi
129
130 fi
131 diff --git a/eclass/tests/pypi.sh b/eclass/tests/pypi.sh
132 index ebfcdb630856..471ac048b18a 100755
133 --- a/eclass/tests/pypi.sh
134 +++ b/eclass/tests/pypi.sh
135 @@ -5,7 +5,8 @@
136 EAPI=8
137 source tests-common.sh || exit
138
139 -PN=Foo.Bar
140 +PN=foo-bar
141 +PYPI_PN=Foo.Bar
142 PV=1.2.3_beta2
143 WORKDIR='<WORKDIR>'
144
145 --
146 2.40.0

Replies