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 21/30] distutils-r1.eclass: Use heredoc instead of "python -c"
Date: Sun, 06 Feb 2022 12:55:30
Message-Id: 20220206124841.1299133-22-mgorny@gentoo.org
In Reply to: [gentoo-dev] [PATCH 00/30] One batch of Python eclass updates to rule them all by "Michał Górny"
1 Use heredocs instead of inlining longish scripts in "python -c",
2 for greater readability. Thanks to arthurzam for the suggestion.
3
4 Signed-off-by: Michał Górny <mgorny@g.o>
5 ---
6 eclass/distutils-r1.eclass | 31 +++++++++++++++++++++----------
7 1 file changed, 21 insertions(+), 10 deletions(-)
8
9 diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
10 index 7f9cf242c421..ea8fc7e5d165 100644
11 --- a/eclass/distutils-r1.eclass
12 +++ b/eclass/distutils-r1.eclass
13 @@ -936,9 +936,13 @@ _distutils-r1_get_backend() {
14 if [[ -f pyproject.toml ]]; then
15 # if pyproject.toml exists, try getting the backend from it
16 # NB: this could fail if pyproject.toml doesn't list one
17 - build_backend=$("${EPYTHON}" -c 'import tomli; \
18 - print(tomli.load(open("pyproject.toml", "rb")) \
19 - ["build-system"]["build-backend"])' 2>/dev/null)
20 + build_backend=$(
21 + "${EPYTHON}" - <<-EOF 2>/dev/null
22 + import tomli
23 + print(tomli.load(open("pyproject.toml", "rb"))
24 + ["build-system"]["build-backend"])
25 + EOF
26 + )
27 fi
28 if [[ -z ${build_backend} && ${DISTUTILS_USE_PEP517} == setuptools &&
29 -f setup.py ]]
30 @@ -1004,10 +1008,13 @@ distutils_pep517_install() {
31
32 local build_backend=$(_distutils-r1_get_backend)
33 einfo " Building the wheel for ${PWD#${WORKDIR}/} via ${build_backend}"
34 - local wheel=$("${EPYTHON}" -c "import ${build_backend%:*}; \
35 - import os; \
36 - print(${build_backend/:/.}.build_wheel(os.environ['WHEEL_BUILD_DIR']))" ||
37 - die "Wheel build failed")
38 + local wheel=$(
39 + "${EPYTHON}" - <<-EOF || die "Wheel build failed"
40 + import ${build_backend%:*}
41 + import os
42 + print(${build_backend/:/.}.build_wheel(os.environ['WHEEL_BUILD_DIR']))
43 + EOF
44 + )
45 [[ -n ${wheel} ]] || die "No wheel name returned"
46
47 einfo " Installing the wheel to ${root}"
48 @@ -1017,9 +1024,13 @@ distutils_pep517_install() {
49 # NB: we override sys.prefix & sys.exec_prefix because otherwise
50 # installer would use virtualenv's prefix
51 local -x PYTHON_PREFIX=${EPREFIX}/usr
52 - "${EPYTHON}" -c 'import os, sys; sys.prefix = sys.exec_prefix = os.environ["PYTHON_PREFIX"]; from installer.__main__ import main; main(sys.argv[1:])' \
53 - -d "${root}" "${WHEEL_BUILD_DIR}/${wheel}" --no-compile-bytecode ||
54 - die "installer failed"
55 + "${EPYTHON}" - -d "${root}" "${WHEEL_BUILD_DIR}/${wheel}" --no-compile-bytecode \
56 + <<-EOF || die "installer failed"
57 + import os, sys
58 + sys.prefix = sys.exec_prefix = os.environ["PYTHON_PREFIX"]
59 + from installer.__main__ import main
60 + main(sys.argv[1:])
61 + EOF
62
63 # remove installed licenses
64 find "${root}$(python_get_sitedir)" \
65 --
66 2.35.1