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