Blame SOURCES/macros.pybytecompile

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