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