Blame SOURCES/macros.pybytecompile

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