Commits

Lynn Rees  committed 4b418d5

- commit point

  • Participants
  • Parent commits 1cfc377

Comments (0)

Files changed (7)

File appspace/__init__.py

 # -*- coding: utf-8 -*-
 '''appspace'''
 
-from appspace.keys import appifies
+from appspace.managers import Manager
 from appspace.registry import Registry
-from appspace.keys import NoAppError, AppLookupError
 from appspace.builders import patterns, class_patterns
-from appspace.spaces import Branch, Namespace, Patterns, include
+from appspace.spaces import (
+    Branch, Namespace, Patterns, include, space_patterns)
+from appspace.keys import (
+    NoAppError, AppLookupError, AppspaceKey, Attribute, appifies)
 
-__version__ = (0, 5, 4)
+__version__ = (0, 6, 0)

File appspace/builders.py

 # -*- coding: utf-8 -*-
 '''appspace builder'''
 
-from appspace.spaces import patterns as apatterns
+from appspace.spaces import space_patterns
 from appspace.keys import AAppspace, appifies, AppLookupError, NoAppError
 
-__all__ = ['patterns']
+__all__ = ['patterns', 'class_patterns']
 
 
 @appifies(AAppspace)
 
     @param label: label for manager
     '''
-    return Appspace(apatterns(label, *args, **kw))
+    return Appspace(space_patterns(label, *args, **kw))
 
 
 def class_patterns(clspatterns):

File appspace/keys.py

 # -*- coding: utf-8 -*-
-#@PydevCodeAnalysisIgnore
 '''appspace keys'''
 
+from stuf.utils import map as exhaustmap
 # pylint: disable-msg=f0401
+from zope.interface.interface import InterfaceClass
 from zope.interface.interfaces import ComponentLookupError
-from zope.interface.interface import InterfaceClass, Attribute
-from zope.interface import implementer, directlyProvides, providedBy
+from zope.interface import implementer, Attribute, implementedBy
 from zope.interface.adapter import AdapterRegistry, VerifyingAdapterRegistry
 # pylint: enable-msg=f0401
 
+keys = implementedBy
 AppStore = AdapterRegistry
 StrictAppStore = VerifyingAdapterRegistry
-apped = directlyProvides
-appifies = implementer
-get_apps = providedBy
 # primary key
 AppspaceKey = InterfaceClass('AppspaceKey')
 # app lookup exception
 AppLookupError = ComponentLookupError
 
 
+class appifies(implementer):
+
+    def __init__(self, key, **metadata):
+        exhaustmap(metadata, key.setTaggedValue)
+        super(appifies, self).__init__(key)
+
+
 class AApp(AppspaceKey):
 
     '''app key'''
 
     manager = Attribute('appspace manager')
 
-    def __call__(label, *args, **kw):
+    def __call__(label, *args, **kw):  # @NoSelf
         '''@param label: label of app in appspace'''
 
-    def __getattr__(label):
+    def __getattr__(label):  # @NoSelf
         '''get attribute'''
 
-    def __getitem__(label):
+    def __getitem__(label):  # @NoSelf
         '''get item'''
-        
+
 
 class ABranch(AppspaceKey):
 
     '''branch key'''
 
 # pylint: disable-msg=e0211
-    def build():
+    def build():  # @NoSelf
         '''build appspace'''
 # pylint: enable-msg=e0211
 
 class AManager(AppspaceKey):
 
     '''appspace key'''
-    
-    def apply(label, key=False, *args, **kw):
+
+    def apply(label, key=False, *args, **kw):  # @NoSelf
         '''
         invoke appspaced callable
 
         @param key: key label (default: False)
         '''
 
-    def get(label, key=False):
+    def get(label, key=False):  # @NoSelf
         '''
         get thing from appspace
 
         @param key: appspace key (default: False)
         '''
 
-    def load(label, key, module):
+    def load(label, key, module):  # @NoSelf
         '''
         import thing into appspace
 
         @param key: appspace key
         @param module: module path
         '''
-        
-    def namespace(label):
+
+    def namespace(label):  # @NoSelf
         '''
         fetch key
 
         @param label: appspace key label
         '''
-        
-    def partial(call, key=False, *args, **kw):
-        '''
-        partialize callable or appspaced application with any passed parameters
 
