← Back to team overview

dolfin team mailing list archive

patches for setting swig_binary and swig_path

 

Hello!

Here comes four patches that makes it possible to set the swig binary and the 
path to that binary.

In dolfin:

  parameters["swig_binary"] = "swig2.0"

  # Optional
  parameters["swig_path"] = "/home/jada/local/bin"

It defaults to

  parameters["swig_binary"] = "swig"
  parameters["swig_path"] = ""

All pataches need to be applied for it to work. 

Soon time to switch to SWIG 2.0!

Johan
# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: hake.dev@xxxxxxxxx-20110308052111-z1bwyhatg6n1f2ox
# target_branch: bzr+ssh://bazaar.launchpad.net/~dolfin-\
#   core/dolfin/main/
# testament_sha1: 497494ddaf24667d8037d974bbb95ec555acf9b0
# timestamp: 2011-03-07 21:24:53 -0800
# base_revision_id: meg@xxxxxxxxx-20110306222505-fqw8k87j2lbngzqz
# 
# Begin patch
=== modified file 'site-packages/dolfin/common/globalparameters.py'
--- site-packages/dolfin/common/globalparameters.py	2010-02-01 09:56:17 +0000
+++ site-packages/dolfin/common/globalparameters.py	2011-03-08 05:21:11 +0000
@@ -26,9 +26,15 @@
 # Initialize form compiler parameters
 form_compiler_parameters = Parameters("form_compiler")
 for key, value in form_compiler.default_parameters().iteritems():
+    if key in ["swig_binary", "swig_path"]:
+        continue
     form_compiler_parameters.add(key, value)
 form_compiler_parameters.add("name", form_compiler_name)
 
+# Set default swig path and binary parameters
+parameters.add("swig_binary", "swig")
+parameters.add("swig_path", "")
+
 # Increase log level for form compiler to hide output
 form_compiler_parameters["log_level"] = ufl.INFO + 5
 

=== modified file 'site-packages/dolfin/compilemodules/compilemodules.py'
--- site-packages/dolfin/compilemodules/compilemodules.py	2011-02-11 16:05:14 +0000
+++ site-packages/dolfin/compilemodules/compilemodules.py	2011-03-08 05:21:11 +0000
@@ -1,7 +1,7 @@
 "This module provides functionality to compile PyDOLFIN compatible extension modules."
 
 __author__ = "Johan Hake (hake@xxxxxxxxx)"
-__date__ = "2009-08-15 -- 2011-02-11"
+__date__ = "2009-08-15 -- 2011-03-05"
 __copyright__ = "Copyright (C) 2009 Johan Hake"
 __license__  = "GNU LGPL Version 2.1"
 
@@ -116,13 +116,21 @@
         # Check if dolfin.h is installed in dolfin_include_dir
         if os.path.exists(os.path.join(inc_dir, "dolfin.h")):
             return os.path.abspath(inc_dir)
-    raise OSError, "Could not find 'dolfin.h', make sure it is installed in a directory that 'pkg-config --cflags dolfin' returns."
+    raise OSError, "Could not find 'dolfin.h', make sure it is installed in a"\
+          " directory that 'pkg-config --cflags dolfin' returns."
 
 def configure_instant():
     """Check system requirements
 
     Returns a dict with kwargs that can be passed to instant.build_module.
     """
