building a .py files with distutils

Jeff Epler jepler at unpythonic.net
Sat Apr 5 11:15:19 EST 2003


I'm writing a program which uses a generated .py file (it's generated based
on a yapps grammar file).  I know how to generate the .py file either as a 
shell command (python yapps.py gram.g) or as a python expression
(yapps.generate("gram.g"))

I'd like to use distutils to build the program, but I don't see an easy
way to cause a .py file to be built at the right time.  

I tried overriding build_ext and handling the .g -> .py in the subclass.
But when I did that, gram.py/gram.pyc aren't written in INSTALLED_FILES,
so bdist_rpm (at least) fails.  I tried overriding get_outputs in addition
to build_extensions, but that function doesn't even seem to be called.

(I suspect that using ext_modules would also make my built rpm be .i386
instead of .noarch, but this is a comparatively minor concern)

The next thing I tried was subclassing build_py and replacing
find_package_modules and build_modules.  This seems to have worked, at
least for the case where the .g file is inside a package.

Is there a better method I should have used?

Jeff





More information about the Python-list mailing list