1 |
--- |
2 |
gx86/eclass/python-utils-r1.eclass | 63 ++++++++++++++++++++++++++++++-------- |
3 |
1 file changed, 50 insertions(+), 13 deletions(-) |
4 |
|
5 |
diff --git a/gx86/eclass/python-utils-r1.eclass b/gx86/eclass/python-utils-r1.eclass |
6 |
index ad56919..29101b2 100644 |
7 |
--- a/gx86/eclass/python-utils-r1.eclass |
8 |
+++ b/gx86/eclass/python-utils-r1.eclass |
9 |
@@ -285,6 +285,55 @@ _python_ln_rel() { |
10 |
ln -fs "${rel_path}" "${to}" |
11 |
} |
12 |
|
13 |
+# @FUNCTION: python_optimize |
14 |
+# @USAGE: [<directory>...] |
15 |
+# @DESCRIPTION: |
16 |
+# Compile and optimize Python modules in specified directories (absolute |
17 |
+# paths). If no directories are provided, the paths in ${PYTHONPATH} |
18 |
+# are used (prepended with ${D}). |
19 |
+python_optimize() { |
20 |
+ debug-print-function ${FUNCNAME} "${@}" |
21 |
+ |
22 |
+ [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).' |
23 |
+ |
24 |
+ local PYTHON=${PYTHON} |
25 |
+ [[ ${PYTHON} ]] || python_export PYTHON |
26 |
+ |
27 |
+ # Note: python2.6 can't handle passing files to compileall... |
28 |
+ |
29 |
+ # default to sys.path |
30 |
+ if [[ ${#} -eq 0 ]]; then |
31 |
+ local f |
32 |
+ while IFS= read -r -d '' f; do |
33 |
+ # 1) accept only absolute paths |
34 |
+ # (i.e. skip '', '.' or anything like that) |
35 |
+ # 2) skip paths which do not exist |
36 |
+ # (python2.6 complains about them verbosely) |
37 |
+ |
38 |
+ if [[ ${f} == /* && -d ${D}${f} ]]; then |
39 |
+ set -- "${D}${f}" "${@}" |
40 |
+ fi |
41 |
+ done < <("${PYTHON}" -c 'import sys; print("\0".join(sys.path))') |
42 |
+ fi |
43 |
+ |
44 |
+ local d |
45 |
+ for d; do |
46 |
+ # make sure to get a nice path without // |
47 |
+ local instpath=${d#${D}} |
48 |
+ instpath=/${instpath##/} |
49 |
+ |
50 |
+ case "${EPYTHON}" in |
51 |
+ python*) |
52 |
+ "${PYTHON}" -m compileall -q -f -d "${instpath}" "${d}" |
53 |
+ "${PYTHON}" -OO -m compileall -q -f -d "${instpath}" "${d}" |
54 |
+ ;; |
55 |
+ *) |
56 |
+ "${PYTHON}" -m compileall -q -f -d "${instpath}" "${@}" |
57 |
+ ;; |
58 |
+ esac |
59 |
+ done |
60 |
+} |
61 |
+ |
62 |
# @ECLASS-VARIABLE: python_scriptroot |
63 |
# @DEFAULT_UNSET |
64 |
# @DESCRIPTION: |
65 |
@@ -430,19 +479,7 @@ python_domodule() { |
66 |
insinto "${d}" |
67 |
doins -r "${@}" |
68 |
|
69 |
- local PYTHON=${PYTHON} |
70 |
- [[ ${PYTHON} ]] || python_export PYTHON |
71 |
- |
72 |
- # erm, python2.6 can't handle passing files to compileall... |
73 |
- case "${EPYTHON}" in |
74 |
- python*) |
75 |
- "${PYTHON}" -m compileall -q "${D}/${d}" |
76 |
- "${PYTHON}" -OO -m compileall -q -f "${D}/${d}" |
77 |
- ;; |
78 |
- *) |
79 |
- "${PYTHON}" -m compileall -q "${D}/${d}" |
80 |
- ;; |
81 |
- esac |
82 |
+ python_optimize "${D}/${d}" |
83 |
} |
84 |
|
85 |
_PYTHON_UTILS_R1=1 |
86 |
-- |
87 |
1.8.0 |