You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@allura.apache.org by jo...@apache.org on 2013/12/12 19:55:51 UTC

[1/4] git commit: [#6830] Let derived tools 'inherit' static resources from parent

Updated Branches:
  refs/heads/master 1eea58c63 -> 4aeceac34


[#6830] Let derived tools 'inherit' static resources from parent

Signed-off-by: Tim Van Steenburgh <tv...@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/4aeceac3
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/4aeceac3
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/4aeceac3

Branch: refs/heads/master
Commit: 4aeceac3483f90ab06b31e25188d1fc99a150493
Parents: 6a47d3d
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Tue Dec 10 02:06:31 2013 +0000
Committer: Cory Johns <ad...@users.sf.net>
Committed: Thu Dec 12 17:55:08 2013 +0000

----------------------------------------------------------------------
 Allura/allura/config/resources.py | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/4aeceac3/Allura/allura/config/resources.py
----------------------------------------------------------------------
diff --git a/Allura/allura/config/resources.py b/Allura/allura/config/resources.py
index 6e231e4..1f1ce53 100644
--- a/Allura/allura/config/resources.py
+++ b/Allura/allura/config/resources.py
@@ -20,6 +20,7 @@ import logging
 
 import pkg_resources
 
+from allura.app import Application
 from allura.lib.helpers import iter_entry_points
 
 log = logging.getLogger(__name__)
@@ -33,11 +34,22 @@ def register_ew_resources(manager):
         'allura', pkg_resources.resource_filename('allura', 'public/nf'))
     for ep in iter_entry_points('allura'):
         try:
+            # Allow derived tools to "inherit" static resources from a parent.
+            module_name = ep.module_name
+            resource_path = os.path.join('nf', ep.name.lower())
+            if not pkg_resources.resource_exists(module_name, resource_path):
+                for cls in [c for c in ep.load().__mro__[1:]
+                        if issubclass(c, Application)]:
+                    module_name = cls.__module__
+                    if pkg_resources.resource_exists(module_name, resource_path):
+                        break
+                else:
+                    continue
+
             manager.register_directory(
                 'tool/%s' % ep.name.lower(),
                 pkg_resources.resource_filename(
-                    ep.module_name,
-                    os.path.join('nf', ep.name.lower())))
+                    module_name, resource_path))
         except ImportError:
             log.warning('Cannot import entry point %s', ep)
             raise