+
+    # Check and set swig binary
+    if not instant.check_and_set_swig_binary(dolfin.parameters["swig_binary"], \
+                                             dolfin.parameters["swig_path"]):
+        raise OSError, "Could not find swig installation. Pass an existing "\
+              "swig binary or install SWIG version 1.3.35 or higher.\n"
+    
     instant_kwargs = {}
     # Get system configuration
     (instant_kwargs['include_dirs'],
@@ -148,17 +156,21 @@
                 swig_include_dirs.append(inc_dir)
 
     if not dolfin_include_found:
-        raise OSError, """Didn't find dolfin.i in include paths returned from pkg-config.
-Please make sure that your DOLFIN installation corresponds with the one returned by pkg-config"""
+        raise OSError, """
+Didn't find dolfin.i in include paths returned from pkg-config.
+Please make sure that your DOLFIN installation corresponds with the
+one returned by pkg-config"""
 
     if not ufc_include_found:
         raise OSError, """Didn't find ufc.i in include paths returned from pkg-config.
-Please make sure that your UFC installation corresponds with the one returned by pkg-config"""
+Please make sure that your UFC installation corresponds with the one
+returned by pkg-config"""
 
     # Check if UFC is importable and what version of swig was used to
     # create the UFC extension module
     try: import ufc
-    except: raise OSError, "Please install the python extenstion module of UFC on your system.\n"
+    except: raise OSError, "Please install the python extenstion module of UFC "\
+            "on your system.\n"
 
     # Check that the form compiler will use the same swig version
     # that UFC was compiled with

=== modified file 'site-packages/dolfin/compilemodules/jit.py'
--- site-packages/dolfin/compilemodules/jit.py	2010-10-06 22:14:43 +0000
+++ site-packages/dolfin/compilemodules/jit.py	2011-03-08 05:21:11 +0000
@@ -2,7 +2,7 @@
 the chosen form compiler."""
 
 __author__ = "Johan Hake (hake@xxxxxxxxx)"
-__date__ = "2008-12-04 -- 2010-09-11"
+__date__ = "2008-12-04 -- 2011-03-07"
 __copyright__ = "Copyright (C) 2008-2009 Johan Hake"
 __license__  = "GNU LGPL Version 2.1"
 
@@ -69,14 +69,14 @@
     It uses the jit function from the form compiler registered by
     parameters["form_compiler"]["name"].
     """
-
+    
     global _swig_version_ok
-
+    
     # Check that the form compiler will use the same swig version
     # that PyDOLFIN was compiled with
     _swig_version_ok = _swig_version_ok or \
                        check_swig_version(cpp.__swigversion__, same=True)
-
+    
     if not _swig_version_ok:
         raise OSError, """\
 PyDOLFIN was not compiled with the present version of swig.
@@ -105,6 +105,10 @@
     if form_compiler_parameters:
         p.update(form_compiler_parameters)
 
+    # Set the swig binary and path
+    p["swig_binary"] = parameters["swig_binary"]
+    p["swig_path"] = parameters["swig_path"]
+    
     # Get jit function
     try:
         jit_compile = form_compiler.jit

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWQNsBC8AA8zfgEVQWOf/91/3
zo6////wYAfbi67r4bs0UF2r6a+no6NAUeEoiFHpPRoZJiYahtGoep6TygAAAwINIhlME9I0A0AA
AAAAAABoQyKehR+qaZMmmTRoAAAAANAAkSCJkGqeTBINPRGjE0GgBoANBoGlQDQaaND1A000yMgA
D1ANGIGEwkiJo0EZNGpk9AmibRTynpNEzFNNAaZGNIEVAZEJ3beeNJqjQkLqrQPL0/A14SHOzijC
wfvgzscH6w6tE7g3aOHThh3Mlp2BC6br6cVZQ4rGJ1cRxRUdNn6yRTBAlQEMe44xrk+cHy/eFuXC
LN5aFyJiG220dX2QatOOuOsbccbXlrG9igm1dE6XhylhZay17WzFadNEE5okFi9TkcdDyGmNvFQ6
KBiyqPZWwYEx5NbKc8BBcUidQZYXDTxIJtttLhjmmJZYPupqdQ4EB6GcLqJwQeMN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un
# target_branch: bzr+ssh://bazaar.launchpad.net/~ffc-core/ffc/main/
# testament_sha1: 7c56484b21276a60e260a34459870aafaae4d3c9
# timestamp: 2011-03-07 21:25:32 -0800
# base_revision_id: logg@xxxxxxxxx-20110223202543-sav36taj2ko8x8lg
# 
# Begin patch
=== modified file 'ffc/jitcompiler.py'
--- ffc/jitcompiler.py	2011-02-21 13:48:40 +0000
+++ ffc/jitcompiler.py	2011-03-08 05:18:56 +0000
@@ -94,15 +94,14 @@
     else:
         preprocessed_form = preprocess(form, common_cell=common_cell)
         _memory_cache[(id(form), repr(form))] = preprocessed_form
-
+        
         # For each 10th time the refcount of the cached form are checked
         # and superflous forms are poped
         if (_memory_check % 10) == 0:
             for key, cached_form in _memory_cache.items():
                 if sys.getrefcount(cached_form) < 6:
                     _memory_cache.pop(key)
-        else:
-            _memory_check += 1
+        _memory_check += 1
 
     # Wrap input
     jit_object = JITObject(form, preprocessed_form, parameters)
@@ -127,10 +126,12 @@
     cppfile = jit_object.signature() + ".cpp"
     module = ufc_utils.build_ufc_module(
         hfile,
+        swig_binary=parameters["swig_binary"], swig_path=parameters["swig_path"], 
         source_directory = os.curdir,
         signature = jit_object.signature(),
         sources = [cppfile] if parameters["split"] else [],
-        cppargs = parameters["cpp_optimize_flags"].split() if parameters["cpp_optimize"] else ["-O0"],
+        cppargs = parameters["cpp_optimize_flags"].split() \
+                  if parameters["cpp_optimize"] else ["-O0"],
         cache_dir = cache_dir)
 
     # Remove code
@@ -161,6 +162,9 @@
     # Compile form
     (compiled_form, module, form_data) = jit_form(form, parameters)
 
+    # Pop cache for element form. Otherwise it might interfere with DOLFIN forms
+    _memory_cache.pop((id(form), repr(form)))
+
     return _extract_element_and_dofmap(module, form_data)
 
 def _check_parameters(form, parameters):

=== modified file 'ffc/parameters.py'
--- ffc/parameters.py	2011-01-18 14:46:41 +0000
+++ ffc/parameters.py	2011-03-08 05:18:56 +0000
@@ -34,7 +34,9 @@
   "log_level":                      INFO,    # log level, displaying only
                                              # messages with level >= log_level
   "log_prefix":                     "",      # log prefix
-  "error_control":                  False    # with error control
+  "error_control":                  False,   # with error control
+  "swig_binary":                    "swig",  # swig binary file for the JIT compiler
+  "swig_path":                      "",      # path to swig binary for the JIT compiler
 }
 
 def default_parameters():

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWU5PMhoAAn9/gFQRUABYb//3
d3XEDr////BQBW5Hj0etm95lSUFbe7CURNNCZNNCnsmFGyo8miG0mRkDJ5NJ6jQJUaqeniam09SM
hNGj1AAZA0ANAAAlQ1U/NST0abVNpqPUNqA0YQNMBAAADEmkEammaTZQNBkPSANGg00AAAkkCDQS
ZqepjQRoGUbSm9UGQABp6mj0TFUc2dSDJH5yb32by263jCXL2wb5fFyXyZ1yAH2gjnGJPDE4d6sB
IwIEGAZAbyQZioMiKPRtoUC2ESklVZ5g/EZ7zMtZUrImSlVLB2piFI7QS8tiu5AWbdja/L14J6fk
1HlNDGmNjKrm/iVzlW4kg87oCei9qP4Odtje8HmSmYiqs16sw0geYQ7pcm/MhtxTyTytg0xGyNA7
GNVevc01W06fk7CprPQgwKc6ubrdbScTEXFIakJgOqgsL5k9EMt4HvVk4w3IOtB3obfdMcY9ZdZQ
OLYJL0zfw45wgdA0sgHGcYHJgM5gO9gIOkI5epMtAeVhIoLAk9dJEdzdxUbozJ1bzZnmyBrrDbIS
TNBiiF4t1owZ2FiDEUgsB4SQnpnq71aNlpOEG8LcS4ndhU0CsedGyNYHB44ycXhadkdRYTYWIyFU
n1FQ80yuGTiIylkONcVjifSzSYzWhkMPKscj5q86mvdW7QoZgLyyKeWlZJwSKB+GH/J+SQmf+Jh0
Sg1VnFilxtLwqcUssJsVrnFeRbECcg+yisiobrIEiJcBde4pUi14FJnhNVadMwNk9FQ4XftlwgxL
NQ4dYi5broxA2EEStLUbtFD0jS9QaywtAgXbxBpJVc1iYJ00r5rGAk2ka8RB0tOp7BbYVkahGiNA
UiTMoID1mAkVzly8+NRRTFXjr7txtWsDioGa8Csx1qNhdddQaIGpV06HKEidlMIukQFVpi7AKZRM
5Es67BcWhuKu0FdFgQYLJjv+AsxoHchrnkVUVV4Tt5eTePIYRbuTdn7YNF7gXKhOmc3T6SpiJ4cO
wiTFXEEvQg0S81GzWzYQgdztxNkmyoPvQL1870HTdiUgSi7RztAmwFApnk9Ds4Fy6cz34Juch44c
Fq9l6Hj9R9nokUuGGrWusd8IlhZZ1QP9J8ynRawixsb9EDLKWq/3nSdE+Itml0lNkJlKoaYgpiB7
5xR2ezzHFBkRUsu/5cDP3DmyfwPF0kEpHLE1Eh0kEfhKYdVfUtxFEbRs0ajIMZChPzq6dpcVc3G6
NX4+ckoXVyYbDI9LU70VBqWZ9Ghbo9bQL9N8wg+RAlQoRCOnAY695g7lmJNkSHKeY5TX+mjaMe7Y
4P1GVDdfaPqCTbN4OFsOIm8wf0A9kHeZGFO0WruPU90IMwn3K0Uz10PHkCszYFiBogKaBa91qCu+
saeKIa6UDdqXmqDFhkdxzFqRnjC/sxjSi3kijh6qBeSGhmXkcdu45m0DcqBGvJHnxXccUHANBnR1
PDkjOBvoAgy812366cgohfPwLwG8ndaB6kU6Cp10AG2NkxV+hwpKKVFV0IpLx0mcrCQ4ZTICiMh8
HEtPwRMIMmkOBy9MfDijMri/APxcbkKtGLh/rWyoWYFmQYiQMTMPKEZYA4pL8FYehYwUHMLVZrrU
2XbrpuUtc6SQuRsAiQNrKr6EF4jVxFIBMnRN23iYu6vSk1FqKxEkRUhZBBIU4YpEzX6EiutWfGxz
UxkG5CFBpGHw0SEQkQVp3qMoMuHbMMaI4vhfZce+sfOswEoULINBDxdapiVEqzMLIyTBXZhLUjNa
A+rM9RKEFSZHIDmBQkWVE8D3I4iQweFAooKhgB3z5etQwKJP+LuSKcKEgnJ5kNA=
# Bazaar merge directive format 2 (Bazaar 0.90)
# revision_id: hake.dev@xxxxxxxxx-20110308014050-d4gvwbbm1134s7nz
# target_branch: bzr+ssh://bazaar.launchpad.net/~ufc-core/ufc/main/
# testament_sha1: 6dac9df05e5649b25b9c4069d18725bd1755229c
# timestamp: 2011-03-07 21:26:07 -0800
# base_revision_id: logg@xxxxxxxxx-20110223202608-1uq0vzgjv57qf94r
# 
# Begin patch
=== modified file 'src/utils/python/ufc_utils/build.py'
--- src/utils/python/ufc_utils/build.py	2010-08-25 09:48:16 +0000
+++ src/utils/python/ufc_utils/build.py	2011-03-08 01:40:50 +0000
@@ -1,5 +1,5 @@
 __author__ = "Johan Hake (hake@xxxxxxxxx)"
