* [gentoo-dev] [PATCH python-utils-r1] Add python_optimize() to compile Python modules by hand.
@ 2012-11-25 9:33 Michał Górny
0 siblings, 0 replies; only message in thread
From: Michał Górny @ 2012-11-25 9:33 UTC (permalink / raw
To: gentoo-dev; +Cc: python, Michał Górny
---
gx86/eclass/python-utils-r1.eclass | 63 ++++++++++++++++++++++++++++++--------
1 file changed, 50 insertions(+), 13 deletions(-)
diff --git a/gx86/eclass/python-utils-r1.eclass b/gx86/eclass/python-utils-r1.eclass
index ad56919..29101b2 100644
--- a/gx86/eclass/python-utils-r1.eclass
+++ b/gx86/eclass/python-utils-r1.eclass
@@ -285,6 +285,55 @@ _python_ln_rel() {
ln -fs "${rel_path}" "${to}"
}
+# @FUNCTION: python_optimize
+# @USAGE: [<directory>...]
+# @DESCRIPTION:
+# Compile and optimize Python modules in specified directories (absolute
+# paths). If no directories are provided, the paths in ${PYTHONPATH}
+# are used (prepended with ${D}).
+python_optimize() {
+ debug-print-function ${FUNCNAME} "${@}"
+
+ [[ ${EPYTHON} ]] || die 'No Python implementation set (EPYTHON is null).'
+
+ local PYTHON=${PYTHON}
+ [[ ${PYTHON} ]] || python_export PYTHON
+
+ # Note: python2.6 can't handle passing files to compileall...
+
+ # default to sys.path
+ if [[ ${#} -eq 0 ]]; then
+ local f
+ while IFS= read -r -d '' f; do
+ # 1) accept only absolute paths
+ # (i.e. skip '', '.' or anything like that)
+ # 2) skip paths which do not exist
+ # (python2.6 complains about them verbosely)
+
+ if [[ ${f} == /* && -d ${D}${f} ]]; then
+ set -- "${D}${f}" "${@}"
+ fi
+ done < <("${PYTHON}" -c 'import sys; print("\0".join(sys.path))')
+ fi
+
+ local d
+ for d; do
+ # make sure to get a nice path without //
+ local instpath=${d#${D}}
+ instpath=/${instpath##/}
+
+ case "${EPYTHON}" in
+ python*)
+ "${PYTHON}" -m compileall -q -f -d "${instpath}" "${d}"
+ "${PYTHON}" -OO -m compileall -q -f -d "${instpath}" "${d}"
+ ;;
+ *)
+ "${PYTHON}" -m compileall -q -f -d "${instpath}" "${@}"
+ ;;
+ esac
+ done
+}
+
# @ECLASS-VARIABLE: python_scriptroot
# @DEFAULT_UNSET
# @DESCRIPTION:
@@ -430,19 +479,7 @@ python_domodule() {
insinto "${d}"
doins -r "${@}"
- local PYTHON=${PYTHON}
- [[ ${PYTHON} ]] || python_export PYTHON
-
- # erm, python2.6 can't handle passing files to compileall...
- case "${EPYTHON}" in
- python*)
- "${PYTHON}" -m compileall -q "${D}/${d}"
- "${PYTHON}" -OO -m compileall -q -f "${D}/${d}"
- ;;
- *)
- "${PYTHON}" -m compileall -q "${D}/${d}"
- ;;
- esac
+ python_optimize "${D}/${d}"
}
_PYTHON_UTILS_R1=1
--
1.8.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2012-11-25 9:32 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-11-25 9:33 [gentoo-dev] [PATCH python-utils-r1] Add python_optimize() to compile Python modules by hand Michał Górny
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox