[Checkins] SVN: z3c.autoinclude/trunk/src/z3c/autoinclude/ more attempts to increase clarity
Ethan Jucovy
ejucovy at openplans.org
Sat Jan 17 17:05:14 EST 2009
Log message for revision 94812:
more attempts to increase clarity
Changed:
U z3c.autoinclude/trunk/src/z3c/autoinclude/dependency.py
U z3c.autoinclude/trunk/src/z3c/autoinclude/dependency.txt
U z3c.autoinclude/trunk/src/z3c/autoinclude/plugin.py
U z3c.autoinclude/trunk/src/z3c/autoinclude/utils.py
U z3c.autoinclude/trunk/src/z3c/autoinclude/zcml.py
-=-
Modified: z3c.autoinclude/trunk/src/z3c/autoinclude/dependency.py
===================================================================
--- z3c.autoinclude/trunk/src/z3c/autoinclude/dependency.py 2009-01-17 20:58:43 UTC (rev 94811)
+++ z3c.autoinclude/trunk/src/z3c/autoinclude/dependency.py 2009-01-17 22:05:13 UTC (rev 94812)
@@ -4,27 +4,29 @@
from pkg_resources import get_provider
from pkg_resources import get_distribution
from z3c.autoinclude.utils import DistributionManager
+from z3c.autoinclude.utils import ZCMLInfo
class DependencyFinder(DistributionManager):
- def includableInfo(self, include_candidates):
+
+ def includableInfo(self, zcml_to_look_for):
"""Return the packages in the dependencies which are includable.
- include_candidates - a list of include files we are looking for
+ zcml_to_look_for - a list of zcml filenames we are looking for
Returns a dictionary with the include candidates as keys, and lists
of dotted names of packages that contain the include candidates as
values.
"""
- result = {}
+ result = ZCMLInfo(zcml_to_look_for)
for req in self.context.requires():
dist_manager = DistributionManager(get_provider(req))
for dotted_name in dist_manager.dottedNames():
module = resolve(dotted_name)
- for candidate in include_candidates:
+ for candidate in zcml_to_look_for:
candidate_path = os.path.join(
os.path.dirname(module.__file__), candidate)
if os.path.isfile(candidate_path):
- result.setdefault(candidate, []).append(dotted_name)
+ result[candidate].append(dotted_name)
return result
def package_includes(project_name, zcml_filenames=None):
Modified: z3c.autoinclude/trunk/src/z3c/autoinclude/dependency.txt
===================================================================
--- z3c.autoinclude/trunk/src/z3c/autoinclude/dependency.txt 2009-01-17 20:58:43 UTC (rev 94811)
+++ z3c.autoinclude/trunk/src/z3c/autoinclude/dependency.txt 2009-01-17 22:05:13 UTC (rev 94812)
@@ -140,13 +140,15 @@
>>> from z3c.autoinclude import package_includes
>>> pprint(package_includes('BCPackage'))
- {'configure.zcml': ['F.H'], 'meta.zcml': ['testdirective', 'F.G', 'F.H']}
+ {'configure.zcml': ['F.H'],
+ 'meta.zcml': ['testdirective', 'F.G', 'F.H'],
+ 'overrides.zcml': []}
As with ``includableInfo``, we can also supply a list of ZCML filenames to search for::
>>> pprint(package_includes('BCPackage', ['configure.zcml', 'silly.zcml']))
- {'configure.zcml': ['F.H']}
-
+ {'configure.zcml': ['F.H'], 'silly.zcml': []}
+
Note that it will not catch DistributionNotFound errors::
>>> package_includes('NonexistentPackage')
Modified: z3c.autoinclude/trunk/src/z3c/autoinclude/plugin.py
===================================================================
--- z3c.autoinclude/trunk/src/z3c/autoinclude/plugin.py 2009-01-17 20:58:43 UTC (rev 94811)
+++ z3c.autoinclude/trunk/src/z3c/autoinclude/plugin.py 2009-01-17 22:05:13 UTC (rev 94812)
@@ -3,21 +3,22 @@
from pkg_resources import resource_filename
from z3c.autoinclude.utils import DistributionManager
from z3c.autoinclude.utils import distributionForDottedName
+from z3c.autoinclude.utils import ZCMLInfo
class PluginFinder(DistributionManager):
def __init__(self, platform_dottedname):
self.context = distributionForDottedName(platform_dottedname)
self.dottedname = platform_dottedname
- def includableInfo(self, include_candidates):
- includable_info = {}
+ def includableInfo(self, zcml_to_look_for):
+ includable_info = ZCMLInfo(zcml_to_look_for)
for plugin_distribution in find_plugins(self.dottedname):
include_finder = DistributionManager(plugin_distribution)
for plugin_dottedname in include_finder.dottedNames():
- groups = zcml_to_include(plugin_dottedname, include_candidates)
- for group in groups:
- includable_info.setdefault(group, []).append(plugin_dottedname)
+ groups = zcml_to_include(plugin_dottedname, zcml_to_look_for)
+ for zcml_group in groups:
+ includable_info[zcml_group].append(plugin_dottedname)
return includable_info
Modified: z3c.autoinclude/trunk/src/z3c/autoinclude/utils.py
===================================================================
--- z3c.autoinclude/trunk/src/z3c/autoinclude/utils.py 2009-01-17 20:58:43 UTC (rev 94811)
+++ z3c.autoinclude/trunk/src/z3c/autoinclude/utils.py 2009-01-17 22:05:13 UTC (rev 94812)
@@ -33,6 +33,13 @@
if subpackage not in ns_dottednames:
result.append(subpackage)
return result
+
+class ZCMLInfo(dict):
+ def __init__(self, zcml_to_look_for):
+ dict.__init__(self)
+ for zcml_group in zcml_to_look_for:
+ self[zcml_group] = []
+
def subpackageDottedNames(package_path, ns_dottedname=None):
# we do not look for subpackages in zipped eggs
Modified: z3c.autoinclude/trunk/src/z3c/autoinclude/zcml.py
===================================================================
--- z3c.autoinclude/trunk/src/z3c/autoinclude/zcml.py 2009-01-17 20:58:43 UTC (rev 94811)
+++ z3c.autoinclude/trunk/src/z3c/autoinclude/zcml.py 2009-01-17 22:05:13 UTC (rev 94812)
@@ -12,7 +12,9 @@
log = logging.getLogger("z3c.autoinclude")
def includeZCMLGroup(_context, info, filename, override=False):
- includable_zcml = list(info.get(filename, []))
+ includable_zcml = info[filename]
+ # ^^ a key error would mean that we are trying to include a group of ZCML
+ # with a filename that wasn't ever searched for. that *should* be an error
zcml_context = repr(_context.info)
@@ -75,6 +77,7 @@
def includePluginsDirective(_context, package, file=None):
dotted_name = package.__name__
+
if file is None:
zcml_to_look_for = ['meta.zcml', 'configure.zcml']
else:
More information about the Checkins
mailing list