[2/4] git commit: [#6830] New entry point handling for allura tools

Posted by jo...@apache.org.
[#6830] New entry point handling for allura tools

New logic allows multiple EPs with the same name in the [allura] (tools)
section, as long as one of the EPs is a subclass of the other(s), in
which case the subclass will be the EP that is used, and the others with
the same name ignored.

Signed-off-by: Tim Van Steenburgh <tv...@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/26209f4c
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/26209f4c
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/26209f4c

Branch: refs/heads/master
Commit: 26209f4ca9d992bef3ab202c95752851a8e6bc41
Parents: 3dc1bd6
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Mon Dec 9 22:03:43 2013 +0000
Committer: Cory Johns <ad...@users.sf.net>
Committed: Thu Dec 12 17:55:08 2013 +0000

----------------------------------------------------------------------
 Allura/allura/lib/helpers.py        | 44 +++++++++++++++++++++++++++-----
 Allura/allura/tests/test_helpers.py | 44 ++++++++++++++++++++++++++++++++
 2 files changed, 81 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/26209f4c/Allura/allura/lib/helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/lib/helpers.py b/Allura/allura/lib/helpers.py
index a987a3e..0b4e2dc 100644
--- a/Allura/allura/lib/helpers.py
+++ b/Allura/allura/lib/helpers.py
@@ -1000,13 +1000,43 @@ def plain2markdown(text, preserve_multiple_spaces=False, has_html_entities=False
 
 
 def iter_entry_points(group, *a, **kw):
-    '''
-    yield entry points that have not been disabled in the config
-    '''
-    disabled = aslist(tg.config.get('disable_entry_points.' + group), sep=',')
-    for ep in pkg_resources.iter_entry_points(group, *a, **kw):
-        if ep.name not in disabled:
-            yield ep
+    """Yields entry points that have not been disabled in the config.
+
+    If ``group`` is "allura" (Allura tool entry points), this function also
+    checks for multiple entry points with the same name. If there are
+    multiple entry points with the same name, and one of them is a subclass
+    of the other(s), it will be yielded, and the other entry points with that
+    name will be ignored. If a subclass is not found, an ImportError will be
+    raised.
+
+    This treatment of "allura" entry points allows tool authors to subclass
+    another tool while reusing the original entry point name.
+
+    """
+    def active_eps():
+        disabled = aslist(tg.config.get('disable_entry_points.' + group), sep=',')
+        return [ep for ep in pkg_resources.iter_entry_points(group, *a, **kw)
+                if ep.name not in disabled]
+    def unique_eps(entry_points):
+        by_name = defaultdict(list)
+        for ep in entry_points:
+            by_name[ep.name].append(ep)
+        for name, eps in by_name.iteritems():
+            ep_count = len(eps)
+            if ep_count == 1:
+                yield eps[0]
+            else:
+                yield subclass(eps)
+    def subclass(entry_points):
+        loaded = dict((ep, ep.load()) for ep in entry_points)
+        for ep, cls in loaded.iteritems():
+            others = loaded.values()[:]
+            others.remove(cls)
+            if all([issubclass(cls, other) for other in others]):
+                return ep
+        raise ImportError('Ambiguous [allura] entry points detected. ' +
+                'Multiple entry points with name "%s".' % entry_points[0].name)
+    return iter(unique_eps(active_eps()) if group == 'allura' else active_eps())
 
 
 # http://stackoverflow.com/a/1060330/79697

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/26209f4c/Allura/allura/tests/test_helpers.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/test_helpers.py b/Allura/allura/tests/test_helpers.py
index bdd3cea..e00231f 100644
--- a/Allura/allura/tests/test_helpers.py
+++ b/Allura/allura/tests/test_helpers.py
@@ -22,6 +22,7 @@ from os import path
 from datetime import datetime
 
 from mock import Mock, patch
+import tg
 from pylons import tmpl_context as c
 from nose.tools import eq_, assert_equals
 from IPython.testing.decorators import skipif, module_not_available
@@ -444,3 +445,46 @@ def test_login_overlay():
     with td.raises(HTTPUnauthorized):
         with h.login_overlay(exceptions=['foobar']):
             raise HTTPUnauthorized()
+
+class TestIterEntryPoints(TestCase):
+    def _make_ep(self, name, cls):
+        m = Mock()
+        m.name = name
+        m.load.return_value = cls
+        return m
+
+    @patch('allura.lib.helpers.pkg_resources')
+    @patch.dict(h.tg.config, {'disable_entry_points.allura': 'myapp'})
+    def test_disabled(self, pkg_resources):
+        pkg_resources.iter_entry_points.return_value = [
+                self._make_ep('myapp', object)]
+        self.assertEqual([], list(h.iter_entry_points('allura')))
+
+    @patch('allura.lib.helpers.pkg_resources')
+    def test_subclassed_ep(self, pkg_resources):
+        class App(object): pass
+        class BetterApp(App): pass
+
+        pkg_resources.iter_entry_points.return_value = [
+                self._make_ep('myapp', App),
+                self._make_ep('myapp', BetterApp)]
+
+        eps = list(h.iter_entry_points('allura'))
+        self.assertEqual(len(eps), 1)
+        self.assertEqual(BetterApp, eps[0].load())
+
+    @patch('allura.lib.helpers.pkg_resources')
+    def test_ambiguous_eps(self, pkg_resources):
+        class App(object): pass
+        class BetterApp(App): pass
+        class BestApp(object): pass
+
+        pkg_resources.iter_entry_points.return_value = [
+                self._make_ep('myapp', App),
+                self._make_ep('myapp', BetterApp),
+                self._make_ep('myapp', BestApp)]
+
+        self.assertRaisesRegexp(ImportError,
+                'Ambiguous \[allura\] entry points detected. '
+                'Multiple entry points with name "myapp".',
+                list, h.iter_entry_points('allura'))


[4/4] git commit: [#6830] Don't make Activity app hidden by default

Posted by jo...@apache.org.
[#6830] Don't make Activity app hidden by default

Signed-off-by: Tim Van Steenburgh <tv...@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/3dc1bd61
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/3dc1bd61
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/3dc1bd61

Branch: refs/heads/master
Commit: 3dc1bd61b2dc38481e85b8a6ead5abfedd02c4e1
Parents: 1eea58c
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Mon Dec 9 14:28:28 2013 +0000
Committer: Cory Johns <ad...@users.sf.net>
Committed: Thu Dec 12 17:55:08 2013 +0000

----------------------------------------------------------------------
 ForgeActivity/forgeactivity/main.py | 8 --------
 1 file changed, 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/3dc1bd61/ForgeActivity/forgeactivity/main.py
----------------------------------------------------------------------
diff --git a/ForgeActivity/forgeactivity/main.py b/ForgeActivity/forgeactivity/main.py
index c1cc686..87c7557 100644
--- a/ForgeActivity/forgeactivity/main.py
+++ b/ForgeActivity/forgeactivity/main.py
@@ -43,20 +43,12 @@ class ForgeActivityApp(Application):
     default_mount_point = 'activity'
     installable = False
     searchable = False
-    hidden = True
-    sitemap=[]
 
     def __init__(self, project, config):
         Application.__init__(self, project, config)
         self.root = ForgeActivityController(self)
         self.api_root = ForgeActivityRestController(self)
 
-    def main_menu(self): # pragma no cover
-        return []
-
-    def sidebar_menu(self): # pragma no cover
-        return []
-
     def admin_menu(self): # pragma no cover
         return []
 


[3/4] git commit: [#6830] Remove project root redirect to activity app

Posted by jo...@apache.org.
[#6830] Remove project root redirect to activity app

Signed-off-by: Tim Van Steenburgh <tv...@gmail.com>


Project: http://git-wip-us.apache.org/repos/asf/incubator-allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-allura/commit/6a47d3d9
Tree: http://git-wip-us.apache.org/repos/asf/incubator-allura/tree/6a47d3d9
Diff: http://git-wip-us.apache.org/repos/asf/incubator-allura/diff/6a47d3d9

Branch: refs/heads/master
Commit: 6a47d3d9602cf37c9bcc39a13225841529e9667a
Parents: 26209f4
Author: Tim Van Steenburgh <tv...@gmail.com>
Authored: Mon Dec 9 22:22:55 2013 +0000
Committer: Cory Johns <ad...@users.sf.net>
Committed: Thu Dec 12 17:55:08 2013 +0000

----------------------------------------------------------------------
 Allura/allura/controllers/project.py        |  4 +---
 Allura/allura/tests/functional/test_root.py | 17 -----------------
 2 files changed, 1 insertion(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6a47d3d9/Allura/allura/controllers/project.py
----------------------------------------------------------------------
diff --git a/Allura/allura/controllers/project.py b/Allura/allura/controllers/project.py
index ebaeaa3..b0e5b8b 100644
--- a/Allura/allura/controllers/project.py
+++ b/Allura/allura/controllers/project.py
@@ -370,9 +370,7 @@ class ProjectController(FeedController):
         activity_enabled = config.get('activitystream.enabled', False)
         activity_enabled = request.cookies.get('activitystream.enabled', activity_enabled)
         activity_enabled = asbool(activity_enabled)
-        if activity_enabled and c.project.app_instance('activity'):
-            redirect('activity/')
-        elif mount is not None:
+        if mount is not None:
             if 'ac' in mount:
                 redirect(mount['ac'].options.mount_point + '/')
             elif 'sub' in mount:

http://git-wip-us.apache.org/repos/asf/incubator-allura/blob/6a47d3d9/Allura/allura/tests/functional/test_root.py
----------------------------------------------------------------------
diff --git a/Allura/allura/tests/functional/test_root.py b/Allura/allura/tests/functional/test_root.py
index aa77873..918377f 100644
--- a/Allura/allura/tests/functional/test_root.py
+++ b/Allura/allura/tests/functional/test_root.py
@@ -94,23 +94,6 @@ class TestRootController(TestController):
         assert len(response.html.findAll('a',{'href':'/adobe/adobe-1/'})) == 0
         assert len(response.html.findAll('a',{'href':'/adobe/adobe-2/'})) == 0
 
-    def test_project_redirect(self):
-        with push_config(config, **{'activitystream.enabled': 'false'}):
-            resp = self.app.get('/p/test2/')
-            assert_equal(resp.status_int, 302)
-            assert_equal(resp.location, 'http://localhost/p/test2/admin/')
-
-        with push_config(config, **{'activitystream.enabled': 'true'}):
-            resp = self.app.get('/p/test2/')
-            assert_equal(resp.status_int, 302)
-            assert_equal(resp.location, 'http://localhost/p/test2/activity/')
-
-        with push_config(config, **{'activitystream.enabled': 'false'}):
-            self.app.cookies['activitystream.enabled'] = 'true'
-            resp = self.app.get('/p/test2/')
-            assert_equal(resp.status_int, 302)
-            assert_equal(resp.location, 'http://localhost/p/test2/activity/')
-
     def test_neighborhood_home(self):
         # Install home app
         nb = M.Neighborhood.query.get(name='Adobe')