Gentoo Archives: gentoo-commits

From: "Michał Górny" <mgorny@g.o>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] repo/gentoo:master commit in: eclass/
Date: Sun, 16 Jan 2022 17:41:01
Message-Id: 1642354852.7ff39e403ecb492d9921826848ead926ea46ce3b.mgorny@gentoo
1 commit: 7ff39e403ecb492d9921826848ead926ea46ce3b
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Tue Nov 9 14:39:51 2021 +0000
4 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
5 CommitDate: Sun Jan 16 17:40:52 2022 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=7ff39e40
7
8 distutils-r1.eclass: Implement PEP517 mode
9
10 Add a PEP517 mode to the distutils-r1.eclass in order to facilitate
11 building packages via PEP517 backends. In order to use it, set
12 DISTUTILS_USE_PEP517 to the appropriate build system name. The eclass
13 will take care of setting BDEPEND, then invoke the backend to build
14 a wheel and then install its contents in python_compile(). The install
15 phase is limited to merging the staging area into the image directory.
16
17 In PEP517 mode, the test phase is automatically provided with venv-style
18 install tree that should suffice the vast majority of test suites.
19 As a result, distutils_install_for_testing should no longer be necessary
20 and is not available in this mode.
21
22 The new mode can also be used to install pre-PEP517 distutils
23 and setuptools packages. To do so, just specify setuptools backend.
24 If pyproject.toml is missing, the eclass assumes legacy setuptools
25 backend that invokes setup.py. It also enables setuptools-vendored
26 distutils, effectively carrying the migration from deprecated stdlib
27 version.
28
29 The PEP517 support effectively deprecates the legacy eclass mode.
30 This follows upstream deprecation of distutils and install commands
31 in setuptools.
32
33 Closes: https://github.com/gentoo/gentoo/pull/23750
34 Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
35
36 eclass/distutils-r1.eclass | 409 +++++++++++++++++++++++++++++++++++----------
37 1 file changed, 319 insertions(+), 90 deletions(-)
38
39 diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
40 index ba0226f8fed3..200360510f80 100644
41 --- a/eclass/distutils-r1.eclass
42 +++ b/eclass/distutils-r1.eclass
43 @@ -78,7 +78,35 @@ esac
44 # to be exported. It must be run in order for the eclass functions
45 # to function properly.
46
47 +# @ECLASS-VARIABLE: DISTUTILS_USE_PEP517
48 +# @PRE_INHERIT
49 +# @DEFAULT_UNSET
50 +# @DESCRIPTION:
51 +# Enable experimental PEP 517 mode for the specified build system.
52 +# In this mode, the complete build and install is done
53 +# in python_compile(), venv-style install tree is provided
54 +# to python_test() and python_install() just merges the temporary
55 +# install tree into real fs.
56 +#
57 +# The variable specifies the build system used. Currently,
58 +# the following values are supported:
59 +#
60 +# - flit - flit_core backend
61 +#
62 +# - pdm - pdm.pep517 backend
63 +#
64 +# - poetry - poetry-core backend
65 +#
66 +# - setuptools - distutils or setuptools (incl. legacy mode)
67 +#
68 +# - standalone - standalone build systems without external deps
69 +# (used for bootstrapping).
70 +#
71 +# The variable needs to be set before the inherit line. The eclass
72 +# adds appropriate build-time dependencies and verifies the value.
73 +
74 # @ECLASS-VARIABLE: DISTUTILS_USE_SETUPTOOLS
75 +# @DEFAULT_UNSET
76 # @PRE_INHERIT
77 # @DESCRIPTION:
78 # Controls adding dev-python/setuptools dependency. The allowed values
79 @@ -97,13 +125,13 @@ esac
80 # (assumes you will take care of doing it correctly)
81 #
82 # This variable is effective only if DISTUTILS_OPTIONAL is disabled.
83 -# It needs to be set before the inherit line.
84 -: ${DISTUTILS_USE_SETUPTOOLS:=bdepend}
85 +# It is available only in non-PEP517 mode. It needs to be set before
86 +# the inherit line.
87
88 if [[ ! ${_DISTUTILS_R1} ]]; then
89
90 [[ ${EAPI} == 6 ]] && inherit eutils xdg-utils
91 -inherit multiprocessing toolchain-funcs
92 +inherit multibuild multiprocessing toolchain-funcs
93
94 if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
95 inherit python-r1
96 @@ -121,25 +149,61 @@ if [[ ! ${_DISTUTILS_R1} ]]; then
97
98 _distutils_set_globals() {
99 local rdep bdep
100 - local setuptools_dep='>=dev-python/setuptools-42.0.2[${PYTHON_USEDEP}]'
101 + if [[ ${DISTUTILS_USE_PEP517} ]]; then
102 + if [[ ${DISTUTILS_USE_SETUPTOOLS} ]]; then
103 + die "DISTUTILS_USE_SETUPTOOLS is not used in PEP517 mode"
104 + fi
105
106 - case ${DISTUTILS_USE_SETUPTOOLS} in
107 - no|manual)
108 - ;;
109 - bdepend)
110 - bdep+=" ${setuptools_dep}"
111 - ;;
112 - rdepend)
113 - bdep+=" ${setuptools_dep}"
114 - rdep+=" ${setuptools_dep}"
115 - ;;
116 - pyproject.toml)
117 - bdep+=' >=dev-python/pyproject2setuppy-22[${PYTHON_USEDEP}]'
118 - ;;
119 - *)
120 - die "Invalid DISTUTILS_USE_SETUPTOOLS=${DISTUTILS_USE_SETUPTOOLS}"
121 - ;;
122 - esac
123 + # installer is used to install the wheel
124 + # tomli is used to read build-backend from pyproject.toml
125 + bdep+='
126 + >=dev-python/installer-0.4.0_p20220115[${PYTHON_USEDEP}]
127 + dev-python/tomli[${PYTHON_USEDEP}]'
128 + case ${DISTUTILS_USE_PEP517} in
129 + flit)
130 + bdep+='
131 + dev-python/flit_core[${PYTHON_USEDEP}]'
132 + ;;
133 + pdm)
134 + bdep+='
135 + dev-python/pdm-pep517[${PYTHON_USEDEP}]'
136 + ;;
137 + poetry)
138 + bdep+='
139 + dev-python/poetry-core[${PYTHON_USEDEP}]'
140 + ;;
141 + setuptools)
142 + bdep+='
143 + >=dev-python/setuptools-60.5.0[${PYTHON_USEDEP}]
144 + dev-python/wheel[${PYTHON_USEDEP}]'
145 + ;;
146 + standalone)
147 + ;;
148 + *)
149 + die "Unknown DISTUTILS_USE_PEP517=${DISTUTILS_USE_PEP517}"
150 + ;;
151 + esac
152 + else
153 + local setuptools_dep='>=dev-python/setuptools-42.0.2[${PYTHON_USEDEP}]'
154 +
155 + case ${DISTUTILS_USE_SETUPTOOLS:-bdepend} in
156 + no|manual)
157 + ;;
158 + bdepend)
159 + bdep+=" ${setuptools_dep}"
160 + ;;
161 + rdepend)
162 + bdep+=" ${setuptools_dep}"
163 + rdep+=" ${setuptools_dep}"
164 + ;;
165 + pyproject.toml)
166 + bdep+=' >=dev-python/pyproject2setuppy-22[${PYTHON_USEDEP}]'
167 + ;;
168 + *)
169 + die "Invalid DISTUTILS_USE_SETUPTOOLS=${DISTUTILS_USE_SETUPTOOLS}"
170 + ;;
171 + esac
172 + fi
173
174 if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
175 bdep=${bdep//\$\{PYTHON_USEDEP\}/${PYTHON_USEDEP}}
176 @@ -397,6 +461,9 @@ distutils_enable_tests() {
177 _DISTUTILS_TEST_INSTALL=
178 case ${1} in
179 --install)
180 + if [[ ${DISTUTILS_USE_PEP517} ]]; then
181 + die "${FUNCNAME} --install is not implemented in PEP517 mode"
182 + fi
183 _DISTUTILS_TEST_INSTALL=1
184 shift
185 ;;
186 @@ -469,11 +536,15 @@ esetup.py() {
187
188 _python_check_EPYTHON
189
190 - [[ ${BUILD_DIR} ]] && _distutils-r1_create_setup_cfg
191 + if [[ ${BUILD_DIR} && ! ${DISTUTILS_USE_PEP517} ]]; then
192 + _distutils-r1_create_setup_cfg
193 + fi
194
195 local setup_py=( setup.py )
196 if [[ ${DISTUTILS_USE_SETUPTOOLS} == pyproject.toml ]]; then
197 setup_py=( -m pyproject2setuppy )
198 + elif [[ ! -f setup.py ]]; then
199 + setup_py=( -c "from setuptools import setup; setup()" )
200 fi
201
202 if [[ ${EAPI} != [67] && ${mydistutilsargs[@]} ]]; then
203 @@ -487,7 +558,7 @@ esetup.py() {
204 "${@}" || die -n
205 local ret=${?}
206
207 - if [[ ${BUILD_DIR} ]]; then
208 + if [[ ${BUILD_DIR} && ! ${DISTUTILS_USE_PEP517} ]]; then
209 rm "${HOME}"/.pydistutils.cfg || die -n
210 fi
211
212 @@ -525,9 +596,17 @@ esetup.py() {
213 #
214 # Please note that in order to test the solution properly you need
215 # to unmerge the package first.
216 +#
217 +# This function is not available in PEP517 mode. The eclass provides
218 +# a venv-style install unconditionally therefore, and therefore it
219 +# should no longer be necessary.
220 distutils_install_for_testing() {
221 debug-print-function ${FUNCNAME} "${@}"
222
223 + if [[ ${DISTUTILS_USE_PEP517} ]]; then
224 + die "${FUNCNAME} is not implemented in PEP517 mode"
225 + fi
226 +
227 # A few notes about --via-home mode:
228 # 1) 'install --home' is terribly broken on pypy, so we need
229 # to override --install-lib and --install-scripts,
230 @@ -612,6 +691,10 @@ distutils_install_for_testing() {
231 # Stub out ez_setup.py and distribute_setup.py to prevent packages
232 # from trying to download a local copy of setuptools.
233 _distutils-r1_disable_ez_setup() {
234 + if [[ ${DISTUTILS_USE_PEP517} ]]; then
235 + die "${FUNCNAME} is not implemented in PEP517 mode"
236 + fi
237 +
238 local stub="def use_setuptools(*args, **kwargs): pass"
239 if [[ -f ez_setup.py ]]; then
240 echo "${stub}" > ez_setup.py || die
241 @@ -626,6 +709,10 @@ _distutils-r1_disable_ez_setup() {
242 # @DESCRIPTION:
243 # Generate setup.py for pyproject.toml if requested.
244 _distutils-r1_handle_pyproject_toml() {
245 + if [[ ${DISTUTILS_USE_PEP517} ]]; then
246 + die "${FUNCNAME} is not implemented in PEP517 mode"
247 + fi
248 +
249 [[ ${DISTUTILS_USE_SETUPTOOLS} == manual ]] && return
250
251 if [[ ! -f setup.py && -f pyproject.toml ]]; then
252 @@ -676,8 +763,10 @@ distutils-r1_python_prepare_all() {
253 fi
254 fi
255
256 - _distutils-r1_disable_ez_setup
257 - _distutils-r1_handle_pyproject_toml
258 + if [[ ! ${DISTUTILS_USE_PEP517} ]]; then
259 + _distutils-r1_disable_ez_setup
260 + _distutils-r1_handle_pyproject_toml
261 + fi
262
263 if [[ ${DISTUTILS_IN_SOURCE_BUILD} && ! ${DISTUTILS_SINGLE_IMPL} ]]
264 then
265 @@ -694,6 +783,10 @@ distutils-r1_python_prepare_all() {
266 # Create implementation-specific configuration file for distutils,
267 # setting proper build-dir (and install-dir) paths.
268 _distutils-r1_create_setup_cfg() {
269 + if [[ ${DISTUTILS_USE_PEP517} ]]; then
270 + die "${FUNCNAME} is not implemented in PEP517 mode"
271 + fi
272 +
273 cat > "${HOME}"/.pydistutils.cfg <<-_EOF_ || die
274 [build]
275 build_base = ${BUILD_DIR}
276 @@ -721,8 +814,8 @@ _distutils-r1_create_setup_cfg() {
277 zip_safe = False
278 _EOF_
279
280 - # we can't refer to ${D} before src_install()
281 if [[ ${EBUILD_PHASE} == install ]]; then
282 + # we can't refer to ${D} before src_install()
283 cat >> "${HOME}"/.pydistutils.cfg <<-_EOF_ || die
284
285 # installation paths -- allow calling extra install targets
286 @@ -734,6 +827,7 @@ _distutils-r1_create_setup_cfg() {
287 _EOF_
288
289 if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
290 + # this gets appended to [install]
291 cat >> "${HOME}"/.pydistutils.cfg <<-_EOF_ || die
292 install_scripts = $(python_get_scriptdir)
293 _EOF_
294 @@ -748,11 +842,44 @@ _distutils-r1_create_setup_cfg() {
295 # egg-base in esetup.py). This way, we respect whatever's in upstream
296 # egg-info.
297 _distutils-r1_copy_egg_info() {
298 + if [[ ${DISTUTILS_USE_PEP517} ]]; then
299 + die "${FUNCNAME} is not implemented in PEP517 mode"
300 + fi
301 +
302 mkdir -p "${BUILD_DIR}" || die
303 # stupid freebsd can't do 'cp -t ${BUILD_DIR} {} +'
304 find -name '*.egg-info' -type d -exec cp -R -p {} "${BUILD_DIR}"/ ';' || die
305 }
306
307 +# @FUNCTION: _distutils-r1_backend_to_key
308 +# @USAGE: <backend>
309 +# @INTERNAL
310 +# @DESCRIPTION:
311 +# Print the DISTUTILS_USE_PEP517 value corresponding to the backend
312 +# passed as the only argument.
313 +_distutils-r1_backend_to_key() {
314 + debug-print-function ${FUNCNAME} "${@}"
315 +
316 + local backend=${1}
317 + case ${backend} in
318 + flit_core.buildapi)
319 + echo flit
320 + ;;
321 + pdm.pep517.api)
322 + echo pdm
323 + ;;
324 + poetry.core.masonry.api)
325 + echo poetry
326 + ;;
327 + setuptools.build_meta|setuptools.build_meta:__legacy__)
328 + echo setuptools
329 + ;;
330 + *)
331 + die "Unknown backend: ${backend}"
332 + ;;
333 + esac
334 +}
335 +
336 # @FUNCTION: distutils-r1_python_compile
337 # @USAGE: [additional-args...]
338 # @DESCRIPTION:
339 @@ -767,16 +894,92 @@ distutils-r1_python_compile() {
340
341 _python_check_EPYTHON
342
343 - _distutils-r1_copy_egg_info
344 + # call setup.py build when using setuptools (either via PEP517
345 + # or in legacy mode)
346 + if [[ ${DISTUTILS_USE_PEP517:-setuptools} == setuptools ]]; then
347 + if [[ ! ${DISTUTILS_USE_PEP517} ]]; then
348 + _distutils-r1_copy_egg_info
349 + fi
350
351 - # distutils is parallel-capable since py3.5
352 - local jobs=$(makeopts_jobs "${MAKEOPTS}" INF)
353 - if [[ ${jobs} == INF ]]; then
354 - local nproc=$(get_nproc)
355 - jobs=$(( nproc + 1 ))
356 + # distutils is parallel-capable since py3.5
357 + local jobs=$(makeopts_jobs "${MAKEOPTS}" INF)
358 + if [[ ${jobs} == INF ]]; then
359 + local nproc=$(get_nproc)
360 + jobs=$(( nproc + 1 ))
361 + fi
362 +
363 + esetup.py build -j "${jobs}" "${@}"
364 fi
365
366 - esetup.py build -j "${jobs}" "${@}"
367 + if [[ ${DISTUTILS_USE_PEP517} ]]; then
368 + if [[ -n ${DISTUTILS_ARGS[@]} || -n ${mydistutilsargs[@]} ]]; then
369 + die "DISTUTILS_ARGS are not supported in PEP-517 mode"
370 + fi
371 +
372 + # python likes to compile any module it sees, which triggers sandbox
373 + # failures if some packages haven't compiled their modules yet.
374 + addpredict "${EPREFIX}/usr/lib/${EPYTHON}"
375 + addpredict /usr/lib/pypy3.8
376 + addpredict /usr/lib/portage/pym
377 + addpredict /usr/local # bug 498232
378 +
379 + local -x WHEEL_BUILD_DIR=${BUILD_DIR}/wheel
380 + mkdir -p "${WHEEL_BUILD_DIR}" || die
381 +
382 + local build_backend
383 + if [[ -f pyproject.toml ]]; then
384 + build_backend=$("${EPYTHON}" -c 'import tomli; \
385 + print(tomli.load(open("pyproject.toml", "rb")) \
386 + ["build-system"]["build-backend"])' 2>/dev/null)
387 + fi
388 + if [[ -z ${build_backend} && ${DISTUTILS_USE_PEP517} == setuptools &&
389 + -f setup.py ]]
390 + then
391 + # use the legacy setuptools backend
392 + build_backend=setuptools.build_meta:__legacy__
393 + fi
394 + [[ -z ${build_backend} ]] &&
395 + die "Unable to obtain build-backend from pyproject.toml"
396 +
397 + if [[ ${DISTUTILS_USE_PEP517} != standalone ]]; then
398 + local expected_value=$(_distutils-r1_backend_to_key "${build_backend}")
399 + if [[ ${DISTUTILS_USE_PEP517} != ${expected_value} ]]; then
400 + eerror "DISTUTILS_USE_PEP517 does not match pyproject.toml!"
401 + eerror " have: DISTUTILS_USE_PEP517=${DISTUTILS_USE_PEP517}"
402 + eerror "expected: DISTUTILS_USE_PEP517=${expected_value}"
403 + eerror "(backend: ${build_backend})"
404 + die "DISTUTILS_USE_PEP517 value incorrect"
405 + fi
406 + fi
407 +
408 + einfo "Building a wheel via ${build_backend}"
409 + "${EPYTHON}" -c "import ${build_backend%:*}; \
410 + import os; \
411 + ${build_backend/:/.}.build_wheel(os.environ['WHEEL_BUILD_DIR'])" ||
412 + die "Wheel build failed"
413 +
414 + local wheel=( "${WHEEL_BUILD_DIR}"/*.whl )
415 + if [[ ${#wheel[@]} -ne 1 ]]; then
416 + die "Incorrect number of wheels created (${#wheel[@]}): ${wheel[*]}"
417 + fi
418 +
419 + local root=${BUILD_DIR}/install
420 + # NB: --compile-bytecode does not produce the correct paths,
421 + # and python_optimize doesn't handle being called outside D,
422 + # so we just defer compiling until the final merge
423 + "${EPYTHON}" -m installer -d "${root}" "${wheel}" \
424 + --no-compile-bytecode ||
425 + die "installer failed"
426 +
427 + # enable venv magic inside the install tree
428 + mkdir -p "${root}"/usr/bin || die
429 + ln -s "${PYTHON}" "${root}/usr/bin/${EPYTHON}" || die
430 + ln -s "${EPYTHON}" "${root}/usr/bin/python3" || die
431 + ln -s "${EPYTHON}" "${root}/usr/bin/python" || die
432 + cat > "${root}"/usr/pyvenv.cfg <<-EOF || die
433 + include-system-site-packages = true
434 + EOF
435 + fi
436 }
437
438 # @FUNCTION: _distutils-r1_wrap_scripts
439 @@ -888,59 +1091,73 @@ distutils-r1_python_install() {
440
441 _python_check_EPYTHON
442
443 - local root=${D%/}/_${EPYTHON}
444 - [[ ${DISTUTILS_SINGLE_IMPL} ]] && root=${D%/}
445 -
446 - # inline DISTUTILS_ARGS logic from esetup.py in order to make
447 - # argv overwriting easier
448 - local args=(
449 - "${DISTUTILS_ARGS[@]}"
450 - "${mydistutilsargs[@]}"
451 - install --skip-build --root="${root}" "${args[@]}"
452 - "${@}"
453 - )
454 - local DISTUTILS_ARGS=()
455 - local mydistutilsargs=()
456 + local scriptdir=${EPREFIX}/usr/bin
457 + if [[ ${DISTUTILS_USE_PEP517} ]]; then
458 + local root=${BUILD_DIR}/install
459 + local rscriptdir=${root}$(python_get_scriptdir)
460 + [[ -d ${rscriptdir} ]] &&
461 + die "${rscriptdir} should not exist!"
462 + # remove venv magic
463 + rm "${root}"/usr/{pyvenv.cfg,bin/{python,python3,${EPYTHON}}} || die
464 + find "${root}"/usr/bin -empty -delete || die
465 + if [[ ! ${DISTUTILS_SINGLE_IMPL} && -d ${root}/usr/bin ]]; then
466 + mkdir -p "${rscriptdir%/*}" || die
467 + mv "${root}/usr/bin" "${rscriptdir}" || die
468 + fi
469 + else
470 + local root=${D%/}/_${EPYTHON}
471 + [[ ${DISTUTILS_SINGLE_IMPL} ]] && root=${D%/}
472 +
473 + # inline DISTUTILS_ARGS logic from esetup.py in order to make
474 + # argv overwriting easier
475 + local args=(
476 + "${DISTUTILS_ARGS[@]}"
477 + "${mydistutilsargs[@]}"
478 + install --skip-build --root="${root}" "${args[@]}"
479 + "${@}"
480 + )
481 + local DISTUTILS_ARGS=()
482 + local mydistutilsargs=()
483
484 - # enable compilation for the install phase.
485 - local -x PYTHONDONTWRITEBYTECODE=
486 + # enable compilation for the install phase.
487 + local -x PYTHONDONTWRITEBYTECODE=
488
489 - # python likes to compile any module it sees, which triggers sandbox
490 - # failures if some packages haven't compiled their modules yet.
491 - addpredict "${EPREFIX}/usr/lib/${EPYTHON}"
492 - addpredict /usr/lib/pypy3.8
493 - addpredict /usr/lib/portage/pym
494 - addpredict /usr/local # bug 498232
495 + # python likes to compile any module it sees, which triggers sandbox
496 + # failures if some packages haven't compiled their modules yet.
497 + addpredict "${EPREFIX}/usr/lib/${EPYTHON}"
498 + addpredict /usr/lib/pypy3.8
499 + addpredict /usr/lib/portage/pym
500 + addpredict /usr/local # bug 498232
501
502 - if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
503 - # user may override --install-scripts
504 - # note: this is poor but distutils argv parsing is dumb
505 - local scriptdir=${EPREFIX}/usr/bin
506 -
507 - # rewrite all the arguments
508 - set -- "${args[@]}"
509 - args=()
510 - while [[ ${@} ]]; do
511 - local a=${1}
512 - shift
513 + if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
514 + # user may override --install-scripts
515 + # note: this is poor but distutils argv parsing is dumb
516 +
517 + # rewrite all the arguments
518 + set -- "${args[@]}"
519 + args=()
520 + while [[ ${@} ]]; do
521 + local a=${1}
522 + shift
523 +
524 + case ${a} in
525 + --install-scripts=*)
526 + scriptdir=${a#--install-scripts=}
527 + ;;
528 + --install-scripts)
529 + scriptdir=${1}
530 + shift
531 + ;;
532 + *)
533 + args+=( "${a}" )
534 + ;;
535 + esac
536 + done
537 + fi
538
539 - case ${a} in
540 - --install-scripts=*)
541 - scriptdir=${a#--install-scripts=}
542 - ;;
543 - --install-scripts)
544 - scriptdir=${1}
545 - shift
546 - ;;
547 - *)
548 - args+=( "${a}" )
549 - ;;
550 - esac
551 - done
552 + esetup.py "${args[@]}"
553 fi
554
555 - esetup.py "${args[@]}"
556 -
557 local forbidden_package_names=(
558 examples test tests
559 .pytest_cache .hypothesis
560 @@ -964,8 +1181,15 @@ distutils-r1_python_install() {
561 die "Package installs 'share' in PyPy prefix, see bug #465546."
562 fi
563
564 - if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
565 + if [[ ! ${DISTUTILS_SINGLE_IMPL} || ${DISTUTILS_USE_PEP517} ]]; then
566 multibuild_merge_root "${root}" "${D%/}"
567 + if [[ ${DISTUTILS_USE_PEP517} ]]; then
568 + # we need to recompile everything here in order to embed
569 + # the correct paths
570 + python_optimize "${D%/}$(python_get_sitedir)"
571 + fi
572 + fi
573 + if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
574 _distutils-r1_wrap_scripts "${scriptdir}"
575 fi
576 }
577 @@ -1006,12 +1230,21 @@ distutils-r1_run_phase() {
578 fi
579 local BUILD_DIR=${BUILD_DIR}/build
580 fi
581 - local -x PYTHONPATH="${BUILD_DIR}/lib:${PYTHONPATH}"
582
583 - # make PATH local for distutils_install_for_testing calls
584 - # it makes little sense to let user modify PATH in per-impl phases
585 - # and _all() already localizes it
586 - local -x PATH=${PATH}
587 + if [[ ${DISTUTILS_USE_PEP517} ]]; then
588 + local -x PATH=${BUILD_DIR}/install/usr/bin:${PATH}
589 + else
590 + local -x PYTHONPATH="${BUILD_DIR}/lib:${PYTHONPATH}"
591 +
592 + # make PATH local for distutils_install_for_testing calls
593 + # it makes little sense to let user modify PATH in per-impl phases
594 + # and _all() already localizes it
595 + local -x PATH=${PATH}
596 +
597 + # Undo the default switch in setuptools-60+ for the time being,
598 + # to avoid replacing .egg-info file with directory in-place.
599 + local -x SETUPTOOLS_USE_DISTUTILS="${SETUPTOOLS_USE_DISTUTILS:-stdlib}"
600 + fi
601
602 # Bug 559644
603 # using PYTHONPATH when the ${BUILD_DIR}/lib is not created yet might lead to
604 @@ -1037,10 +1270,6 @@ distutils-r1_run_phase() {
605
606 local -x LDSHARED="${CC} ${ldopts}" LDCXXSHARED="${CXX} ${ldopts}"
607
608 - # Undo the default switch in setuptools-60+ for the time being,
609 - # to avoid replacing .egg-info file with directory in-place.
610 - local -x SETUPTOOLS_USE_DISTUTILS="${SETUPTOOLS_USE_DISTUTILS:-stdlib}"
611 -
612 "${@}"
613
614 cd "${_DISTUTILS_INITIAL_CWD}" || die