Include package from inner module
authorThierry Florac <tflorac@ulthar.net>
Fri, 06 Mar 2015 18:50:25 +0100
changeset 12 88e572df4a82
parent 11 7693c14c352e
child 13 e84adc865c35
Include package from inner module
src/pyams_utils/__init__.py
src/pyams_utils/include.py
--- a/src/pyams_utils/__init__.py	Fri Mar 06 18:49:50 2015 +0100
+++ b/src/pyams_utils/__init__.py	Fri Mar 06 18:50:25 2015 +0100
@@ -18,13 +18,6 @@
 # import interfaces
 
 # import packages
-from chameleon import PageTemplateFile
-from pyams_utils.context import ContextSelector
-from pyams_utils.request import get_annotations, get_debug
-from pyams_utils.site import site_factory
-from pyams_utils.tales import ExtensionExpr
-from pyams_utils.traversing import NamespaceTraverser
-from z3c.pt.pagetemplate import PageTemplateFile as Z3cPageTemplateFile
 
 from pyramid.i18n import TranslationStringFactory
 _ = TranslationStringFactory('pyams_utils')
@@ -32,33 +25,5 @@
 
 def includeme(config):
     """pyams_utils features include"""
-
-    # add translations
-    config.add_translation_dirs('pyams_utils:locales')
-
-    # define root factory
-    config.set_root_factory(site_factory)
-
-    # add request annotations
-    config.add_request_method(get_annotations, 'annotations', reify=True)
-    config.add_request_method(get_debug, 'debug', reify=True)
-
-    # add traverser handling namespaces via "++ns++(options)" URLs
-    config.add_traverser(NamespaceTraverser)
-
-    # add custom subscriber predicate to filter events via supported interface(s)
-    config.add_subscriber_predicate('context_selector', ContextSelector)
-
-    # load registry components
-    try:
-        import pyams_zmi
-    except ImportError:
-        config.scan(ignore='pyams_utils.zmi')
-    else:
-        config.scan()
-
-    if hasattr(config, 'load_zcml'):
-        config.load_zcml('configure.zcml')
-
-    PageTemplateFile.expression_types['extension'] = ExtensionExpr
-    Z3cPageTemplateFile.expression_types['extension'] = ExtensionExpr
+    from .include import include_package
+    include_package(config)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/pyams_utils/include.py	Fri Mar 06 18:50:25 2015 +0100
@@ -0,0 +1,65 @@
+#
+# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
+# All Rights Reserved.
+#
+# This software is subject to the provisions of the Zope Public License,
+# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
+# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
+# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
+# FOR A PARTICULAR PURPOSE.
+#
+
+__docformat__ = 'restructuredtext'
+
+
+# import standard library
+
+# import interfaces
+from zope.annotation.interfaces import IAttributeAnnotatable, IAnnotations
+
+# import packages
+from chameleon import PageTemplateFile
+from pyams_utils.context import ContextSelector
+from pyams_utils.request import get_annotations, get_debug
+from pyams_utils.site import site_factory
+from pyams_utils.tales import ExtensionExpr
+from pyams_utils.traversing import NamespaceTraverser
+from z3c.pt.pagetemplate import PageTemplateFile as Z3cPageTemplateFile
+from zope.annotation.attribute import AttributeAnnotations
+
+
+def include_package(config):
+    """Pyramid package include"""
+
+    # add translations
+    config.add_translation_dirs('pyams_utils:locales')
+
+    # define root factory
+    config.set_root_factory(site_factory)
+
+    # add request annotations
+    config.add_request_method(get_annotations, 'annotations', reify=True)
+    config.add_request_method(get_debug, 'debug', reify=True)
+
+    # add traverser handling namespaces via "++ns++(options)" URLs
+    config.add_traverser(NamespaceTraverser)
+
+    # add custom subscriber predicate to filter events via supported interface(s)
+    config.add_subscriber_predicate('context_selector', ContextSelector)
+
+    # load registry components
+    config.registry.registerAdapter(AttributeAnnotations, (IAttributeAnnotatable, ), IAnnotations)
+
+    try:
+        import pyams_zmi
+    except ImportError:
+        config.scan(ignore='pyams_utils.zmi')
+    else:
+        config.scan()
+
+    if hasattr(config, 'load_zcml'):
+        config.load_zcml('configure.zcml')
+
+    PageTemplateFile.expression_types['extension'] = ExtensionExpr
+    Z3cPageTemplateFile.expression_types['extension'] = ExtensionExpr