f245b7
# Note that the path could itself be a python file, or a directory
f245b7
f245b7
# Python's compile_all module only works on directories, and requires a max
f245b7
# recursion depth
f245b7
f245b7
# Usage:
f245b7
#    %py_byte_compile <interpereter> <path>
f245b7
# Example:
f245b7
#    %py_byte_compile %{__python3} %{buildroot}%{_datadir}/spam/plugins/
f245b7
f245b7
# This will terminate build on SyntaxErrors, if you want to avoid that,
f245b7
# use it in a subshell like this:
f245b7
#    (%{py_byte_compile <interpereter> <path>}) || :
f245b7
f245b7
%py_byte_compile()\
f245b7
python_binary="%1"\
f245b7
buildroot_path="%2"\
f245b7
bytecode_compilation_path=".${buildroot_path/#$RPM_BUILD_ROOT}"\
f245b7
failure=0\
f245b7
pushd $RPM_BUILD_ROOT\
f245b7
find $bytecode_compilation_path -type f -a -name "*.py" -print0 | xargs -0 $python_binary -O -m py_compile || failure=1\
f245b7
find $bytecode_compilation_path -type f -a -name "*.py" -print0 | xargs -0 $python_binary -m py_compile || failure=1\
f245b7
popd\
f245b7
test $failure -eq 0