-__date__ = "2009-03-06 -- 2010-05-27"
+__date__ = "2009-03-06 -- 2011-03-05"
 __copyright__ = "Copyright (C) 2009 Johan Hake"
 __license__  = "GNU LGPL Version 2.1"
 
@@ -12,7 +12,8 @@
 
 from distutils import sysconfig
 
-def build_ufc_module(h_files, source_directory="", system_headers=None, **kwargs):
+def build_ufc_module(h_files, source_directory="", system_headers=None, \
+                     swig_binary="swig", swig_path="", **kwargs):
     """Build a python extension module from ufc compliant source code.
 
     The compiled module will be imported and returned by the function.
@@ -24,6 +25,10 @@
        The directory where the source files reside.
     @param system_headers:
        Extra headers that will be #included in the generated wrapper file.
+    @param swig_binary:
+       Name of the swig binary instant need to look for
+    @param swig_path:
+       Path to the swig binary
 
     Any additional keyword arguments are passed on to instant.build_module.
     """
@@ -32,7 +37,8 @@
     if isinstance(h_files, str):
         h_files = [h_files]
     assert isinstance(h_files, list) , "Provide a 'list' or a 'str' as 'h_files'."
-    assert all(isinstance(f, str) for f in h_files), "Elements of 'h_files' must be 'str'."
+    assert all(isinstance(f, str) for f in h_files), \
+           "Elements of 'h_files' must be 'str'."
 
     h_files2 = [os.path.join(source_directory, fn) for fn in h_files]
     for f in h_files2:
