Check for third party Python modules during configure.
[bbaumbach/samba-autobuild/.git] / third_party / wscript
index 8e7581f1e6c5ce3488b3c88ff9652691e0c11234..4f6347795eb1b47319f668782d7faf5ff595191f 100644 (file)
@@ -1,15 +1,52 @@
 #!/usr/bin/env python
 
+import Utils
 import os
+import sys
 
 # work out what python external libraries we need to install
-external_libs = {
+external_pkgs = {
     "dns.resolver": "dnspython/dns",
     "iso8601": "pyiso8601/iso8601",
     }
 
 
+def find_third_party_module(conf, module, package):
+    conf.COMPOUND_START("Checking for third party Python module %s" % module)
+    try:
+        __import__(module)
+    except ImportError:
+        pass
+    else:
+        # Installed on the system
+        conf.COMPOUND_END("system")
+
+    old_path = sys.path
+    try:
+        sys.path.append(os.path.join(conf.curdir, os.path.dirname(package)))
+        try:
+            __import__(module)
+        except ImportError:
+            if (os.path.isdir(os.path.join(conf.srcdir, ".git")) and
+                os.path.isfile(os.path.join(conf.srcdir, ".gitmodule"))):
+                raise Utils.WafError("""\
+Unable to find Python module '%s'. Please install the system package or check \
+out the relevant submodule by running 'git submodule init; git submodule update'.
+""" % module)
+            else:
+                raise Utils.WafError("""\
+Unable to find Python module '%s'. Please install the system package or place a copy in
+%s.
+""" % (module, package))
+        else:
+            conf.COMPOUND_END("bundled")
+    finally:
+        sys.path = old_path
+
+
 def configure(conf):
+    for module, package in external_pkgs.items():
+        find_third_party_module(conf, module, package)
     conf.RECURSE('popt')
     conf.RECURSE('zlib')
 
@@ -17,7 +54,7 @@ def configure(conf):
 def build(bld):
     list = []
 
-    for module, package in external_libs.items():
+    for module, package in external_pkgs.items():
         try:
             __import__(module)
         except ImportError: