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 03/30] distutils-r1.eclass: Create distutils_pep517_install helper
Date: Sun, 06 Feb 2022 12:50:11
Message-Id: 20220206124841.1299133-4-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 Split the wheel build & install logic into a a new helper.
2
3 Signed-off-by: Michał Górny <mgorny@g.o>
4 ---
5 eclass/distutils-r1.eclass | 77 ++++++++++++++++++++++++--------------
6 1 file changed, 48 insertions(+), 29 deletions(-)
7
8 diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
9 index 22070f6b74f4..814ee85a2b1f 100644
10 --- a/eclass/distutils-r1.eclass
11 +++ b/eclass/distutils-r1.eclass
12 @@ -984,6 +984,53 @@ _distutils-r1_get_backend() {
13 echo "${build_backend}"
14 }
15
16 +# @FUNCTION: distutils_pep517_install
17 +# @USAGE: [<root>]
18 +# @DESCRIPTION:
19 +# Build the wheel for the package in the current directory using PEP 517
20 +# backend and install it into <root>. If <root> is not specified,
21 +# ${BUILD_DIR}/install is used.
22 +#
23 +# This function is intended for expert use only. It does not handle
24 +# wrapping executables.
25 +distutils_pep517_install() {
26 + debug-print-function ${FUNCNAME} "${@}"
27 +
28 + local root=${1:-${BUILD_DIR}/install}
29 + local -x WHEEL_BUILD_DIR=${BUILD_DIR}/wheel
30 + mkdir -p "${WHEEL_BUILD_DIR}" || die
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 + [[ -n ${wheel} ]] || die "No wheel name returned"
39 +
40 + einfo " Installing the wheel to ${root}"
41 + # NB: --compile-bytecode does not produce the correct paths,
42 + # and python_optimize doesn't handle being called outside D,
43 + # so we just defer compiling until the final merge
44 + # NB: we override sys.prefix & sys.exec_prefix because otherwise
45 + # installer would use virtualenv's prefix
46 + local -x PYTHON_PREFIX=${EPREFIX}/usr
47 + "${EPYTHON}" -c 'import os, sys; sys.prefix = sys.exec_prefix = os.environ["PYTHON_PREFIX"]; from installer.__main__ import main; main(sys.argv[1:])' \
48 + -d "${root}" "${WHEEL_BUILD_DIR}/${wheel}" --no-compile-bytecode ||
49 + die "installer failed"
50 +
51 + # remove installed licenses
52 + find "${root}$(python_get_sitedir)" \
53 + '(' -path '*.dist-info/COPYING*' -o \
54 + -path '*.dist-info/LICENSE*' ')' -delete || die
55 +
56 + # clean the build tree; otherwise we may end up with PyPy3
57 + # extensions duplicated into CPython dists
58 + if [[ ${DISTUTILS_USE_PEP517:-setuptools} == setuptools ]]; then
59 + esetup.py clean -a
60 + fi
61 +}
62 +
63 # @FUNCTION: distutils-r1_python_compile
64 # @USAGE: [additional-args...]
65 # @DESCRIPTION:
66 @@ -1027,36 +1074,8 @@ distutils-r1_python_compile() {
67 addpredict /usr/lib/portage/pym
68 addpredict /usr/local # bug 498232
69
70 - local -x WHEEL_BUILD_DIR=${BUILD_DIR}/wheel
71 - mkdir -p "${WHEEL_BUILD_DIR}" || die
72 -
73 - local build_backend=$(_distutils-r1_get_backend)
74 - einfo " Building the wheel via ${build_backend}"
75 - local wheel=$("${EPYTHON}" -c "import ${build_backend%:*}; \
76 - import os; \
77 - print(${build_backend/:/.}.build_wheel(os.environ['WHEEL_BUILD_DIR']))" ||
78 - die "Wheel build failed")
79 - [[ -n ${wheel} ]] || die "No wheel name returned"
80 -
81 local root=${BUILD_DIR}/install
82 - einfo " Installing the wheel to ${root}"
83 - # NB: --compile-bytecode does not produce the correct paths,
84 - # and python_optimize doesn't handle being called outside D,
85 - # so we just defer compiling until the final merge
86 - "${EPYTHON}" -m installer -d "${root}" "${WHEEL_BUILD_DIR}/${wheel}" \
87 - --no-compile-bytecode ||
88 - die "installer failed"
89 -
90 - # remove installed licenses
91 - find "${root}$(python_get_sitedir)" \
92 - '(' -path '*.dist-info/COPYING*' -o \
93 - -path '*.dist-info/LICENSE*' ')' -delete || die
94 -
95 - # clean the build tree; otherwise we may end up with PyPy3
96 - # extensions duplicated into CPython dists
97 - if [[ ${DISTUTILS_USE_PEP517:-setuptools} == setuptools ]]; then
98 - esetup.py clean -a
99 - fi
100 + distutils_pep517_install "${root}"
101
102 # copy executables to python-exec directory
103 # we do it early so that we can alter bindir recklessly
104 --
105 2.35.1