Blame SOURCES/macros.pybytecompile

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