1 |
Signed-off-by: Michał Górny <mgorny@g.o> |
2 |
--- |
3 |
eclass/distutils-r1.eclass | 110 +++++++++++++++++++++---------------- |
4 |
1 file changed, 63 insertions(+), 47 deletions(-) |
5 |
|
6 |
diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass |
7 |
index 2b5acb09d926..81eea83c67b3 100644 |
8 |
--- a/eclass/distutils-r1.eclass |
9 |
+++ b/eclass/distutils-r1.eclass |
10 |
@@ -922,6 +922,68 @@ _distutils-r1_backend_to_key() { |
11 |
esac |
12 |
} |
13 |
|
14 |
+# @FUNCTION: _distutils-r1_get_backend |
15 |
+# @INTERNAL |
16 |
+# @DESCRIPTION: |
17 |
+# Read (or guess, in case of setuptools) the build-backend |
18 |
+# for the package in the current directory. |
19 |
+_distutils-r1_get_backend() { |
20 |
+ debug-print-function ${FUNCNAME} "${@}" |
21 |
+ |
22 |
+ local build_backend |
23 |
+ if [[ -f pyproject.toml ]]; then |
24 |
+ # if pyproject.toml exists, try getting the backend from it |
25 |
+ # NB: this could fail if pyproject.toml doesn't list one |
26 |
+ build_backend=$("${EPYTHON}" -c 'import tomli; \ |
27 |
+ print(tomli.load(open("pyproject.toml", "rb")) \ |
28 |
+ ["build-system"]["build-backend"])' 2>/dev/null) |
29 |
+ fi |
30 |
+ if [[ -z ${build_backend} && ${DISTUTILS_USE_PEP517} == setuptools && |
31 |
+ -f setup.py ]] |
32 |
+ then |
33 |
+ # use the legacy setuptools backend as a fallback |
34 |
+ build_backend=setuptools.build_meta:__legacy__ |
35 |
+ fi |
36 |
+ if [[ -z ${build_backend} ]]; then |
37 |
+ die "Unable to obtain build-backend from pyproject.toml" |
38 |
+ fi |
39 |
+ |
40 |
+ if [[ ${DISTUTILS_USE_PEP517} != standalone ]]; then |
41 |
+ # verify whether DISTUTILS_USE_PEP517 was set correctly |
42 |
+ local expected_value=$(_distutils-r1_backend_to_key "${build_backend}") |
43 |
+ if [[ ${DISTUTILS_USE_PEP517} != ${expected_value} ]]; then |
44 |
+ eerror "DISTUTILS_USE_PEP517 does not match pyproject.toml!" |
45 |
+ eerror " have: DISTUTILS_USE_PEP517=${DISTUTILS_USE_PEP517}" |
46 |
+ eerror "expected: DISTUTILS_USE_PEP517=${expected_value}" |
47 |
+ eerror "(backend: ${build_backend})" |
48 |
+ die "DISTUTILS_USE_PEP517 value incorrect" |
49 |
+ fi |
50 |
+ |
51 |
+ # fix deprecated backends up |
52 |
+ local new_backend= |
53 |
+ case ${build_backend} in |
54 |
+ flit.buildapi) |
55 |
+ new_backend=flit_core.buildapi |
56 |
+ ;; |
57 |
+ poetry.masonry.api) |
58 |
+ new_backend=poetry.core.masonry.api |
59 |
+ ;; |
60 |
+ esac |
61 |
+ |
62 |
+ if [[ -n ${new_backend} ]]; then |
63 |
+ if [[ ! -f ${T}/.distutils_deprecated_backend_warned ]]; then |
64 |
+ eqawarn "${build_backend} backend is deprecated. Please see:" |
65 |
+ eqawarn "https://projects.gentoo.org/python/guide/distutils.html#deprecated-pep-517-backends" |
66 |
+ eqawarn "The eclass will be using ${new_backend} instead." |
67 |
+ > "${T}"/.distutils_deprecated_backend_warned || die |
68 |
+ fi |
69 |
+ build_backend=${new_backend} |
70 |
+ fi |
71 |
+ fi |
72 |
+ |
73 |
+ echo "${build_backend}" |
74 |
+} |
75 |
+ |
76 |
# @FUNCTION: distutils-r1_python_compile |
77 |
# @USAGE: [additional-args...] |
78 |
# @DESCRIPTION: |
79 |
@@ -968,53 +1030,7 @@ distutils-r1_python_compile() { |
80 |
local -x WHEEL_BUILD_DIR=${BUILD_DIR}/wheel |
81 |
mkdir -p "${WHEEL_BUILD_DIR}" || die |
82 |
|
83 |
- local build_backend |
84 |
- if [[ -f pyproject.toml ]]; then |
85 |
- build_backend=$("${EPYTHON}" -c 'import tomli; \ |
86 |
- print(tomli.load(open("pyproject.toml", "rb")) \ |
87 |
- ["build-system"]["build-backend"])' 2>/dev/null) |
88 |
- fi |
89 |
- if [[ -z ${build_backend} && ${DISTUTILS_USE_PEP517} == setuptools && |
90 |
- -f setup.py ]] |
91 |
- then |
92 |
- # use the legacy setuptools backend |
93 |
- build_backend=setuptools.build_meta:__legacy__ |
94 |
- fi |
95 |
- [[ -z ${build_backend} ]] && |
96 |
- die "Unable to obtain build-backend from pyproject.toml" |
97 |
- |
98 |
- if [[ ${DISTUTILS_USE_PEP517} != standalone ]]; then |
99 |
- local expected_value=$(_distutils-r1_backend_to_key "${build_backend}") |
100 |
- if [[ ${DISTUTILS_USE_PEP517} != ${expected_value} ]]; then |
101 |
- eerror "DISTUTILS_USE_PEP517 does not match pyproject.toml!" |
102 |
- eerror " have: DISTUTILS_USE_PEP517=${DISTUTILS_USE_PEP517}" |
103 |
- eerror "expected: DISTUTILS_USE_PEP517=${expected_value}" |
104 |
- eerror "(backend: ${build_backend})" |
105 |
- die "DISTUTILS_USE_PEP517 value incorrect" |
106 |
- fi |
107 |
- |
108 |
- # fix deprecated backends up |
109 |
- local new_backend= |
110 |
- case ${build_backend} in |
111 |
- flit.buildapi) |
112 |
- new_backend=flit_core.buildapi |
113 |
- ;; |
114 |
- poetry.masonry.api) |
115 |
- new_backend=poetry.core.masonry.api |
116 |
- ;; |
117 |
- esac |
118 |
- |
119 |
- if [[ -n ${new_backend} ]]; then |
120 |
- if [[ ! ${_DISTUTILS_DEPRECATED_BACKEND_WARNED} ]]; then |
121 |
- eqawarn "${build_backend} backend is deprecated. Please see:" |
122 |
- eqawarn "https://projects.gentoo.org/python/guide/distutils.html#deprecated-pep-517-backends" |
123 |
- eqawarn "The eclass will be using ${new_backend} instead." |
124 |
- _DISTUTILS_DEPRECATED_BACKEND_WARNED=1 |
125 |
- fi |
126 |
- build_backend=${new_backend} |
127 |
- fi |
128 |
- fi |
129 |
- |
130 |
+ local build_backend=$(_distutils-r1_get_backend) |
131 |
einfo " Building the wheel via ${build_backend}" |
132 |
"${EPYTHON}" -c "import ${build_backend%:*}; \ |
133 |
import os; \ |
134 |
-- |
135 |
2.35.1 |