Commits

Lynn Rees committed 1385787

- namespacing

Comments (0)

Files changed (12)

 # -*- coding: utf-8 -*-
+# pylint: disable-msg=w0232
 '''graphalchemy appconf'''
 
 from __future__ import absolute_import
 
 class Appconf(Patterns):
 
-    label = 'graphalchemy',
+    label = 'graphalchemy'
+    backends = include('graphalchemy.backends.apps')
 
     class collection(Include):
         link = 'graphalchemy.collections.Links'
         node = 'graphalchemy.collections.Nodes'
-
-        class model(Include):
-            link = 'graphalchemy.collections.ModelLinks'
-            node = 'graphalchemy.collections.ModelNodes'
-
-    backends = include('graphalchemy.backends.apps')
+        link_model = 'graphalchemy.collections.ModelLinks'
+        node_model = 'graphalchemy.collections.ModelNodes'
 
     class helper(Include):
         model = 'graphalchemy.helpers.Model'
         link = 'graphalchemy.writers.Links'
         node = 'graphalchemy.writers.Nodes'
 
+    class finder(Include):
+        link = 'graphalchemy.core.link'
+        node = 'graphalchemy.core.node'
+
 
 appconf = Appconf.build()
 
 
 class Internals(InternalSettings):
 
-    appspace = appconf
-
     appspace = 'graphalchemy'
     backends = 'graphalchemy.backends'
 
 
-appconf.internals = Internals
-
-
 class Defaults(DefaultSettings):
 
     appspace = Internals.appspace
     backends = Internals.backends
     backend = 'backends.neo4j.embedded'
 
-    class manager(Include):
+    class manager:
         graph = 'manager.graph'
         node = Appconf.manager.node
         link = Appconf.manager.link
 
-    class model(Include):
+    class model:
         node = Appconf.model.node
         link = Appconf.model.link
 
-    class generic(Include):
+    class generic:
         link = Appconf.generic.link
         node = Appconf.generic.node
 
-    class read(Include):
+    class read:
         link = 'backends.neo4j.read.link'
         node = 'backends.neo4j.read.node'
 
-    class write(Include):
+    class write:
         link = 'backends.neo4j.write.link'
         node = 'backends.neo4j.write.node'
 
-    class wrapper(Include):
+    class wrapper:
         link = Appconf.wrapper.link
         node = Appconf.wrapper.node
 
-    class collection(Include):
+    class collection:
         node = Appconf.collection.node
         link = Appconf.collection.link
+        node_model = Appconf.collection.node_model
+        link_model = Appconf.collection.link_model
 
-        class model(Include):
-            node = Appconf.collection.model.node
-            link = Appconf.collection.model.link
-
-    class reader(Include):
+    class reader:
         link = Appconf.reader.link
         node = Appconf.reader.node
 
-    class writer(Include):
+    class writer:
         link = Appconf.writer.link
         node = Appconf.writer.node
 
-    class helper(Include):
+    class helper:
         writer = Appconf.helper.writer
         model = Appconf.helper.model
 
+    class finder:
+        link = Appconf.finder.link
+        node = Appconf.finder.link
 
-appconf.defaults = Defaults
+
+appconf.settings.internals = Internals
+appconf.settings.defaults = Defaults

graphalchemy/collections.py

 # -*- coding: utf-8 -*-
+# pylint: disable-msg=w0212
 '''graph element collections'''
 
 from __future__ import absolute_import
 
-from appspace import component, lazy
+from stuf.utils import lazy
+from appspace import component
 
 from .core import Appspaced
 from .errors import UnrelatedLinkError
 
     _inner = []
 
-    def __init__(self, this):
+    def __init__(self, this, model=None):
         '''
         @param this: graph model instance
         '''
         super(Collection, self).__init__()
         self.this = this
+        self.model = self._finder(model)
         self._g = this._g
 
     def __getitem__(self, key):
     def __len__(self):
         return len(self._inner)
 
