[Checkins] SVN: z3c.autoinclude/trunk/src/z3c/autoinclude/utils.py slight refactoring of common functionality in utils

Ethan Jucovy ejucovy at openplans.org
Mon Apr 21 11:56:26 EDT 2008


Log message for revision 85534:
  slight refactoring of common functionality in utils

Changed:
  U   z3c.autoinclude/trunk/src/z3c/autoinclude/utils.py

-=-
Modified: z3c.autoinclude/trunk/src/z3c/autoinclude/utils.py
===================================================================
--- z3c.autoinclude/trunk/src/z3c/autoinclude/utils.py	2008-04-21 15:34:44 UTC (rev 85533)
+++ z3c.autoinclude/trunk/src/z3c/autoinclude/utils.py	2008-04-21 15:56:24 UTC (rev 85534)
@@ -14,11 +14,8 @@
     def namespaceDottedNames(self):
         """Return dotted names of all namespace packages in distribution.
         """
-        try:
-            return list(self.context.get_metadata_lines('namespace_packages.txt'))
-        except IOError:
-            return []
-        
+        return namespaceDottedNames(self.context)
+
     def dottedNames(self):
         """Return dotted names of all relevant packages in a distribution.
 
@@ -39,7 +36,7 @@
     
 def subpackageDottedNames(package_path, ns_dottedname=None):
     # we do not look for subpackages in zipped eggs
-    if not os.path.isdir(package_path):
+    if not isUnzippedEgg(package_path):
         return []
 
     result = []
@@ -66,13 +63,10 @@
     for path in sys.path:
         dists = find_distributions(path, True)
         for dist in dists:
-            if not os.path.isdir(dist.location):
+            if not isUnzippedEgg(dist.location):
                 continue
             packages = find_packages(dist.location)
-            try:
-                ns_packages = dist.get_metadata_lines('namespace_packages.txt')
-            except IOError:
-                ns_packages = []
+            ns_packages = namespaceDottedNames(dist)
             if package_dottedname in ns_packages:
                 continue
             if package_dottedname not in packages:
@@ -85,6 +79,25 @@
 def distributionForDottedName(dotted_name):
     return distributionForPackage(resolve(dotted_name))
 
+def namespaceDottedNames(dist):
+    """
+    Return a list of dotted names of all namespace packages in a distribution.
+    """
+    try:
+        ns_dottednames = list(dist.get_metadata_lines('namespace_packages.txt'))
+    except IOError:
+        ns_dottednames = []
+    return ns_dottednames
+
+def isUnzippedEgg(path):
+    """
+    Check whether a filesystem path points to an unzipped egg; z3c.autoinclude
+    does not support zipped eggs or python libraries that are not packaged as
+    eggs. This function can be called on e.g. entries in sys.path or the
+    location of a distribution object.
+    """
+    return os.path.isdir(path)
+
 def debug_includes(dist, include_type, dotted_names):
     if not dotted_names:
         return



More information about the Checkins mailing list