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/4] pypi.eclass: Support --unpack in pypi_wheel_url
Date: Sun, 05 Feb 2023 18:41:48
Message-Id: 20230205184138.438007-1-mgorny@gentoo.org
1 Add a handy `--unpack` option to pypi_wheel_url, that automatically
2 renames the downloaded distfile to have .zip suffix. This is used
3 e.g. in dev-python/installer and dev-python/tomli to have
4 default_src_unpack unpack the wheels automatically.
5
6 Signed-off-by: Michał Górny <mgorny@g.o>
7 ---
8 eclass/pypi.eclass | 26 +++++++++++++++++++-------
9 1 file changed, 19 insertions(+), 7 deletions(-)
10
11 diff --git a/eclass/pypi.eclass b/eclass/pypi.eclass
12 index e11999fc7e9c..ea57b2345502 100644
13 --- a/eclass/pypi.eclass
14 +++ b/eclass/pypi.eclass
15 @@ -89,10 +89,16 @@ pypi_wheel_name() {
16 }
17
18 # @FUNCTION: pypi_wheel_url
19 -# @USAGE: [<project> [<version> [<python-tag> [<abi-platform-tag>]]]]
20 +# @USAGE: [--unpack] [<project> [<version> [<python-tag> [<abi-platform-tag>]]]]
21 # @DESCRIPTION:
22 # Output the URL to PyPI wheel for specified project/version tuple.
23 #
24 +# The `--unpack` option causes a SRC_URI with an arrow operator to
25 +# be generated, that adds a .zip suffix to the fetched distfile,
26 +# so that it is unpacked in default src_unpack(). Note that
27 +# the wheel contents will be unpacked straight into ${WORKDIR}.
28 +# You need to add a BDEPEND on app-arch/unzip.
29 +#
30 # If <package> is unspecified, it defaults to ${PN}.
31 #
32 # If <version> is unspecified, it defaults to ${PV}.
33 @@ -103,21 +109,27 @@ pypi_wheel_name() {
34 # If <abi-platform-tag> is unspecified, it defaults to "none-any".
35 # You need to specify the correct value for non-pure wheels,
36 # e.g. "abi3-linux_x86_64".
37 -#
38 -# Note that wheels are suffixed .whl by default and therefore are not
39 -# unpacked automatically. If you need automatic unpacking, use "->"
40 -# operator to rename it or call unzip directly. Remember to BDEPEND
41 -# on app-arch/unzip.
42 pypi_wheel_url() {
43 + local unpack=
44 + if [[ ${1} == --unpack ]]; then
45 + unpack=1
46 + shift
47 + fi
48 +
49 if [[ ${#} -gt 4 ]]; then
50 die "Usage: ${FUNCNAME} <project> [<version> [<python-tag> [<abi-platform-tag>]]]"
51 fi
52
53 + local filename=$(pypi_wheel_name "${@}")
54 local project=${1-"${PN}"}
55 local version=${2-"${PV}"}
56 local pytag=${3-py3}
57 printf "https://files.pythonhosted.org/packages/%s" \
58 - "${pytag}/${project::1}/${project}/$(pypi_wheel_name "${@}")"
59 + "${pytag}/${project::1}/${project}/${filename}"
60 +
61 + if [[ ${unpack} ]]; then
62 + echo " -> ${filename}.zip"
63 + fi
64 }
65
66 fi
67 --
68 2.39.1

Replies