[PATCHES] Improve third party Python module checks, allow for submodules

Jelmer Vernooij jelmer at samba.org
Sat Mar 28 10:48:55 MDT 2015


Currently users with missing (system and bundled) third_party modules
will just get an ImportError when they tried to run Samba.

This patchset improves the checks for third party Python modules, by
letting the user know where modules were found and if they weren't,
what they can do to install the module.

This also updates autobuild to use 'git clone --recursive'. This
change doesn't actually add any submodules, but allows us to add
submodules in the future if we wanted to.

Cheers,

Jelmer
-------------- next part --------------
From db433ef183a68f666c1f101bb3c3bb7940def25d Mon Sep 17 00:00:00 2001
From: Jelmer Vernooij <jelmer at samba.org>
Date: Sat, 28 Mar 2015 16:15:03 +0000
Subject: [PATCH 1/3] Pass --recursive to 'git clone' in autobuild.

This makes it possible to use submodules in Samba.

Change-Id: Iccb1876b1daf82864b18486f2dca9036d7d3c75c
Signed-Off-By: Jelmer Vernooij <jelmer at samba.org>
---
 script/autobuild.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/script/autobuild.py b/script/autobuild.py
index 3175ff0..6e1e3e0 100755
--- a/script/autobuild.py
+++ b/script/autobuild.py
@@ -197,7 +197,7 @@ class builder(object):
         cleanup_list.append(self.prefix)
         os.makedirs(self.sdir)
         run_cmd("rm -rf %s" % self.sdir)
-        run_cmd("git clone --shared %s %s" % (test_master, self.sdir), dir=test_master, show=True)
+        run_cmd("git clone --recursive --shared %s %s" % (test_master, self.sdir), dir=test_master, show=True)
         self.start_next()
 
     def start_next(self):
@@ -575,7 +575,7 @@ while True:
     try:
         run_cmd("rm -rf %s" % test_master)
         cleanup_list.append(test_master)
-        run_cmd("git clone --shared %s %s" % (gitroot, test_master), show=True, dir=gitroot)
+        run_cmd("git clone --recursive --shared %s %s" % (gitroot, test_master), show=True, dir=gitroot)
     except Exception:
         cleanup()
         raise
-- 
2.1.4


From 538aaf10c39a9036ea1f3be2887f13fe6be63b95 Mon Sep 17 00:00:00 2001
From: Jelmer Vernooij <jelmer at samba.org>
Date: Sat, 28 Mar 2015 15:43:29 +0000
Subject: [PATCH 2/3] Move configure part of third party to
 third_party/wscript.

Change-Id: I34875a8bde99df2e0a2659677e88640bb0ec1816
Signed-off-by: Jelmer Vernooij <jelmer at samba.org>
---
 third_party/wscript       | 36 ++++++++++++++++++++++++++++++++++++
 third_party/wscript_build | 29 -----------------------------
 wscript                   |  3 +--
 3 files changed, 37 insertions(+), 31 deletions(-)
 create mode 100644 third_party/wscript
 delete mode 100644 third_party/wscript_build

diff --git a/third_party/wscript b/third_party/wscript
new file mode 100644
index 0000000..8e7581f
--- /dev/null
+++ b/third_party/wscript
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+
+import os
+
+# work out what python external libraries we need to install
+external_libs = {
+    "dns.resolver": "dnspython/dns",
+    "iso8601": "pyiso8601/iso8601",
+    }
+
+
+def configure(conf):
+    conf.RECURSE('popt')
+    conf.RECURSE('zlib')
+
+
+def build(bld):
+    list = []
+
+    for module, package in external_libs.items():
+        try:
+            __import__(module)
+        except ImportError:
+            list.append(package)
+
+    for e in list:
+        bld.INSTALL_WILDCARD('${PYTHONARCHDIR}/samba/third_party', e + '/**/*', flat=False,
+                             exclude='*.pyc', trim_path=os.path.dirname(e))
+
+    bld.SAMBA_GENERATOR('third_party_init_py',
+                        rule='touch ${TGT}',
+                        target='empty_file')
+
+    bld.INSTALL_FILES('${PYTHONARCHDIR}/samba/third_party', 'empty_file', destname='__init__.py')
+    bld.RECURSE('zlib')
+    bld.RECURSE('popt')
diff --git a/third_party/wscript_build b/third_party/wscript_build
deleted file mode 100644
index 9a5fabc..0000000
--- a/third_party/wscript_build
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/usr/bin/env python
-
-import os
-
-# work out what python external libraries we need to install
-external_libs = {
-    "dns.resolver": "dnspython/dns",
-    "iso8601": "pyiso8601",
-    }
-
-list = []
-
-for module, package in external_libs.items():
-    try:
-        __import__(module)
-    except ImportError:
-        list.append(package)
-
-for e in list:
-    bld.INSTALL_WILDCARD('${PYTHONARCHDIR}/samba/third_party', e + '/**/*', flat=False,
-                         exclude='*.pyc', trim_path=os.path.dirname(e))
-
-bld.SAMBA_GENERATOR('third_party_init_py',
-                    rule='touch ${TGT}',
-                    target='empty_file')
-
-bld.INSTALL_FILES('${PYTHONARCHDIR}/samba/third_party', 'empty_file', destname='__init__.py')
-bld.RECURSE('zlib')
-bld.RECURSE('popt')
diff --git a/wscript b/wscript
index 146556b..8cf22f8 100644
--- a/wscript
+++ b/wscript
@@ -114,8 +114,7 @@ def configure(conf):
     conf.RECURSE('dynconfig')
 
     if conf.CHECK_FOR_THIRD_PARTY():
-        conf.RECURSE('third_party/zlib')
-        conf.RECURSE('third_party/popt')
+        conf.RECURSE('third_party')
     else:
         if not conf.CHECK_ZLIB():
             raise Utils.WafError('zlib development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
-- 
2.1.4


From 1a532901d8bd84e7ce6697f543587ad8b73347a5 Mon Sep 17 00:00:00 2001
From: Jelmer Vernooij <jelmer at samba.org>
Date: Sat, 28 Mar 2015 16:11:51 +0000
Subject: [PATCH 3/3] Check for third party Python modules during configure.

Inform the user whether the module was found on the system, or if the
bundled copy is being used. If the module is not found, suggest what
they can do to make it available to Samba.

Change-Id: I89ec57a2acf87768ca3714add59575578d2ee399
Signed-Off-By: Jelmer Vernooij <jelmer at samba.org>
---
 third_party/wscript | 41 +++++++++++++++++++++++++++++++++++++++--
 1 file changed, 39 insertions(+), 2 deletions(-)

diff --git a/third_party/wscript b/third_party/wscript
index 8e7581f..4f63477 100644
--- a/third_party/wscript
+++ b/third_party/wscript
@@ -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:
-- 
2.1.4

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: Digital signature
URL: <http://lists.samba.org/pipermail/samba-technical/attachments/20150328/2a5d213f/attachment.pgp>


More information about the samba-technical mailing list