+    def _finder(self, model, element):
+        pass
+
     @lazy
     def deep_dump(self):
         '''deep serializeable form of graph elements in this collection'''
 
     '''nodes collection'''
 
-    _collection = component(Nodes.settings.collection.node)
+    _collection = component(Nodes.s.collection.node)
+    _finder = component(ModelLinks.s.finder.node)
 
-    def __init__(self, this, model):
-        super(Nodes, self).__init__(this)
+    def __init__(self, this, model=None):
+        super(Nodes, self).__init__(this, model)
         self.n = self.this.n
-        self.model = self.n.default(model)
 
     @lazy
     def forks(self):
     '''links collection'''
 
     # internal components
-    _collection = component(Links.settings.collection.link)
+    _finder = component(ModelLinks.s.finder.link)
+    _collection = component(Links.s.collection.link)
 
     def __init__(self, this, model=None):
         super(Links, self).__init__(this)
         self.l = self.this.l
-        self.model = self.l.default(model)
 
     @lazy
     def ins(self):
 
     '''collection of graph element models'''
 
-    def __init__(self, this=None, **kw):
+    def __init__(self, this=None, model=None, **kw):
         '''
         @param this: graph model instance
         '''
-        super(ModelCollection, self).__init__(this)
+        super(ModelCollection, self).__init__(this, model)
         self.direction = kw.get('direction')
         self.keys = kw.get('keys', {})
         self.name = kw.get('name')
 
     '''collection of nodes from a specific instance'''
 
+    _finder = component(ModelLinks.s.finder.node)
+
     def __init__(self, this, model=None, **kw):
-        super(ModelNodes, self).__init__(this, **kw)
+        super(ModelNodes, self).__init__(this, model, **kw)
         self.n = self.this.n
-        self.model = self.n.default(model)
         self.l = self.this.l
 
     @property
 
     '''collection of links from a specific instance'''
 
+    _finder = component(ModelLinks.s.finder.link)
+
     def __init__(self, this, model=None, **kw):
-        super(ModelLinks, self).__init__(this, **kw)
+        super(ModelLinks, self).__init__(this, model, **kw)
         self.l = self.this.l
-        self.model = self.l.default(model)
 
     @lazy
     def config(self):
 
 from __future__ import absolute_import
 
-
 from appspace import appspacer, delegater
 
 from .apps import appconf

graphalchemy/directions.py

 
 from __future__ import absolute_import
 
-from appspace import component, lazy
+from stuf.utils import lazy
+from appspace import component
 
 from .core import Appspaced
 
 
     '''direction definition'''
 
+    _finder = component(In.s.finder.node)
+    _collection = component(Direction.s.collection.node_model)
     direction = ''
     link_end = ''
 
-    _collection = component(Direction.settings.collection.model.node)
-
     def __init__(self, model=None, link=''):
         '''
         @param model: model with direction (default: None)
         '''
         super(Direction, self).__init__()
         self.link = link
-        self._model = model
+        self.model = self._finder(model)
 
     def __get__(self, instance, model):
         if instance is None:
         return self._collection(instance, **self.config)
 
     @lazy