@@ -42,7 +48,8 @@
     # Check system_headers argument
     system_headers = system_headers or []
     assert isinstance(system_headers, list), "Provide a 'list' as 'system_headers'"
-    assert all(isinstance(header, str) for header in system_headers), "Elements of 'system_headers' must be 'str'."
+    assert all(isinstance(header, str) for header in system_headers), \
+           "Elements of 'system_headers' must be 'str'."
 
     system_headers.append("boost/shared_ptr.hpp")
 
@@ -50,7 +57,7 @@
     declarations = extract_declarations(h_files2)
 
     # Check system requirements
-    (cpp_path, swig_path) = configure_instant()
+    (cpp_path, swig_include_dirs) = configure_instant(swig_binary, swig_path)
 
     # Call instant and return module
     return instant.build_module(wrap_headers            = h_files,
@@ -59,27 +66,29 @@
                                 system_headers          = system_headers,
                                 include_dirs            = cpp_path,
                                 swigargs                = ['-c++', '-I.','-O'],
-                                swig_include_dirs       = swig_path,
+                                swig_include_dirs       = swig_include_dirs,
                                 **kwargs)
 
-def configure_instant():
+def configure_instant(swig_binary="swig", swig_path=""):
     "Check system requirements"
 
     # Get include directory for ufc.h (might be better way to do this?)
     (path, dummy, dummy, dummy) = instant.header_and_libs_from_pkgconfig("ufc-1")
