[Distutils] patch for more SWIG support

Andi Vajda andi at osafoundation.org
Thu Oct 7 00:17:31 CEST 2004


The distutils documentation about using it with SWIG says that support is 
rough around the edges. 
(see http://www.python.org/doc/current/dist/setup-script.html, section 3.3.2)

The attached patch tries to unroughen things a little.

I needed support for two things:
   . specifying more swig options than just '-c++'
   . specifying the path to the swig executable

The attached patch to build_ext.py replaces the --swig-cpp option with:
   . --swig-opts=<space separated options passed to swig>
   . --swig=<path to swig executable>

I just subscribed to this list, pardon my ignorance about the process to 
follow to get this patch accepted and integrated into the sources, what do I 
need to do next ?

Thanks !

Andi..

ps: the attached patch file is relative to the Pythonn 2.3.3 source
     distribution
-------------- next part --------------
--- Python-2.3.3/Lib/distutils/command/build_ext.py	Tue Nov 19 05:12:28 2002
+++ Python-2.3.3-patched/Lib/distutils/command/build_ext.py	Tue Oct  5 14:24:48 2004
@@ -79,11 +79,13 @@
          "forcibly build everything (ignore file timestamps)"),
         ('compiler=', 'c',
          "specify the compiler type"),
-        ('swig-cpp', None,
-         "make SWIG create C++ files (default is C)"),
+        ('swig-opts=', None,
+         "list of SWIG command line options"),
+        ('swig=', None,
+         "path to the SWIG executable"),
         ]
 
-    boolean_options = ['inplace', 'debug', 'force', 'swig-cpp']
+    boolean_options = ['inplace', 'debug', 'force']
 
     help_options = [
         ('help-compiler', None,
@@ -107,8 +109,8 @@
         self.debug = None
         self.force = None
         self.compiler = None
-        self.swig_cpp = None
-
+        self.swig_opts = None
+        self.swig = None
 
     def finalize_options (self):
         from distutils import sysconfig
@@ -205,6 +207,11 @@
         if self.undef:
             self.undef = string.split(self.undef, ',')
 
+        if self.swig_opts is None:
+            self.swig_opts = []
+        else:
+            self.swig_opts = self.swig_opts.split(' ')
+
     # finalize_options ()
 
 
@@ -509,7 +516,7 @@
         # source -- but there should be an option to put SWIG output in
         # the temp dir.
 
-        if self.swig_cpp:
+        if '-c++' in self.swig_opts:
             target_ext = '.cpp'
         else:
             target_ext = '.c'
@@ -526,10 +533,9 @@
         if not swig_sources:
             return new_sources
 
-        swig = self.find_swig()
-        swig_cmd = [swig, "-python"]
-        if self.swig_cpp:
-            swig_cmd.append("-c++")
+        swig = self.swig or self.find_swig()
+        swig_cmd = [swig, '-python']
+        swig_cmd.extend(self.swig_opts)
 
         for source in swig_sources:
             target = swig_targets[source]


More information about the Distutils-SIG mailing list