Python Extension Designer / Builder.

Skip Montanaro skip at pobox.com
Sat Jan 26 16:54:25 EST 2002


    Dave> Paul Rubin <phr-n2002a at nightsong.com> wrote:
    >> 
    >> Gustavo  <rangerelf at axtel.net> writes:
    >>> I'm thinking *very* seriously about making a python module which
    >>> will build the skeleton to a python extension module (with types and
    >>> all).
    >> 
    >> Something wrong with SWIG?

    Dave> SWIG is great.

    Dave> But, wouldn't it be nice to be able to customize the generated
    Dave> code by adding/modifying Python code.  Maybe Gustavo wants more
    Dave> control over the generated code and wants that control in Python.

Have a look at bgen in the Tools/bgen directory of the Python distribution.
Jack Jansen uses it to wrap Mac classes, though it's not supposed to be
Mac-specific.  It is essentially without documentation, which has always
been a stumbling block for me.  Every time I've looked at it, I've concluded
it would take me far longer to get that first bgen-based wrapper module
written than to just wrap the dang thing by hand.

That said, if you grep for "bgen" in the Mac directory you will find lots of
examples.

    Dave> Another place to look for ideas -- The pygtk distribution contains
    Dave> a sub-directory 'generate' that contains python code which
    Dave> translates definition files into C code.  The definition (.defs)
    Dave> files contain S-expressions, not XML, but maybe this is the idea
    Dave> you (Gustavo) are looking for.  You can find pygtk at:
    Dave> http://www.daa.com.au/~james/pygtk/.

This is essentially a SWIG-like thing, though tailored somewhat (I think) to
Gtk.  It works pretty well, but you have to be prepared to expend a fair
amount of effort to get it to understand how to wrap your datatype(s).  Int,
float, etc are obviously trivial (you can probably reuse the code for gint,
gfloat, etc).  It's your complex types that will require some effort.  It's
a major win with Gtk because the one type responsible for most of the
wrapper heartache is GtkWidget.  Once that's done you get its subclasses for
free.  That gets you a long way toward the finish line.

-- 
Skip Montanaro (skip at pobox.com - http://www.mojam.com/)




More information about the Python-list mailing list