1 |
Add a check that detects Python modules that were not compiled after |
2 |
installation. To limit false positives, this is only done on modules |
3 |
installed to site-packages. |
4 |
|
5 |
Early testing of this check made it possible to detect a bug |
6 |
in python_optimize. |
7 |
|
8 |
Signed-off-by: Michał Górny <mgorny@g.o> |
9 |
--- |
10 |
metadata/install-qa-check.d/60python-pyc | 83 ++++++++++++++++++++++++ |
11 |
1 file changed, 83 insertions(+) |
12 |
create mode 100644 metadata/install-qa-check.d/60python-pyc |
13 |
|
14 |
diff --git a/metadata/install-qa-check.d/60python-pyc b/metadata/install-qa-check.d/60python-pyc |
15 |
new file mode 100644 |
16 |
index 000000000000..7fe3b0c963d1 |
17 |
--- /dev/null |
18 |
+++ b/metadata/install-qa-check.d/60python-pyc |
19 |
@@ -0,0 +1,83 @@ |
20 |
+# Copyright 2019 Gentoo Authors |
21 |
+# Distributed under the terms of the GNU General Public License v2 |
22 |
+ |
23 |
+# QA check: ensure that Python modules are compiled after installing |
24 |
+# Maintainer: Python project <python@g.o> |
25 |
+ |
26 |
+inherit python-utils-r1 |
27 |
+ |
28 |
+python_pyc_check() { |
29 |
+ local impl missing=() outdated=() |
30 |
+ for impl in "${_PYTHON_SUPPORTED_IMPLS[@]}"; do |
31 |
+ python_export "${impl}" EPYTHON PYTHON |
32 |
+ local sitedir=$(python_get_sitedir "${impl}") |
33 |
+ |
34 |
+ if [[ -d ${D}${sitedir} ]]; then |
35 |
+ local suffixes=() subdir= |
36 |
+ case ${EPYTHON} in |
37 |
+ python2*) |
38 |
+ suffixes=( .py{c,o} ) |
39 |
+ ;; |
40 |
+ pypy) |
41 |
+ suffixes=( .pyc ) |
42 |
+ ;; |
43 |
+ python3*|pypy3*) |
44 |
+ local tag=$("${PYTHON}" -c 'import sys; print(sys.implementation.cache_tag)') |
45 |
+ suffixes=( ".${tag}"{,.opt-{1,2}}.pyc ) |
46 |
+ subdir=__pycache__/ |
47 |
+ ;; |
48 |
+ *) |
49 |
+ # skip testing unknown impl |
50 |
+ continue |
51 |
+ ;; |
52 |
+ esac |
53 |
+ |
54 |
+ einfo "Verifying compiled files in ${sitedir}" |
55 |
+ local f s |
56 |
+ while read -d $'\0' -r f; do |
57 |
+ local dir=${f%/*} |
58 |
+ local basename=${f##*/} |
59 |
+ basename=${basename%.py} |
60 |
+ |
61 |
+ for s in "${suffixes[@]}"; do |
62 |
+ local cache=${dir}/${subdir}${basename}${s} |
63 |
+ if [[ ! -f ${cache} ]]; then |
64 |
+ missing+=( "${cache}" ) |
65 |
+ elif [[ ${f} -nt ${cache} ]]; then |
66 |
+ outdated+=( "${cache}" ) |
67 |
+ fi |
68 |
+ done |
69 |
+ done < <(find "${D}${sitedir}" -name '*.py' -print0) |
70 |
+ fi |
71 |
+ done |
72 |
+ |
73 |
+ if [[ ${missing[@]} ]]; then |
74 |
+ eqawarn |
75 |
+ eqawarn "This package installs one or more Python modules that are not byte-compiled." |
76 |
+ eqawarn "The following files are missing:" |
77 |
+ eqawarn |
78 |
+ eqatag -v python-pyc.missing "${missing[@]#${D}}" |
79 |
+ fi |
80 |
+ |
81 |
+ if [[ ${outdated[@]} ]]; then |
82 |
+ eqawarn |
83 |
+ eqawarn "This package installs one or more compiled Python modules that have older" |
84 |
+ eqawarn "timestamps than the corresponding source files:" |
85 |
+ eqawarn |
86 |
+ eqatag -v python-pyc.outdated "${outdated[@]#${D}}" |
87 |
+ fi |
88 |
+ |
89 |
+ if [[ ${missing[@]} || ${outdated[@]} ]]; then |
90 |
+ eqawarn |
91 |
+ eqawarn "Please either fix the upstream build system to byte-compile Python modules" |
92 |
+ eqawarn "correctly, or call python_optimize after installing them. For more" |
93 |
+ eqawarn "information, see:" |
94 |
+ eqawarn "https://wiki.gentoo.org/wiki/Project:Python/Byte_compiling" |
95 |
+ eqawarn |
96 |
+ fi |
97 |
+} |
98 |
+ |
99 |
+python_pyc_check |
100 |
+: # guarantee successful exit |
101 |
+ |
102 |
+# vim:ft=ebuild |
103 |
-- |
104 |
2.23.0 |