compile python bytecode at RPM build time
From the world of quick hacks – I needed to rebuild the Puppet RPM from the EPEL folks for a customer, they need it deployed at kickstart time with custom configs (hundreds of servers). Using the EPEL source RPM the “yumhelper.py” file wasn’t getting compiled into .pyc and .pyo objects on a standard RHEL 5 system (which I’ve seen before with MySQL-python RPMs).
The quick hack was to simply run Python’s compileall module on it:
%install
rm -rf %{buildroot}
ruby install.rb --destdir=%{buildroot} --quick --no-rdoc
# Precompile python modules to avoid selinux issues later
python -mcompileall %{buildroot}%{ruby_sitelibdir}/puppet/provider/package
python -O -mcompileall %{buildroot}%{ruby_sitelibdir}/puppet/provider/package
Is it ugly and dirty? Yes. Does it work? Yes. Problem solved, walk away and get other work done.