-    if len(path) == 0: path = [(os.sep).join(sysconfig.get_python_inc().split(os.sep)[:-2]) + os.sep + "include"]
+    if len(path) == 0: path = [(os.sep).join(sysconfig.get_python_inc().\
+                                    split(os.sep)[:-2]) + os.sep + "include"]
 
     # Register the paths
-    cpp_path, swig_path = [path[0]], [path[0]]
+    cpp_path, swig_include_dirs = [path[0]], [path[0]]
 
     # Check for swig installation
-    result, output = instant.get_status_output("swig -version")
-    if result == 1:
-        raise OSError, "Could not find swig installation. Please install swig version 1.3.35 or higher.\n"
+    if not instant.check_and_set_swig_binary(swig_binary, swig_path):
+        raise OSError, "Could not find swig installation. Pass an existing "\
+              "swig binary or install SWIG version 1.3.35 or higher.\n"
 
     # Check swig version for shared_ptr
     if not instant.check_swig_version("1.3.35"):
-        raise OSError, "Your current swig version is %s, it needs to be 1.3.35 or higher.\n" % instant.get_swig_version()
+        raise OSError, "Your current swig version is %s, it needs to be "\
+              "1.3.35 or higher.\n" % instant.get_swig_version()
 
     # Check if UFC is importable and what version of swig was used to
     # create the UFC extension module
@@ -124,7 +133,7 @@
     # Add the boost_include_dir
     cpp_path += boost_include_dir
 
-    return cpp_path, swig_path
+    return cpp_path, swig_include_dirs
 
 def extract_declarations(h_files):
     "Extract information for shared_ptr"

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWdgQJlcAApN/gEyQIARS///3
evHIrr////BQBd6dyy2WqXXa62xp2bu62wkkmmIjJMGkyZPVJ+00ptU/CKPUxAep+qZD1PUAZEKe
BNBGRMSNNiaIDQAAABoDEmiaUbU2p5qCniZINDYo09I0A00A9QPUOaZGQyYIaMJgjTRoxA0yZGAA
IJJCm0TTBNKeyk02aSMhp6mT1HqPSABpoN6kiAceHbrzYsWaIbyEI9neZcNerD+bB7QdQn8EPbOO
I0XTdoIi7rhvfKuUpTv3wreTxfGWESScg0MkOXhoPTrfpl1nGqj658UuvIZJetf0Af7NgnlnfmbT
JGnTRGHNoVhmecnZRnmgJBRQEnZohmjT6aMlBbEdW+mVI4hPo3sHKBtek9yJTN+ahJfh7ysFEnQ8
T6vs6xzPE3XC3WKc9sbeKiyu9BKqVC/ppxQKgwSIjffFNXttz8gmOnt5b+bu76G4YAtcMqk24I95
yGixYXjOGAt19Uy/hH501K9Np+Fn2VvrHE/i7NPNV8WJ4kJeB2TnuhSsRJeNPLZzJGNSNHG9e8Xj
wlcLyWruy4fJ/MjkMY7TgK8FqWpK+aHquS2LRm8nLfxuScSohfsBZNuA0IkNKALGxzpGsODnUNgK
aw+hUHWRSx5WBnxGNsHS3fszIDUF+6rKuXeJYPQY9g22MBFKtFFQjAlGzJoq/SkTSilBdp4YJ4WO
y9LsCzsYK1brLMS7cKUmVWqNemQQZBUv9zLUtgnSwQYaZorggC0s2nsdEOlIYhAA2VhpbEAOeGMy
dCXVzDAeGGUshsbQ1lgIaxYTEtTOYFSFtbDMJ6ojlBRoDJHpLJRaSyMDZtSkln/i9RQX8psiK5zK
bLYsnBkoHnbnXDHWLg+NqFCgezjiYaqYISVChMabhXgwGqyygb0A8hZCg2VRGaJFiAuairjytGjB
RWsrqDUMBOCtsYhebs02sGo3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bazaar 0.90)
# revision_id: hake.dev@xxxxxxxxx-20110308013940-n5185b7spwyalkkk
# target_branch: bzr+ssh://bazaar.launchpad.net/~instant-\
#   core/instant/main/
# testament_sha1: d5e1d62d945371672bbf320ad96787334a51c37f
# timestamp: 2011-03-07 21:25:25 -0800
# base_revision_id: kent-and@xxxxxxxxx-20110223224603-d3dbvyesi0xhrm70
# 
# Begin patch
=== modified file 'instant/build.py'
--- instant/build.py	2011-01-27 09:12:06 +0000
+++ instant/build.py	2011-03-08 01:39:40 +0000
@@ -35,7 +35,6 @@
         x = x.split()
     return strip_strings(x)
 
