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] disttils-r1.eclass: Support GPEP517_TESTING mode
Date: Tue, 05 Apr 2022 11:44:56
Message-Id: 20220405114441.16307-1-mgorny@gentoo.org
1 Support GPEP517_TESTING variable to enable using dev-python/gpep517
2 instead of inline Python snippets. This is meant to provide
3 the necessary testing before we stabilize it and switch over.
4
5 Signed-off-by: Michał Górny <mgorny@g.o>
6 ---
7 eclass/distutils-r1.eclass | 88 ++++++++++++++++++++++++--------------
8 1 file changed, 57 insertions(+), 31 deletions(-)
9
10 diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
11 index ed2e9f70269f..06b614d9018a 100644
12 --- a/eclass/distutils-r1.eclass
13 +++ b/eclass/distutils-r1.eclass
14 @@ -151,6 +151,13 @@ esac
15 # ${DISTUTILS_DEPS}"
16 # @CODE
17
18 +# @ECLASS_VARIABLE: GPEP517_TESTING
19 +# @USER_VARIABLE
20 +# @DESCRIPTION:
21 +# Enable in make.conf to test building via dev-python/gpep517 instead of
22 +# inline Python snippets. dev-python/gpep517 needs to be installed
23 +# first.
24 +
25 if [[ ! ${_DISTUTILS_R1} ]]; then
26
27 [[ ${EAPI} == 6 ]] && inherit eutils xdg-utils
28 @@ -938,16 +945,20 @@ _distutils-r1_get_backend() {
29 if [[ -f pyproject.toml ]]; then
30 # if pyproject.toml exists, try getting the backend from it
31 # NB: this could fail if pyproject.toml doesn't list one
32 - build_backend=$(
33 - "${EPYTHON}" - 3>&1 <<-EOF
34 - import os
35 - import tomli
36 - print(tomli.load(open("pyproject.toml", "rb"))
37 - .get("build-system", {})
38 - .get("build-backend", ""),
39 - file=os.fdopen(3, "w"))
40 - EOF
41 - )
42 + if [[ ${GPEP517_TESTING} ]]; then
43 + build_backend=$(gpep517 get-backend)
44 + else
45 + build_backend=$(
46 + "${EPYTHON}" - 3>&1 <<-EOF
47 + import os
48 + import tomli
49 + print(tomli.load(open("pyproject.toml", "rb"))
50 + .get("build-system", {})
51 + .get("build-backend", ""),
52 + file=os.fdopen(3, "w"))
53 + EOF
54 + )
55 + fi
56 fi
57 if [[ -z ${build_backend} && ${DISTUTILS_USE_PEP517} == setuptools &&
58 -f setup.py ]]
59 @@ -1013,30 +1024,45 @@ distutils_pep517_install() {
60
61 local build_backend=$(_distutils-r1_get_backend)
62 einfo " Building the wheel for ${PWD#${WORKDIR}/} via ${build_backend}"
63 - local wheel=$(
64 - "${EPYTHON}" - 3>&1 >&2 <<-EOF || die "Wheel build failed"
65 - import ${build_backend%:*}
66 - import os
67 - print(${build_backend/:/.}.build_wheel(os.environ['WHEEL_BUILD_DIR']),
68 - file=os.fdopen(3, 'w'))
69 - EOF
70 - )
71 + if [[ ${GPEP517_TESTING} ]]; then
72 + local wheel=$(
73 + gpep517 build-wheel --backend "${build_backend}" \
74 + --output-fd 3 \
75 + --wheel-dir "${WHEEL_BUILD_DIR}" 3>&1 >&2 ||
76 + die "Wheel build failed"
77 + )
78 + else
79 + local wheel=$(
80 + "${EPYTHON}" - 3>&1 >&2 <<-EOF || die "Wheel build failed"
81 + import ${build_backend%:*}
82 + import os
83 + print(${build_backend/:/.}.build_wheel(os.environ['WHEEL_BUILD_DIR']),
84 + file=os.fdopen(3, 'w'))
85 + EOF
86 + )
87 + fi
88 [[ -n ${wheel} ]] || die "No wheel name returned"
89
90 einfo " Installing the wheel to ${root}"
91 - # NB: --compile-bytecode does not produce the correct paths,
92 - # and python_optimize doesn't handle being called outside D,
93 - # so we just defer compiling until the final merge
94 - # NB: we override sys.prefix & sys.exec_prefix because otherwise
95 - # installer would use virtualenv's prefix
96 - local -x PYTHON_PREFIX=${EPREFIX}/usr
97 - "${EPYTHON}" - -d "${root}" "${WHEEL_BUILD_DIR}/${wheel}" --no-compile-bytecode \
98 - <<-EOF || die "installer failed"
99 - import os, sys
100 - sys.prefix = sys.exec_prefix = os.environ["PYTHON_PREFIX"]
101 - from installer.__main__ import main
102 - main(sys.argv[1:])
103 - EOF
104 + if [[ ${GPEP517_TESTING} ]]; then
105 + gpep517 install-wheel --destdir="${root}" --interpreter="${PYTHON}" \
106 + --prefix="${EPREFIX}/usr" "${WHEEL_BUILD_DIR}/${wheel}" ||
107 + die "Wheel install failed"
108 + else
109 + # NB: --compile-bytecode does not produce the correct paths,
110 + # and python_optimize doesn't handle being called outside D,
111 + # so we just defer compiling until the final merge
112 + # NB: we override sys.prefix & sys.exec_prefix because otherwise
113 + # installer would use virtualenv's prefix
114 + local -x PYTHON_PREFIX=${EPREFIX}/usr
115 + "${EPYTHON}" - -d "${root}" "${WHEEL_BUILD_DIR}/${wheel}" --no-compile-bytecode \
116 + <<-EOF || die "installer failed"
117 + import os, sys
118 + sys.prefix = sys.exec_prefix = os.environ["PYTHON_PREFIX"]
119 + from installer.__main__ import main
120 + main(sys.argv[1:])
121 + EOF
122 + fi
123
124 # remove installed licenses
125 find "${root}$(python_get_sitedir)" \
126 --
127 2.35.1