Let we have a package that looks this way:
mext/
package directory__init__.py
package "constructor" modulem1.py
package member module #1m2.py
package member module #2m3.py
package member module #3m4.py
package member module #4
We want to have it in binary (*.so
) for some obscure reasons.
First off we have to write that setup.py
.
It doesn't matter much what else it may do, but it must have these imports:
from distutils.core import setup # because it does everithing
from distutils.command import bdist_rpm # because we want an RPM output
from distutils.extension import Extension # because we build it as an "extension"
from Cython.Distutils import build_ext # because it must be "real binary" thing
In the args of setup()
call we specify
'cmdclass': {'build_ext': build_ext}, # to make cython to join the game
Run the create-rpm.sh
to get dist/mext-0.0-1.x86_64.rpm
file.
If you take a look (rpm -qlp $RPM
) at the fresh build, then you'll see all those
*.py
, *.pyc
, and *.pyo
files you want to get rid of.
so,
Run the repack-rpm.sh
.
It will
- create sorta
.spec
file from the original RPM - unpack the content of that RPM
- remove all the
*.py*
there - add an empty
__init__.py
file for each and every__init__.so
one (to keep it package) - build it back using that
.spec
file from the step 1
Now you may copy the RPM to the target system and install using sudo rpm -ivh --force $RPM
.
Why --force
? Because its intrinsic cpio
wanna create directories like /usr/local
...
It looks harmless, anyway.