Gregory S. Couch
University of California
Computer Graphics Laboratory
San Francisco, CA 94143-0446
(415) 476-9292, fax: (415) 502-1755
email: gregc@cgl.ucsf.edu
Wrappy generates a Python extension module from annotated C++ header files. Wrappy's power comes from how it maps between C++ and Python features. Wrappy understands ISO C++ container classes, C++ classes are converted to Python types (or a Python-subclassable extension class [Ful98]), public member data and get/set member functions are mapped to attributes, C++ exceptions are mapped to Python exceptions, overloaded functions are supported, function argument names are used for Python keyword arguments, and more. Annotating C++ header files is necessary to designate output arguments in functions and to choose how C++ classes are wrapped. Some C++ source code modifications are necessary to harmonize C++ and Python object semantics and to work around limitations in wrappy.The impetus behind wrappy was to generate wrapper code for our (growing) C++ molecular graphics library with 500 member functions in 30 classes. We didn't want to wrap all of those functions and classes by hand, both because the likelihood of making errors due to the repetitive nature of the task, and because the initial versions of the wrapper code would have systemic errors in them. Existing wrapper generators didn't suport the C++ features we wanted to use. Wrappy generates code that is similar to hand-crafted wrapper code, but more robust. The C++ header files generate about 30 times their ``weight'' in Python interface code (in our case, from 850 lines of C++ header files to over 25000 lines of Python interface code).