[Zope3-checkins] SVN: Zope3/trunk/src/zope/dependencytool/finddeps.py fixed zcml depfind

Bernd Dorn bernd.dorn at lovelysystems.com
Mon Dec 4 09:45:25 EST 2006


Log message for revision 71392:
  fixed zcml depfind

Changed:
  U   Zope3/trunk/src/zope/dependencytool/finddeps.py

-=-
Modified: Zope3/trunk/src/zope/dependencytool/finddeps.py
===================================================================
--- Zope3/trunk/src/zope/dependencytool/finddeps.py	2006-12-03 22:56:10 UTC (rev 71391)
+++ Zope3/trunk/src/zope/dependencytool/finddeps.py	2006-12-04 14:45:23 UTC (rev 71392)
@@ -112,8 +112,19 @@
     finder.find_imports(open(path, 'rU'), path, package)
     return finder.get_imports()
 
+def resolveRelative(path, package):
+    pat = re.compile('\.+')
+    match = pat.match(path)
+    if match is None:
+        return path
+    dots = match.end()
+    path = path[dots:]
+    end = 0-dots+1
+    if end < 0:
+        package = '.'.join(package.split('.')[:end])
+    return package + '.' + path
+    
 
-# TODO: Issue: 459, the option -z isn't working
 def getDependenciesOfZCMLFile(path, packages):
     """Get dependencies from ZCML file."""
     s = makeDottedName(path)
@@ -125,11 +136,8 @@
         match = dottedName.findall(line)
         if match:
             match[0] = match[0][1:-1]
-            match.append('.'.join(match[0].split('.')[:-1]))
-
             for name in match:
-                if name.startswith('.'):
-                    name = localPackage + name
+                name = resolveRelative(name, localPackage)
                 name = importfinder.module_for_importable(name)
                 if packages:
                     name = importfinder.package_for_module(name)
@@ -155,6 +163,8 @@
             __import__(dep.name)
         except ImportError:
             continue
+        except TypeError:
+            continue
         module = sys.modules[dep.name]
         # built-ins (like sys) do not have a file associated
         if not hasattr(module, '__file__'):



More information about the Zope3-Checkins mailing list