SWIG+Distutils - no harmony?

Thomas Heller thomas.heller at ion-tof.com
Thu Jan 17 08:47:53 CET 2002

"Martin Bless" <m.bless at gmx.de> wrote in message news:3c48fd83.11695897 at news.muenster.de...
> ["Thomas Heller" <thomas.heller at ion-tof.com>]:
> >A distutils bug. Support for SWIG is rather poor.
> >SWIGging a file <pathname>.i creates a file <pathname>.c
> >overwriting any previous file of this name. So better
> >change another name.
> It's working now. Here's what I changed to get things going:
> >----------<>----------<>----------<
> I changed two lines in distutils.command.build_ext.py

These changes look good, but you could even do this without
changing the disutils sources by subclassing build_ext inside your
setup script and override some methods with your fixes:

from distutils.command.build_ext import build_ext

class my_build_ext(build_ext):
    def swig_sources(self, sources):
        #new_sources.append(base + target_ext)      #old
        new_sources.append(base + '_wrap' + target_ext)  #new
        #swig_cmd = [swig, "-python", "-dnone", "-ISWIG"] #old
        swig_cmd = [swig, "-python"]  #new

Then you instruct duistutils to use your "my_build_ext" class
instead of the buildin build_ext class. In the call to the setup
function supply a cmdclass parameter:

      cmdclass = {'build_ext': my_build_ext, },


More information about the Python-list mailing list