Gentoo Archives: gentoo-dev

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