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