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