[Checkins] SVN: z3c.autoinclude/trunk/ Catch import errors when determining includable packages (warnings are logged). The rationale is, that if a module can't be imported, then it's not includable.

Malthe Borch cvs-admin at zope.org
Fri Oct 19 09:21:41 UTC 2012


Log message for revision 128069:
  Catch import errors when determining includable packages (warnings are logged). The rationale is, that if a module can't be imported, then it's not includable.

Changed:
  U   z3c.autoinclude/trunk/CHANGES.txt
  U   z3c.autoinclude/trunk/src/z3c/autoinclude/dependency.py

-=-
Modified: z3c.autoinclude/trunk/CHANGES.txt
===================================================================
--- z3c.autoinclude/trunk/CHANGES.txt	2012-10-18 19:29:36 UTC (rev 128068)
+++ z3c.autoinclude/trunk/CHANGES.txt	2012-10-19 09:21:37 UTC (rev 128069)
@@ -4,6 +4,13 @@
 0.3.5 (unreleased)
 ------------------
 
+* If a module cannot be resolved, but raises ``ImportError``, log a
+  warn and continue. This fixes an issue where the determining the
+  includable packages would fail due to a problem with the importation
+  of one or potentially more modules. An example is the ``gobject``
+  module which provides a Python binding to ``GObject``. In a recent
+  API deprecation, one is no longer allowed to both import ``gi`` and
+  ``gobject``.
 
 0.3.4 (2011-03-11)
 ------------------

Modified: z3c.autoinclude/trunk/src/z3c/autoinclude/dependency.py
===================================================================
--- z3c.autoinclude/trunk/src/z3c/autoinclude/dependency.py	2012-10-18 19:29:36 UTC (rev 128068)
+++ z3c.autoinclude/trunk/src/z3c/autoinclude/dependency.py	2012-10-19 09:21:37 UTC (rev 128069)
@@ -1,4 +1,5 @@
 import os
+import logging
 from zope.dottedname.resolve import resolve
 from pkg_resources import resource_exists
 from pkg_resources import get_provider
@@ -21,7 +22,11 @@
         for req in self.context.requires():
             dist_manager = DistributionManager(get_provider(req))
             for dotted_name in dist_manager.dottedNames():
-                module = resolve(dotted_name)
+                try:
+                    module = resolve(dotted_name)
+                except ImportError, exc:
+                    logging.warn(exc)
+                    continue
                 for candidate in zcml_to_look_for:
                     candidate_path = os.path.join(
                         os.path.dirname(module.__file__), candidate)



More information about the checkins mailing list