File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -306,6 +306,12 @@ def wrapped(*args, **kwargs):
306306
307307 @classmethod
308308 def register_plugin_entry_point (cls , entry_point , modifier = identity ):
309+ if hasattr (cls , entry_point .name ):
310+ raise ValueError (
311+ f"Can't add { entry_point .name } from { entry_point .module_name } "
312+ f"to { cls .__name__ } : duplicate method name."
313+ )
314+
309315 def stub (* args , ** kwargs ):
310316 """ Entrypoints-based streamz plugin. Will be loaded on first call. """
311317 node = entry_point .load ()
Original file line number Diff line number Diff line change 1+ import warnings
2+
13import pkg_resources
24
35
6+ def try_register (cls , entry_point , * modifier ):
7+ try :
8+ cls .register_plugin_entry_point (entry_point , * modifier )
9+ except ValueError :
10+ warnings .warn (
11+ f"Can't add { entry_point .name } from { entry_point .module_name } : "
12+ "name collision with existing stream node."
13+ )
14+
15+
416def load_plugins (cls ):
517 for entry_point in pkg_resources .iter_entry_points ("streamz.sources" ):
6- cls . register_plugin_entry_point ( entry_point , staticmethod )
18+ try_register ( cls , entry_point , staticmethod )
719 for entry_point in pkg_resources .iter_entry_points ("streamz.nodes" ):
8- cls . register_plugin_entry_point ( entry_point )
20+ try_register ( cls , entry_point )
921 for entry_point in pkg_resources .iter_entry_points ("streamz.sinks" ):
10- cls . register_plugin_entry_point ( entry_point )
22+ try_register ( cls , entry_point )
Original file line number Diff line number Diff line change @@ -41,7 +41,7 @@ class test_source(Source):
4141 assert inspect .isfunction (Stream ().from_test )
4242
4343
44- def test_register_plugin_entry_point_raises ():
44+ def test_register_plugin_entry_point_raises_type ():
4545 class invalid_node :
4646 pass
4747
@@ -51,3 +51,10 @@ class invalid_node:
5151
5252 with pytest .raises (TypeError ):
5353 Stream .test ()
54+
55+
56+ def test_register_plugin_entry_point_raises_duplicate_name ():
57+ entry_point = MockEntryPoint ("map" , None )
58+
59+ with pytest .raises (ValueError ):
60+ Stream .register_plugin_entry_point (entry_point )
You can’t perform that action at this time.
0 commit comments