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: Tue, 07 Jun 2022 06:54:58
Message-Id: 1654584828.de2e1bee2462fccc445b845a889b006f888c6b1d.mgorny@gentoo
1 commit: de2e1bee2462fccc445b845a889b006f888c6b1d
2 Author: Michał Górny <mgorny <AT> gentoo <DOT> org>
3 AuthorDate: Tue May 31 09:51:22 2022 +0000
4 Commit: Michał Górny <mgorny <AT> gentoo <DOT> org>
5 CommitDate: Tue Jun 7 06:53:48 2022 +0000
6 URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=de2e1bee
7
8 distutils-r1.eclass: Move venv/merge-root logic to post-phases
9
10 Move the PEP517 venv logic, install executable wrapping and root-merging
11 logic all into post-phases. This will enable the ebuilds that do not
12 use the standard phase implementations to use them.
13
14 Signed-off-by: Michał Górny <mgorny <AT> gentoo.org>
15
16 eclass/distutils-r1.eclass | 124 ++++++++++++++++++++++++++-------------------
17 1 file changed, 73 insertions(+), 51 deletions(-)
18
19 diff --git a/eclass/distutils-r1.eclass b/eclass/distutils-r1.eclass
20 index 1d7bea6d8cab..208bd2718cb8 100644
21 --- a/eclass/distutils-r1.eclass
22 +++ b/eclass/distutils-r1.eclass
23 @@ -1361,33 +1361,7 @@ distutils-r1_python_compile() {
24 addpredict /usr/lib/portage/pym
25 addpredict /usr/local # bug 498232
26
27 - local root=${BUILD_DIR}/install
28 - distutils_pep517_install "${root}"
29 -
30 - # copy executables to python-exec directory
31 - # we do it early so that we can alter bindir recklessly
32 - local bindir=${root}${EPREFIX}/usr/bin
33 - local rscriptdir=${root}$(python_get_scriptdir)
34 - [[ -d ${rscriptdir} ]] &&
35 - die "${rscriptdir} should not exist!"
36 - if [[ -d ${bindir} ]]; then
37 - mkdir -p "${rscriptdir}" || die
38 - cp -a --reflink=auto "${bindir}"/. "${rscriptdir}"/ || die
39 - fi
40 -
41 - # enable venv magic inside the install tree
42 - mkdir -p "${bindir}" || die
43 - ln -s "${PYTHON}" "${bindir}/${EPYTHON}" || die
44 - ln -s "${EPYTHON}" "${bindir}/python3" || die
45 - ln -s "${EPYTHON}" "${bindir}/python" || die
46 - cat > "${bindir}"/pyvenv.cfg <<-EOF || die
47 - include-system-site-packages = true
48 - EOF
49 -
50 - # we need to change shebangs to point to the venv-python
51 - find "${bindir}" -type f -exec sed -i \
52 - -e "1s@^#!\(${EPREFIX}/usr/bin/\(python\|pypy\)\)@#!${root}\1@" \
53 - {} + || die
54 + distutils_pep517_install "${BUILD_DIR}/install"
55 fi
56 }
57
58 @@ -1501,18 +1475,7 @@ distutils-r1_python_install() {
59 _python_check_EPYTHON
60
61 local scriptdir=${EPREFIX}/usr/bin
62 - if [[ ${DISTUTILS_USE_PEP517} ]]; then
63 - local root=${BUILD_DIR}/install
64 - # remove the altered bindir, executables from the package
65 - # are already in scriptdir
66 - rm -r "${root}${scriptdir}" || die
67 - if [[ ${DISTUTILS_SINGLE_IMPL} ]]; then
68 - local wrapped_scriptdir=${root}$(python_get_scriptdir)
69 - if [[ -d ${wrapped_scriptdir} ]]; then
70 - mv "${wrapped_scriptdir}" "${root}${scriptdir}" || die
71 - fi
72 - fi
73 - else
74 + if [[ ! ${DISTUTILS_USE_PEP517} ]]; then
75 local root=${D%/}/_${EPYTHON}
76 [[ ${DISTUTILS_SINGLE_IMPL} ]] && root=${D%/}
77
78 @@ -1565,18 +1528,6 @@ distutils-r1_python_install() {
79
80 esetup.py "${args[@]}"
81 fi
82 -
83 - if [[ ! ${DISTUTILS_SINGLE_IMPL} || ${DISTUTILS_USE_PEP517} ]]; then
84 - multibuild_merge_root "${root}" "${D%/}"
85 - if [[ ${DISTUTILS_USE_PEP517} ]]; then
86 - # we need to recompile everything here in order to embed
87 - # the correct paths
88 - python_optimize "${D%/}$(python_get_sitedir)"
89 - fi
90 - fi
91 - if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
92 - _distutils-r1_wrap_scripts "${scriptdir}"
93 - fi
94 }
95
96 # @FUNCTION: distutils-r1_python_install_all
97 @@ -1764,6 +1715,43 @@ distutils-r1_src_configure() {
98 return ${ret}
99 }
100
101 +# @FUNCTION: _distutils-r1_post_python_compile
102 +# @INTERNAL
103 +# @DESCRIPTION:
104 +# Post-phase function called after python_compile. In PEP517 mode,
105 +# it adjusts the install tree for venv-style usage.
106 +_distutils-r1_post_python_compile() {
107 + debug-print-function ${FUNCNAME} "${@}"
108 +
109 + local root=${BUILD_DIR}/install
110 + if [[ ${DISTUTILS_USE_PEP517} && -d ${root} ]]; then
111 + # copy executables to python-exec directory
112 + # we do it early so that we can alter bindir recklessly
113 + local bindir=${root}${EPREFIX}/usr/bin
114 + local rscriptdir=${root}$(python_get_scriptdir)
115 + [[ -d ${rscriptdir} ]] &&
116 + die "${rscriptdir} should not exist!"
117 + if [[ -d ${bindir} ]]; then
118 + mkdir -p "${rscriptdir}" || die
119 + cp -a --reflink=auto "${bindir}"/. "${rscriptdir}"/ || die
120 + fi
121 +
122 + # enable venv magic inside the install tree
123 + mkdir -p "${bindir}" || die
124 + ln -s "${PYTHON}" "${bindir}/${EPYTHON}" || die
125 + ln -s "${EPYTHON}" "${bindir}/python3" || die
126 + ln -s "${EPYTHON}" "${bindir}/python" || die
127 + cat > "${bindir}"/pyvenv.cfg <<-EOF || die
128 + include-system-site-packages = true
129 + EOF
130 +
131 + # we need to change shebangs to point to the venv-python
132 + find "${bindir}" -type f -exec sed -i \
133 + -e "1s@^#!\(${EPREFIX}/usr/bin/\(python\|pypy\)\)@#!${root}\1@" \
134 + {} + || die
135 + fi
136 +}
137 +
138 distutils-r1_src_compile() {
139 debug-print-function ${FUNCNAME} "${@}"
140 local ret=0
141 @@ -1829,6 +1817,40 @@ distutils-r1_src_test() {
142 _distutils-r1_post_python_install() {
143 debug-print-function ${FUNCNAME} "${@}"
144
145 + local root=${D%/}/_${EPYTHON}
146 + [[ ${DISTUTILS_USE_PEP517} ]] && root=${BUILD_DIR}/install
147 + local scriptdir=${EPREFIX}/usr/bin
148 + if [[ -d ${root} && ${DISTUTILS_USE_PEP517} ]]; then
149 + # remove the altered bindir, executables from the package
150 + # are already in scriptdir
151 + rm -r "${root}${scriptdir}" || die
152 + if [[ ${DISTUTILS_SINGLE_IMPL} ]]; then
153 + local wrapped_scriptdir=${root}$(python_get_scriptdir)
154 + if [[ -d ${wrapped_scriptdir} ]]; then
155 + mv "${wrapped_scriptdir}" "${root}${scriptdir}" || die
156 + fi
157 + fi
158 +
159 + # prune empty directories to see if ${root} contains anything
160 + # to merge
161 + find "${BUILD_DIR}"/install -type d -empty -delete || die
162 + fi
163 +
164 + if [[ -d ${root} ]]; then
165 + if [[ ! ${DISTUTILS_SINGLE_IMPL} || ${DISTUTILS_USE_PEP517} ]]; then
166 + multibuild_merge_root "${root}" "${D%/}"
167 + fi
168 + fi
169 + local pypath=${D%/}$(python_get_sitedir)
170 + if [[ ${DISTUTILS_USE_PEP517} && -d ${pypath} ]]; then
171 + # we need to recompile everything here in order to embed
172 + # the correct paths
173 + python_optimize "${pypath}"
174 + fi
175 + if [[ ! ${DISTUTILS_SINGLE_IMPL} ]]; then
176 + _distutils-r1_wrap_scripts "${scriptdir}"
177 + fi
178 +
179 local forbidden_package_names=(
180 examples test tests
181 .pytest_cache .hypothesis