Commits

Petar Marić committed bfa87bf

Plugin mount points can now contribute custom data to their plugin info

Comments (0)

Files changed (2)

beam_integrals/utils.py

     
     @property
     def plugins(self):
-        if self._meta._base_class._plugins is None:
+        base_cls = self._meta._base_class
+        if base_cls._plugins is None:
             x = AttrDict()
             x.classes = set(self._plugin_registry)
             x.instances = set(cls() for cls in x.classes)
             x.class_to_id = dict((v, k) for k, v in x.id_to_class.items())
             x.instances_sorted_by_id = [v for _, v in sorted(x.id_to_instance.items())]
             x.valid_ids = set(x.id_to_instance)
-            self._meta._base_class._plugins = x
+            
+            if hasattr(base_cls, '_contribute_to_plugins'):
+                base_cls._contribute_to_plugins(_plugins=x)
+            
+            base_cls._plugins = x
         
-        return self._meta._base_class._plugins
+        return base_cls._plugins
     
     def coerce(self, value):
         """Coerce the passed value into the right instance"""

tests/test_utils.py

             __metaclass__ = PluginMount
             class Meta:
                 id_field = 'status_code'
+            @classmethod
+            def _contribute_to_plugins(cls, _plugins):
+                _plugins.contribute_to_plugins_works = True
         class OK(HttpResponse):
             status_code = 200
         class BaseRedirection(HttpResponse):
         # Compare the remaining plugin information directly
         assert_equal(actual_plugins, self.desired_http_method_plugins)
     
+    def test_contribute_to_plugins(self):
+        assert_is(self.HttpResponse.plugins.contribute_to_plugins_works, True)
+    
     def test_distant_relatives_use_same_plugin_info_cache(self):
         self.GET._plugins = None
         self.POST._plugins = None