[Checkins] SVN: z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/ move some of the more generic functionality into z3c.autoinclude.utils for better sharing between dependency/plugin inclusion

Ethan Jucovy ejucovy at openplans.org
Mon Mar 24 21:14:18 EDT 2008


Log message for revision 84913:
  move some of the more generic functionality into z3c.autoinclude.utils for better sharing between dependency/plugin inclusion

Changed:
  U   z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/include.py
  A   z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/utils.py
  U   z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/zcml.py

-=-
Modified: z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/include.py
===================================================================
--- z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/include.py	2008-03-24 22:24:29 UTC (rev 84912)
+++ z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/include.py	2008-03-25 01:14:17 UTC (rev 84913)
@@ -4,39 +4,11 @@
 from pkg_resources import get_provider
 from pkg_resources import get_distribution
 import logging
+from z3c.autoinclude.utils import DistributionManager
 
 log = logging.getLogger("z3c.autoinclude")
 
-class IncludeFinder(object):
-    def __init__(self, dist):
-        self.context = dist
-
-    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 []
-        
-    def dottedNames(self):
-        """Return dotted names of all relevant packages in a distribution.
-
-        Relevant packages are those packages that are directly under the
-        namespace packages in the distribution, but not the namespace packages
-        themselves. If no namespace packages exist, return those packages that
-        are directly in the distribution.
-        """
-        dist_path = self.context.location
-        ns_dottednames = self.namespaceDottedNames()
-        if not ns_dottednames:
-            return subpackageDottedNames(dist_path)
-        result = []
-        for ns_dottedname in ns_dottednames:
-            path = os.path.join(dist_path, *ns_dottedname.split('.'))
-            result.extend(subpackageDottedNames(path, ns_dottedname))
-        return result
-
+class IncludeFinder(DistributionManager):
     def includableInfo(self, include_candidates):
         """Return the packages in the dependencies which are includable.
 
@@ -58,30 +30,6 @@
                         result.setdefault(candidate, []).append(dotted_name)
         return result
 
-    
-def subpackageDottedNames(package_path, ns_dottedname=None):
-    # we do not look for subpackages in zipped eggs
-    if not os.path.isdir(package_path):
-        return []
-
-    result = []
-    for subpackage_name in os.listdir(package_path):
-        full_path = os.path.join(package_path, subpackage_name)
-        if isPythonPackage(full_path):
-            if ns_dottedname:
-                result.append('%s.%s' % (ns_dottedname, subpackage_name))
-            else:
-                result.append(subpackage_name)
-    return result
-
-def isPythonPackage(path):
-    if not os.path.isdir(path):
-        return False
-    for init_variant in ['__init__.py', '__init__.pyc', '__init__.pyo']:
-        if os.path.isfile(os.path.join(path, init_variant)):
-            return True
-    return False
-
 def package_includes(project_name, zcml_filenames=None):
     """
     Convenience function for finding zcml to load from requirements for
@@ -93,9 +41,3 @@
     dist = get_distribution(project_name)
     include_finder = IncludeFinder(dist)
     return include_finder.includableInfo(zcml_filenames)
-
-def debug_includes(dist, include_type, dotted_names):
-    if not dotted_names:
-        return
-    log.debug('%s - autoinclude %s: %r', dist.project_name,
-              include_type, list(dotted_names))

Added: z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/utils.py
===================================================================
--- z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/utils.py	                        (rev 0)
+++ z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/utils.py	2008-03-25 01:14:17 UTC (rev 84913)
@@ -0,0 +1,72 @@
+import logging
+import os
+from pkg_resources import find_distributions
+import sys
+
+log = logging.getLogger("z3c.autoinclude")
+
+class DistributionManager(object):
+    def __init__(self, dist):
+        self.context = dist
+
+    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 []
+        
+    def dottedNames(self):
+        """Return dotted names of all relevant packages in a distribution.
+
+        Relevant packages are those packages that are directly under the
+        namespace packages in the distribution, but not the namespace packages
+        themselves. If no namespace packages exist, return those packages that
+        are directly in the distribution.
+        """
+        dist_path = self.context.location
+        ns_dottednames = self.namespaceDottedNames()
+        if not ns_dottednames:
+            return subpackageDottedNames(dist_path)
+        result = []
+        for ns_dottedname in ns_dottednames:
+            path = os.path.join(dist_path, *ns_dottedname.split('.'))
+            result.extend(subpackageDottedNames(path, ns_dottedname))
+        return result
+    
+def subpackageDottedNames(package_path, ns_dottedname=None):
+    # we do not look for subpackages in zipped eggs
+    if not os.path.isdir(package_path):
+        return []
+
+    result = []
+    for subpackage_name in os.listdir(package_path):
+        full_path = os.path.join(package_path, subpackage_name)
+        if isPythonPackage(full_path):
+            if ns_dottedname:
+                result.append('%s.%s' % (ns_dottedname, subpackage_name))
+            else:
+                result.append(subpackage_name)
+    return result
+
+def isPythonPackage(path):
+    if not os.path.isdir(path):
+        return False
+    for init_variant in ['__init__.py', '__init__.pyc', '__init__.pyo']:
+        if os.path.isfile(os.path.join(path, init_variant)):
+            return True
+    return False
+
+def distributionForPackage(package):
+    package_filename = package.__file__
+    for path in sys.path:
+        if package_filename.startswith(path):
+            break
+    return list(find_distributions(path, True))[0]
+
+def debug_includes(dist, include_type, dotted_names):
+    if not dotted_names:
+        return
+    log.debug('%s - autoinclude %s: %r', dist.project_name,
+              include_type, list(dotted_names))

Modified: z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/zcml.py
===================================================================
--- z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/zcml.py	2008-03-24 22:24:29 UTC (rev 84912)
+++ z3c.autoinclude/branches/adding-salt/src/z3c/autoinclude/zcml.py	2008-03-25 01:14:17 UTC (rev 84913)
@@ -1,13 +1,11 @@
-import sys
-
-from pkg_resources import find_distributions
 from zope.interface import Interface
 from zope.configuration.xmlconfig import include, includeOverrides
 from zope.configuration.fields import GlobalObject
 from zope.dottedname.resolve import resolve
 
 from z3c.autoinclude.include import IncludeFinder
-from z3c.autoinclude.include import debug_includes
+from z3c.autoinclude.utils import debug_includes
+from z3c.autoinclude.utils import distributionForPackage
 from z3c.autoinclude.plugin import plugins_to_include
 
 class IAutoIncludeDirective(Interface):
@@ -43,13 +41,6 @@
     includeZCMLGroup(_context, dist, info, 'meta.zcml')
     includeZCMLGroup(_context, dist, info, 'configure.zcml')
     
-def distributionForPackage(package):
-    package_filename = package.__file__
-    for path in sys.path:
-        if package_filename.startswith(path):
-            break
-    return list(find_distributions(path, True))[0]
-
 class IIncludePluginsDirective(Interface):
     """Auto-include any ZCML in the dependencies of this package."""
     



More information about the Checkins mailing list