-        @param call: callable or appspaced object label
-        @param key: appspace key label (default: False)
-        '''
-        
-    def set(label=False, thing=False, key=False):
+    def set(label=False, thing=False, key=False):  # @NoSelf
         '''
         add thing to appspace
 
         @param key: key label (default: False)
         @param thing: new appspace thing (default: False)
         '''
-        
-    def slugify(value):
+
+    def slugify(value):  # @NoSelf
         '''
         normalizes string, converts to lowercase, removes non-alpha characters,
         and converts spaces to hyphens
 class ANamespace(AppspaceKey):
 
     '''namespace key'''
-    
-    
+
+
 class ConfigurationError(Exception):
 
     '''appspace configuration exception'''

File appspace/managers.py

         app = self.lookup1(key, key, label)
         if app is None:
             raise AppLookupError(app, label)
-        return self._unlazy(label, key, app)
+        return self.load(label, key, app)
 
     def namespace(self, label):
         '''

File appspace/registry.py

 from inspect import isclass
 
 from stuf.six import u, strings
+from stuf.utils import exhaustmap
 
 from appspace.utils import lazyimport, checkname
 from appspace.keys import (
     ALazyLoad, AppStore, InterfaceClass, AApp, StrictAppStore, ANamespace,
-    AManager, appifies)
-
-__all__ = ('LazyLoad', 'Registry', 'StrictRegistry')
+    AManager, appifies, keys)
 
 
 @appifies(ALazyLoad)
 
     '''lazy import loader'''
 
-    __slots__ = ['path']
+    __slots__ = ['_path']
 
     def __init__(self, path):
         '''
 
         @param path: path to component
         '''
-        self.path = path
+        self._path = path
 
     def __repr__(self):
-        return 'lazy import from {}'.format(self.path)
+        return 'lazy import from "{}"'.format(self.path)
+
+    @property
+    def path(self):
+        module = self._path
+        app = lazyimport(module[-1]) if isinstance(
+            module, tuple
+        ) else lazyimport(module)
+        return app, next(list(keys(app)))
 
 
 class RegistryMixin(object):
             thing, (strings, tuple)
         ) else thing
 
-    def _unlazy(self, label, key, thing):
-        return self.load(
-            label, key, thing.path
-        ) if self.keyed(ALazyLoad, thing) else thing
-
     @classmethod
     def create(cls):
         '''create new key'''
             self.register([key], key, label, this)
         return this
 
-    def load(self, label, key, module):
+    def load(self, label, key, thing):
         '''
         import thing into appspace
 
         @param label: appspaced thing label
         @param key: appspace key
-        @param module: module path
+        @param thing: some thing
         '''
-        # add branch appspace from include
-        app = lazyimport(module[-1]) if isinstance(
-            module, tuple
-        ) else lazyimport(module)
-        # register get
+        if not self.keyed(ALazyLoad, thing):
+            return thing
+        app, appkey = thing.path
+        key = key if not appkey else appkey
         self.register([key], key, label, app)
         return app
 
         '''universal unique identifier'''
         return uuid.uuid4().hex.upper()
 
+    def pack(self, label, call):
+        '''
+        pack things into registry
+
+        @param label: event label
+        @param call: some thing
+        '''
+        self.ez_register(self._key, label, self._lazy(call))
+
+    def update(self, labels):
+        '''
+        update event with other registries
+
+        @param labels: eventconf
+        '''
+        exhaustmap(vars(labels), self.pack, lambda x: not x[0].startswith('_'))
+
 
 class Registry(RegistryMixin, AppStore):
 

File appspace/spaces.py

 
 factory = Patterns.factory
 include = Branch.include
-patterns = Patterns.patterns
+space_patterns = Patterns.patterns
 
 setup(
     name='appspace',
-    version='0.5.4',
+    version='0.6.0',
     description='easy application construction with easy building blocks',
     long_description=open(join(getcwd(), 'README.rst'), 'r').read(),
     keywords='component architecture injection aspect-oriented',