-    def model(self):
-        return self._finder(self._model)
-
-    @lazy
     def config(self):
         return dict(
             name=self.model.c.name,
 
     direction = 'incoming'
     link_end = 'start'
-    _finder = component(In.settings.finder.node)
 
 
 class Out(Direction):
 
     direction = 'outgoing'
     link_end = 'end'
-    _finder = component(Out.settings.finder.link)

graphalchemy/graphs.py

 from __future__ import absolute_import
 
 from appspace.error import NoAppError
-from appspace.states import global_settings
-from appspace import app, add_app, component
+from appspace import add_app, component
 from stuf.utils import class_name, object_name, lazy
 
 from .core import Appspaced
     '''graph database interface'''
 
     ## internal components
-    _node_manager = component(Graph.settings.manager.node)
-    _link_manager = component(Graph.settings.manager.link)
+    _node_manager = component(Graph.s.manager.node)
+    _link_manager = component(Graph.s.manager.link)
 
     def __init__(self, url, **kw):
         super(Graph, self).__init__()
 
     @lazy
     def settings(self):
-        return self.appspace.settings
+        return self.a.settings
 
     @lazy
     def nodes(self):
         '''
         add configuration to global configuration
         '''
-        global_settings.set(key, value, namespace)
+        self.a.appspace.set(key, value, namespace)
 
-    def default(self, model=None, element=None):
+    def register(self, model):
+        '''
+        add model class to appspace
+
+        @param model: graph element model
+        '''
+        add_app(
+            self.a, object_name(model).lower(), model, model.appspace
+        )
+
+
+class Finder(Appspaced):
+
+    @property
+    def _default(self):
+        pass
+
+    def __call__(self, model=None, element=None):
         '''
         get default model
 
         @param element: graph database element
         '''
         if model is None:
-            model = app[self.appspace][self.settings.DEFAULT.NODE_MODEL]
-            if all([
-                element is not None,
-                not isinstance(element, model),
-            ]):
+            if element is not None:
                 try:
-                    model = app[self.appspace][element['_model']]
+                    model = self.a[Finder.s.appspace][element['_model']]
                 except NoAppError:
                     pass
-        elif isinstance(model, basestring):
-            model = app[self.appspace][model.lower()]
+            elif isinstance(model, basestring):
+                model = self.a[Finder.s.appspace][model.lower()]
+            else:
+                model = self._default
         return model
 
-    def register(self, model):
-        '''
-        add model class to appspace
 
-        @param model: graph element model
-        '''
-        add_app(app, object_name(model).lower(), model, model.appspace, True)
+class Nodes(Appspaced):
+
+    _model = component(Nodes.s.generic.node)
+
+
+class Links(Appspaced):
+
+    _model = component(Links.s.generic.link)

graphalchemy/helpers.py

 from markupsafe import escape
 
 import nanotime
-from stuf import istuf
-from appspace import lazy
+from stuf import stuf
+from stuf.utils import lazy
 
 
 class Model(object):
     @lazy
     def future_diff(self):
         '''future changes'''
-        return istuf({
+        return stuf({
             k: v for k, v in self.current.iteritems() if k in self.changed
         })
 
     @lazy
     def past_diff(self):
         '''past changes'''
-        return istuf({
+        return stuf({
             k: v for k, v in self.past.iteritems() if k in self.changed
         })
 

graphalchemy/managers.py

 
     '''graph node manager'''
 
-    _wrapper = component(Nodes.settings.wrapper.node)
+    _wrapper = component(Nodes.s.wrapper.node)
 
 
 class Links(Manager):
 
     '''graph link manager'''
 
-    _wrapper = component(Links.settings.wrapper.link)
+    _wrapper = component(Links.s.wrapper.link)

graphalchemy/models.py

 from __future__ import absolute_import
 
 from stuf import stuf
-from stuf.utils import object_name
+from appspace import component
 from appspace.traits import HasTraits, Meta
-from appspace import component, lazy_class, lazy, both
+from stuf.utils import object_name, lazy_class, lazy, both
 
 from .core import Appspaced
 
 
     '''graph element model'''
 
-    _g = component(Model.settings.manager.graph)
-    _h = component(Model.settings.helper.model)
-    _link_collection = component(Model.settings.collection.link)
+    _g = component(Model.s.manager.graph)
+    _h = component(Model.s.helper.model)
+    _link_collection = component(Model.s.collection.link)
 
     def __init__(self, element=None, **kw):
         '''
 
     '''node model'''
 
-    _node_collection = component(Node.settings.collection.node)
+    _node_collection = component(Node.s.collection.node)
 
     ## pylint: disable-msg=e0102,e1101
     @lazy

graphalchemy/readers.py

 # -*- coding: utf-8 -*-
+# pylint: disable-msg=w0221
 '''graph readers'''
 
 from __future__ import absolute_import
 
-from appspace import component, delegatable, lazy
+from stuf.utils import lazy
+from appspace import component, delegatable
 
 from .core import Appspaced
 
 
-class Query(Appspaced):
+class Reader(Appspaced):
 
-    '''graph query base'''
+    '''graph reader base'''
 
     _delegatable = True
 
     def __init__(self, db):
-        super(Query, self).__init__()
+        super(Reader, self).__init__()
         self.db = db
 
+    def _finder(self, model, element):
+        pass
+
+    def _read(self, model):
+        pass
+
     @lazy
     def r(self):
         '''qraph database query'''
         return [i for i in self.walk(this, direction, label, keys)]
 
 
-class Nodes(Query):
+class Nodes(Reader):
 
-    '''graph node query'''
+    '''graph node reader'''
 
-    _finder = component(Nodes.settings.finder.node)
-    _read = component(Nodes.settings.read.node)
+    _finder = component(Nodes.s.finder.node)
+    _read = component(Nodes.s.read.node)
 
     @delegatable(modeled=True)
     def anchor(self, model=None):
         return [i for i in self.walk(this, direction, end, label, keys)]
 
 
-class Links(Query):
+class Links(Reader):
 
-    '''graph link query'''
+    '''graph link reader'''
 
-    _finder = component(Links.settings.finder.link)
-    _read = component(Links.settings.read.link)
+    _finder = component(Links.s.finder.link)
+    _read = component(Links.s.read.link)
 
     @delegatable(modeled=False)
     def get_by(self, this, key, value=None):

graphalchemy/wrappers.py

 
     '''node model wrapper'''
 
-    _finder = component(Nodes.settings.finder.node)
-    _read = delegate(Nodes.settings.reader.node)
-    _writer = delegate(Nodes.settings.writer.node)
+    _finder = component(Nodes.s.finder.node)
+    _read = delegate(Nodes.s.reader.node)
+    _writer = delegate(Nodes.s.writer.node)
 
 
 class Links(Wrapper):
 
     '''link model wrapper'''
 
-    _finder = component(Links.settings.finder.link)
-    _read = delegate(Links.settings.reader.link)
-    _writer = delegate(Links.settings.writer.link)
+    _finder = component(Links.s.finder.link)
+    _read = delegate(Links.s.reader.link)
+    _writer = delegate(Links.s.writer.link)

graphalchemy/writers.py

 # -*- coding: utf-8 -*-
+# pylint: disable-msg=w0212
 '''graph writers'''
 
 from __future__ import absolute_import
     '''graph writer base'''
 
     # internal components
-    _h = component(Writer.settings.helper.writer)
+    _h = component(Writer.s.helper.writer)
 
     # internal settings
     delegatable = True
         self.db = db
         self.r = query
 
+    def _finder(self, model):
+        pass
+
     def _preprocess(self, this, model=None):
         '''
         preprocess database element
 
     '''graph node writer'''
 
-    _finder = component(Nodes.settings.finder.node)
-    _wrapper = component(Nodes.settings.wrapper.node)
+    _finder = component(Nodes.s.finder.node)
+    _wrapper = component(Nodes.s.wrapper.node)
 
     def _postprocess(self, this, model=None):
         '''
 
     '''graph link writer'''
 
-    _finder = component(Links.settings.finder.link)
-    _wrapper = component(Links.settings.wrapper.link)
+    _finder = component(Links.s.finder.link)
+    _wrapper = component(Links.s.wrapper.link)
 
     @delegate(modeled=True)
     def build(self, link, start, end, model=None, kw=None):
         'Programming Language :: Python :: 2.7',
         'Programming Language :: Python :: Implementation :: CPython',
     ],
-    requirements=['appspace>=0.5.0', 'nanotime', 'stuf', 'MarkupSafe'],
+    requirements=['appspace>=0.5.0', 'nanotime', 'stuf>=0.6.0', 'MarkupSafe'],
     zip_safe=False,
 )