Commits

Lynn Rees committed 1508b32

- make inclusion of branch appspaces less magical by requiring name of appconf
module when passed to 'include' e.g. 'module.path.apps' instead of 'module.path'
- change default name of app configuration object to 'appconf' from 'apps'
- rename 'add_appspace' function to 'add_branch'

Comments (0)

Files changed (12)

CHANGELOG

-0.1.1
-
-- release
-
-0.1.2
-
-- use importlib
-
-0.1.3
-
-- python 2.6 support
-
-0.2.0
-
-- dynamic binding support
-
-0.3.0
-
-- lazy load modules from appconf
-
-0.3.1
-
-- remove zope.component dependency
-
-0.3.2
-
-- shift to absolute imports
-
-0.3.3
-
-- add utility functions
+0.1.1
+
+- release
+
+0.1.2
+
+- use importlib
+
+0.1.3
+
+- python 2.6 support
+
+0.2.0
+
+- dynamic binding support
+
+0.3.0
+
+- lazy load modules from appconf
+
+0.3.1
+
+- remove zope.component dependency
+
+0.3.2
+
+- shift to absolute imports
+
+0.3.3
+
+- add utility functions
+
+0.4.0
+
+- make inclusion of branch appspaces less magical by requiring name of appconf
+module when passed to 'include' e.g. 'module.path.apps' instead of 'module.path'
+- change default name of app configuration object to 'appconf' from 'apps'
+- rename 'add_appspace' function to 'add_branch'

LICENSE

-Copyright (c) 2006-2012 L. C. Rees.  All rights reserved.
-Copyright (c) 2009 Raymond Hettinger
-
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
+Copyright (c) 2006-2012 L. C. Rees.  All rights reserved.
+Copyright (c) 2009 Raymond Hettinger
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
-include LICENSE
-include CHANGELOG
+include LICENSE.txt
+include CHANGELOG.txt
 include MANIFEST.in
 include README.rst
 recursive-include appspace *.py
 similar to a Django urlconf:
 
 >>> from appspace import patterns
->>> apps = patterns(
+>>> appconf = patterns(
 ...    'helpers',
 ...    ('square', 'math.sqrt'),
 ...    ('fabulous', 'math.fabs'),
-...    include('subapp', 'foo.bar')
+...    include('subapp', 'foo.bar.apps')
 ... )
 
 Once configured, application components can be accessed as object attributes,

appspace/__init__.py

 
 from __future__ import absolute_import
 
-from .builder import include, patterns, add_app, add_appspace, app
+from .builder import include, patterns, add_app, add_branch, app

appspace/builder.py

 from .error import AppLookupError, NoAppError
 from .state import AppspaceManager, global_appspace, appifies
 
-def add_app(appspace, name, new_app, branch=''):
+def add_app(appspace, name, new_app, branch='', use_global=False):
     '''
     add new app to existing namespace
     
     @param name: name of branch appspace
     '''
     if branch:
-        new_appspace = add_appspace(appspace, branch)
-    new_appspace.appspace.set_live(new_app, name)
+        appspace = add_branch(appspace, branch)
+    elif use_global:
+        appspace = global_appspace
+    appspace.appspace.set_live(new_app, name)
 
-def add_appspace(appspace, name):
+def add_branch(appspace, name):
     '''
     add new appspace to existing appspace
 
         '''
         @param name: name of appspace
         '''
-        # name of branch appspace module e.g. someapp.apps
-        self._appconf = kw.get('appconf', 'apps')
-        # name of appspace in branch appspace module e.g. someapp.apps.apps
-        self._appname = kw.get('appname', 'apps')
-        # use global appspace instead of local appspace
+        # name of appspace in branch appspace module e.g. someapp.apps.appconf
+        self._appconf = kw.get('appconf', 'appconf')
+        # whether to use global appspace instead of local appspace
         self._global = kw.get('use_global', False)
         # namespace
         self._name = name
         if self._global: 
             return global_appspace
         # using local appspace
-        return AppspaceManager()
+        return AppspaceManager(self._appconf)
 
 
 class Appspace(object):

appspace/state.py

     '''appspace state manager'''
 
     appifies(AAppspaceManager)
+    
+    def __init__(self, appconf='appconf'):
+        super(AppspaceManager, self).__init__()
+        self._appconf = appconf
         
     def _app(self, name, path):
         '''
         '''
         # register branch appspace from included module
         if isinstance(path, tuple):
-            app = getattr(self._load('.'.join([path[-1], 'apps'])), 'apps')
+            app = getattr(self._load(path[-1]), self._appconf)
         # register app
         else:
             app = self._load(path)
         self.register((), appspace, name, app)
         
     def set_live(self, app, name, appspace=AApp):
-        '''live app registrar'''
         if isinstance(app, basestring):
             app = App(app)
         self.register((), appspace, name, app)

appspace/test/apps.py

 # -*- coding: utf-8 -*-
 from appspace import patterns
 
-apps = patterns(
+appconf = patterns(
     '',
     ('square', 'math.sqrt'),
     ('fabulous', 'math.fabs'),

appspace/test/tests.py

         from appspace import patterns, include
         patterns(
             'helpers',
-            ('misc', include('appspace.test')),
+            ('misc', include('appspace.test.apps')),
             use_global=True,
         )
 
 
 setup(
     name='appspace',
-    version='0.3.3',
+    version='0.4.0',
     description='easily construct applications with easy building blocks',
     long_description=open(os.path.join(os.getcwd(), 'README.rst'), 'rb').read(),
     author='L. C. Rees',