1 |
commit: a09934ce1b026924c173d535d06e55a3126add04 |
2 |
Author: Michał Górny <mgorny <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Jul 18 08:52:40 2022 +0000 |
4 |
Commit: Michał Górny <mgorny <AT> gentoo <DOT> org> |
5 |
CommitDate: Tue Aug 2 04:04:28 2022 +0000 |
6 |
URL: https://gitweb.gentoo.org/repo/gentoo.git/commit/?id=a09934ce |
7 |
|
8 |
install-qa-check.d: Rewrite 60python-pyc to use gpep517 |
9 |
|
10 |
Signed-off-by: Michał Górny <mgorny <AT> gentoo.org> |
11 |
|
12 |
metadata/install-qa-check.d/60python-pyc | 168 ++++++++++++++++++------------- |
13 |
1 file changed, 96 insertions(+), 72 deletions(-) |
14 |
|
15 |
diff --git a/metadata/install-qa-check.d/60python-pyc b/metadata/install-qa-check.d/60python-pyc |
16 |
index 47e9a3eea908..fd9434994f2f 100644 |
17 |
--- a/metadata/install-qa-check.d/60python-pyc |
18 |
+++ b/metadata/install-qa-check.d/60python-pyc |
19 |
@@ -4,86 +4,110 @@ |
20 |
# QA check: ensure that Python modules are compiled after installing |
21 |
# Maintainer: Python project <python@g.o> |
22 |
|
23 |
-# EAPI guard to prevent errors from trying to import python-utils-r1 |
24 |
-# in unsupported EAPIs. Please keep the list in sync with the eclass! |
25 |
-if [[ ${EAPI} == [6-8] ]]; then |
26 |
- inherit python-utils-r1 |
27 |
+python_pyc_check() { |
28 |
+ local save=$(shopt -p nullglob) |
29 |
+ shopt -s nullglob |
30 |
+ local progs=( "${EPREFIX}"/usr/lib/python-exec/*/gpep517 ) |
31 |
+ ${save} |
32 |
|
33 |
- python_pyc_check() { |
34 |
- local impl missing=() outdated=() |
35 |
- for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do |
36 |
- _python_export "${impl}" EPYTHON PYTHON |
37 |
- [[ -x ${PYTHON} ]] || continue |
38 |
- local sitedir=$(python_get_sitedir "${impl}") |
39 |
+ local invalid=() |
40 |
+ local mismatched_timestamp=() |
41 |
+ local mismatched_data=() |
42 |
+ local missing=() |
43 |
+ local stray=() |
44 |
|
45 |
- if [[ -d ${D}${sitedir} ]]; then |
46 |
- local suffixes=() subdir= |
47 |
- case ${EPYTHON} in |
48 |
- python2*) |
49 |
- suffixes=( .py{c,o} ) |
50 |
- ;; |
51 |
- pypy) |
52 |
- suffixes=( .pyc ) |
53 |
- ;; |
54 |
- python3*|pypy3*) |
55 |
- local tag=$("${PYTHON}" -c 'import sys; print(sys.implementation.cache_tag)') |
56 |
- suffixes=( ".${tag}"{,.opt-{1,2}}.pyc ) |
57 |
- subdir=__pycache__/ |
58 |
- ;; |
59 |
- *) |
60 |
- # skip testing unknown impl |
61 |
- continue |
62 |
- ;; |
63 |
- esac |
64 |
+ for prog in "${progs[@]}"; do |
65 |
+ local impl=${prog%/*} |
66 |
+ impl=${impl##*/} |
67 |
+ einfo "Verifying compiled files for ${impl}" |
68 |
+ local kind pyc py |
69 |
+ while IFS=: read -r kind pyc py extra; do |
70 |
+ case ${kind} in |
71 |
+ invalid) |
72 |
+ invalid+=( "${pyc}" ) |
73 |
+ ;; |
74 |
+ mismatched) |
75 |
+ case ${extra} in |
76 |
+ timestamp) |
77 |
+ mismatched_timestamp+=( "${pyc}" ) |
78 |
+ ;; |
79 |
+ *) |
80 |
+ mismatched_data+=( "${pyc}" ) |
81 |
+ ;; |
82 |
+ esac |
83 |
+ ;; |
84 |
+ missing) |
85 |
+ missing+=( "${pyc}" ) |
86 |
+ ;; |
87 |
+ older) |
88 |
+ # older warnings were produced by earlier version |
89 |
+ # of gpep517 but the check was incorrect, so we just |
90 |
+ # ignore them |
91 |
+ ;; |
92 |
+ stray) |
93 |
+ stray+=( "${pyc}" ) |
94 |
+ ;; |
95 |
+ esac |
96 |
+ done < <("${prog}" verify-pyc --destdir "${D}" --prefix "${EPREFIX}"/usr) |
97 |
+ done |
98 |
|
99 |
- einfo "Verifying compiled files in ${sitedir}" |
100 |
- local f s |
101 |
- while read -d $'\0' -r f; do |
102 |
- local dir=${f%/*} |
103 |
- local basename=${f##*/} |
104 |
- basename=${basename%.py} |
105 |
+ local found= |
106 |
+ if [[ ${missing[@]} ]]; then |
107 |
+ eqawarn |
108 |
+ eqawarn "QA Notice: This package installs one or more Python modules that are" |
109 |
+ eqawarn "not byte-compiled." |
110 |
+ eqawarn "The following files are missing:" |
111 |
+ eqawarn |
112 |
+ eqatag -v python-pyc.missing "${missing[@]}" |
113 |
+ found=1 |
114 |
+ fi |
115 |
|
116 |
- for s in "${suffixes[@]}"; do |
117 |
- local cache=${dir}/${subdir}${basename}${s} |
118 |
- if [[ ! -f ${cache} ]]; then |
119 |
- missing+=( "${cache}" ) |
120 |
- elif [[ ${f} -nt ${cache} ]]; then |
121 |
- outdated+=( "${cache}" ) |
122 |
- fi |
123 |
- done |
124 |
- done < <(find "${D}${sitedir}" -name '*.py' -print0) |
125 |
- fi |
126 |
- done |
127 |
+ if [[ ${invalid[@]} ]]; then |
128 |
+ eqawarn |
129 |
+ eqawarn "QA Notice: This package installs one or more compiled Python modules" |
130 |
+ eqawarn "that seem to be invalid (do not have the correct header)." |
131 |
+ eqawarn "The following files are invalid:" |
132 |
+ eqawarn |
133 |
+ eqatag -v python-pyc.invalid "${invalid[@]}" |
134 |
+ found=1 |
135 |
+ fi |
136 |
|
137 |
- if [[ ${missing[@]} ]]; then |
138 |
- eqawarn |
139 |
- eqawarn "QA Notice: This package installs one or more Python modules that are" |
140 |
- eqawarn "not byte-compiled." |
141 |
- eqawarn "The following files are missing:" |
142 |
- eqawarn |
143 |
- eqatag -v python-pyc.missing "${missing[@]#${D}}" |
144 |
- fi |
145 |
+ if [[ ${mismatched_data[@]} ]]; then |
146 |
+ eqawarn |
147 |
+ eqawarn "QA Notice: This package installs one or more compiled Python modules whose" |
148 |
+ eqawarn ".py files have different content (size or hash) than recorded:" |
149 |
+ eqawarn |
150 |
+ eqatag -v python-pyc.mismatched.data "${mismatched_data[@]}" |
151 |
+ found=1 |
152 |
+ fi |
153 |
|
154 |
- if [[ ${outdated[@]} ]]; then |
155 |
- eqawarn |
156 |
- eqawarn "QA Notice: This package installs one or more compiled Python modules that have" |
157 |
- eqawarn "older timestamps than the corresponding source files:" |
158 |
- eqawarn |
159 |
- eqatag -v python-pyc.outdated "${outdated[@]#${D}}" |
160 |
- fi |
161 |
+ if [[ ${mismatched_timestamp[@]} ]]; then |
162 |
+ eqawarn |
163 |
+ eqawarn "QA Notice: This package installs one or more compiled Python modules whose" |
164 |
+ eqawarn ".py files have different timestamps than recorded:" |
165 |
+ eqawarn |
166 |
+ eqatag -v python-pyc.mismatched.timestamp "${mismatched_timestamp[@]}" |
167 |
+ found=1 |
168 |
+ fi |
169 |
|
170 |
- if [[ ${missing[@]} || ${outdated[@]} ]]; then |
171 |
- eqawarn |
172 |
- eqawarn "Please either fix the upstream build system to byte-compile Python modules" |
173 |
- eqawarn "correctly, or call python_optimize after installing them. For more" |
174 |
- eqawarn "information, see:" |
175 |
- eqawarn "https://projects.gentoo.org/python/guide/helper.html#byte-compiling-python-modules" |
176 |
- eqawarn |
177 |
- fi |
178 |
- } |
179 |
+ if [[ ${stray[@]} ]]; then |
180 |
+ eqawarn |
181 |
+ eqawarn "QA Notice: This package installs one or more compiled Python modules" |
182 |
+ eqawarn "that do not match installed modules (or their implementation)." |
183 |
+ eqawarn "The following files are stray:" |
184 |
+ eqawarn |
185 |
+ eqatag -v python-pyc.stray "${stray[@]}" |
186 |
+ found=1 |
187 |
+ fi |
188 |
|
189 |
- python_pyc_check |
190 |
-fi |
191 |
+ if [[ ${found} ]]; then |
192 |
+ eqawarn |
193 |
+ eqawarn "For more information on bytecode files and related issues, please see:" |
194 |
+ eqawarn " https://projects.gentoo.org/python/guide/qawarn.html#compiled-bytecode-related-warnings" |
195 |
+ fi |
196 |
+} |
197 |
+ |
198 |
+python_pyc_check |
199 |
|
200 |
: # guarantee successful exit |