-
 def copy_files(source, dest, files):
     """Copy a list of files from a source directory to a destination directory.
     This may seem a bit complicated, but a lot of this code is error checking."""
@@ -105,7 +104,6 @@
     # Compilation succeeded, write new_compilation_checksum to checksum_file
     write_file(compilation_checksum_filename, new_compilation_checksum)
 
-
 def copy_to_cache(module_path, cache_dir, modulename):
     "Copy module directory to cache."
     # Get lock, check if the module exists, _otherwise_ copy the
@@ -142,7 +140,6 @@
     release_lock(lock)
     return cache_module_path
 
-
 def build_module(modulename=None, source_directory=".",
                  code="", init_code="",
                  additional_definitions="", additional_declarations="",

=== modified file 'instant/codegeneration.py'
--- instant/codegeneration.py	2010-10-30 19:48:08 +0000
+++ instant/codegeneration.py	2011-03-08 01:39:40 +0000
@@ -2,11 +2,10 @@
 
 import re, os
 from output import instant_assert, instant_warning, instant_debug, write_file
-
+from config import get_swig_binary
 
 def mapstrings(format, sequence):
     return "\n".join(format % i for i in sequence)
-    
 
 def reindent(code):
     '''Reindent a multiline string to allow easier to read syntax.
@@ -191,7 +190,6 @@
     write_file(filename, interface_string)
     instant_debug("Done generating interface file.")
 
-
 def write_setup(filename, modulename, csrcs, cppsrcs, local_headers, include_dirs, library_dirs, libraries, swig_include_dirs, swigargs, cppargs, lddargs):
     """Generate a setup.py file. Intended for internal library use."""
     instant_debug("Generating %s." % filename)
@@ -226,7 +224,7 @@
         import os
         from distutils.core import setup, Extension
         name = '%s'
-        swig_cmd =r'swig -python %s %s %s'
+        swig_cmd =r'%s -python %s %s %s'
         os.system(swig_cmd)
         sources = %s
         setup(name = '%s',
@@ -235,8 +233,9 @@
                              include_dirs=%s,
                              library_dirs=%s,
                              libraries=%s %s %s)])  
-        """ % (modulename, swig_include_dirs, swig_args, swigfilename, cppsrcs, 
-               modulename, modulename, include_dirs, library_dirs, libraries, compile_args, link_args))
+        """ % (modulename, get_swig_binary(), swig_include_dirs, swig_args, \
+               swigfilename, cppsrcs, modulename, modulename, include_dirs, \
+               library_dirs, libraries, compile_args, link_args))
     
     write_file(filename, code)
     instant_debug("Done writing setup.py file.")
@@ -253,10 +252,11 @@
     wrap_headers = ["wrap_header1.h", "wrap_header2.h"]
     arrays = [["length1", "array1"], ["dims", "lengths", "array2"]]
     
-    write_interfacefile("%s.i" % modulename, modulename, code, init_code, additional_definitions, additional_declarations, system_headers, local_headers, wrap_headers, arrays)
+    write_interfacefile("%s.i" % modulename, modulename, code, init_code, \
+                        additional_definitions, additional_declarations, \
+                        system_headers, local_headers, wrap_headers, arrays)
     print "".join(open("%s.i" % modulename).readlines())
 
-
 def _test_write_setup():
     modulename = "testmodule"
     csrcs = ["csrc1.c", "csrc2.c"]
@@ -270,7 +270,9 @@
     cppargs = ["-cpparg1", "-cpparg2"]
     lddargs = ["-Lddarg1", "-Lddarg2"]
     
-    write_setup("setup.py", modulename, csrcs, cppsrcs, local_headers, include_dirs, library_dirs, libraries, swig_include_dirs, swigargs, cppargs, lddargs)
+    write_setup("setup.py", modulename, csrcs, cppsrcs, local_headers, \
+                include_dirs, library_dirs, libraries, swig_include_dirs, \
+                swigargs, cppargs, lddargs)
     print "".join(open("setup.py").readlines())
 
 def unique(list):
@@ -336,7 +338,6 @@
 %(code)s 
 
 """
-    
     class_list = find_vtk_classes(code)
     includes = generate_vtk_includes(class_list) 
     typemaps = create_typemaps(class_list)
@@ -479,8 +480,6 @@
 
     f.write(file_template)
 
-
-
 def write_vtk_interface_file(signature, code):     
     filename = signature
     ifile = filename + ".i"
@@ -489,10 +488,6 @@
     iff.write(ifile_code)
 
 
-
-
-
-
 if __name__ == "__main__":
     _test_write_interfacefile()
     print "\n"*3

=== modified file 'instant/config.py'
--- instant/config.py	2011-01-27 09:12:06 +0000
+++ instant/config.py	2011-03-08 01:39:40 +0000
@@ -4,19 +4,48 @@
 from output import get_status_output
 import re
 
-_swig_version = None
+# Global cache variables
+_swig_binary_cache = None
+_swig_version_cache = None
+_pkg_config_installed = None
+_header_and_library_cache = {}
+
+def check_and_set_swig_binary(binary="swig", path=""):
+    """ Check if a particular swig binary is available"""
+    global _swig_binary_cache
+    if not isinstance(binary, str):
+        raise TypeError, "expected a 'str' as first argument"
+    if not isinstance(path, str):
+        raise TypeError, "expected a 'str' as second argument"
+    swig_binary = os.path.join(path, binary)
+    if swig_binary == _swig_binary_cache:
+        return True
+    
+    result, output = get_status_output("%s -version"%swig_binary)
+    if result != 0: 
+        return False
+    
+    # Set cache
+    _swig_binary_cache = swig_binary
+
+    return True
+
+def get_swig_binary():
+    "Return any cached swig binary"
+    return _swig_binary_cache if _swig_binary_cache else "swig"
+
 def get_swig_version(): 
     """ Return the current swig version in a 'str'"""
-    global _swig_version
-    if _swig_version is None:
+    global _swig_version_cache
+    if _swig_version_cache is None:
         # Check for swig installation
-        result, output = get_status_output("swig -version")
+        result, output = get_status_output("%s -version"%get_swig_binary())
         if result != 0: 
             raise OSError("SWIG is not installed on the system.")
         pattern = "SWIG Version (.*)"
         r = re.search(pattern, output)
-        _swig_version = r.groups(0)[0]
-    return _swig_version
+        _swig_version_cache = r.groups(0)[0]
+    return _swig_version_cache
 
 def check_swig_version(version, same=False):
     """ Check the swig version
@@ -55,17 +84,19 @@
     
     return swig_enough
 
-_pkg_config_installed = None
-_hl_cache = {}
 def header_and_libs_from_pkgconfig(*packages, **kwargs):
-    """This function returns list of include files, flags, libraries and library directories obtain from a pkgconfig file.
+    """This function returns list of include files, flags,
+    libraries and library directories obtain from a pkgconfig file.
     
     The usage is: 
-      (includes, flags, libraries, libdirs) = header_and_libs_from_pkgconfig(*list_of_packages)
+      (includes, flags, libraries, libdirs) = \
+             header_and_libs_from_pkgconfig(*list_of_packages)
     or:
-        (includes, flags, libraries, libdirs, linkflags) = header_and_libs_from_pkgconfig(*list_of_packages, returnLinkFlags=True)
+        (includes, flags, libraries, libdirs, linkflags) = \
+             header_and_libs_from_pkgconfig(*list_of_packages, \
+             returnLinkFlags=True)
     """
-    global _pkg_config_installed, _hl_cache
+    global _pkg_config_installed, _header_and_library_cache
     returnLinkFlags = kwargs.get("returnLinkFlags", False)
     if _pkg_config_installed is None:
         result, output = get_status_output("pkg-config --version ")
@@ -85,27 +116,34 @@
     libdirs = []
     linkflags = []
     for pack in packages:
-        if not pack in _hl_cache:
-            result, output = get_status_output("pkg-config --exists %s " % pack, env=env)
+        if not pack in _header_and_library_cache:
+            result, output = get_status_output(\
+                "pkg-config --exists %s " % pack, env=env)
             if result == 0: 
-                tmp = get_status_output("pkg-config --cflags-only-I %s " % pack, env=env)[1].split()
+                tmp = get_status_output(\
+                    "pkg-config --cflags-only-I %s " % pack, env=env)[1].split()
                 _includes = [i[2:] for i in tmp]
 
-                _flags = get_status_output("pkg-config --cflags-only-other %s " % pack, env=env)[1].split()
+                _flags = get_status_output(\
+                    "pkg-config --cflags-only-other %s " % pack, env=env)[1].split()
 
-                tmp = get_status_output("pkg-config --libs-only-l  %s " % pack, env=env)[1].split()
+                tmp = get_status_output(\
+                    "pkg-config --libs-only-l  %s " % pack, env=env)[1].split()
                 _libs = [i[2:] for i in tmp]
 
-                tmp = get_status_output("pkg-config --libs-only-L  %s " % pack, env=env)[1].split()
+                tmp = get_status_output(\
+                    "pkg-config --libs-only-L  %s " % pack, env=env)[1].split()
                 _libdirs = [i[2:] for i in tmp]
 
-                _linkflags = get_status_output("pkg-config --libs-only-other  %s " % pack, env=env)[1].split()
+                _linkflags = get_status_output(\
+                    "pkg-config --libs-only-other  %s " % pack, env=env)[1].split()
 
-                _hl_cache[pack] = (_includes, _flags, _libs, _libdirs, _linkflags)
+                _header_and_library_cache[pack] = (_includes, _flags, _libs, \
+                                                   _libdirs, _linkflags)
             else:
-                _hl_cache[pack] = None
+                _header_and_library_cache[pack] = None
 
-        result = _hl_cache[pack]
+        result = _header_and_library_cache[pack]
         if not result:
             raise OSError("The pkg-config file %s does not exist" % pack)
 

# Begin bundle
IyBCYXphYXIgcmV2aXNpb24gYnVuZGxlIHY0CiMKQlpoOTFBWSZTWTLNFq8ABSj/gFR8RAB69//3
e/UcDr//3/pgCg748rz3PVO2LBWwzA6MgXZa1tp7ZzUMkU9TTRom1NMnomT9JPTUZMQYTAgaDARp
oJKaEwmhpCm2qbVHtJhTR6QAANDTQANNA00IEKAAbUaAAAAAAAAAJEiaI2hTaag1TelPJ6g1H6U/
VA2kD1NAAAAcAwjCaYhgEAyAGEaZMmEYCGgkUE0IGjQ0CGmlN6qftKn5Gpo9KHpNDTQ9NPSjE0sk
gPftaFsdIeeONa4FF2s4tEZyqI02B8iPi5OjUJ3WlFc9LJEVPNTGe11LmN6zWdEQ/EVhJwNMDulL
bHVKvL0uPV5kotaHqaxu3wjvk2BiYL8aLKDZGEKiDg22WVUjbIjSWgQloaSAIpCT9fy+MfpoFuL9
gEZ/GyB6yPxPtze7AU1aq/9rgmgG2wbQrbPmALbY25Fy+uWjGk5RykGnJnVZs+TBpJFYGtEFcYQl
RpEiCqK5oIlqoRo9QIhQ0kXlRQSkS5DOqTdIUI0Zayp2YcT5QOwzB9NbH3zTqw1fY9YUjEoSF0IG
VRmD1dyzUB+I0rleShsCN1GhVOpxUQGsUJJgm9P8I2jkBjKtJ0yaESNZD0sHKjirl1uuqKMrRXY+
QpLszwbGdcZBj5plrOoPpRiYp5/zDDuzljdzRMBqt6WJEkotA5zEqw4X++4H5FPEUVMoMAecYsgP
hCvQ9GrZS8aRAowOUCDN3Uom0z/VBFyuKRFVVP33yL53V8xqP/pBYdJkW8zzGyiIk5DRW1yYdsYJ
m4UKEw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