99
1010import sys
1111
12+ import pkg_resources
1213from jupyter_core .application import JupyterApp
1314
1415from jupyter_contrib_core import __version__
@@ -22,6 +23,28 @@ class JupyterContribApp(JupyterApp):
2223 description = (
2324 'community-contributed spice for Jupyter Interactive Computing' )
2425
26+ def __init__ (self , * args , ** kwargs ):
27+ self ._refresh_subcommands ()
28+ super (JupyterContribApp , self ).__init__ (* args , ** kwargs )
29+
30+ def _refresh_subcommands (self ):
31+ """
32+ Finds subcommands which have registered entry points.
33+
34+ Each entry point is a function which returns a subcommands-style dict,
35+ where the keys are the name of the subcommand, and the values are
36+ 2-tuples containing the sub-application class, and a description of the
37+ subcommand's action.
38+ """
39+ group = 'jupyter_contrib_core.app.subcommands'
40+ new_subcommands = {}
41+ # import ipdb; ipdb.set_trace()
42+ for entrypoint in pkg_resources .iter_entry_points (group = group ):
43+ get_subcommands_dict = entrypoint .load ()
44+ new_subcommands .update (get_subcommands_dict ())
45+ self .subcommands .clear ()
46+ self .subcommands .update (new_subcommands )
47+
2548 def start (self ):
2649 """Perform the App's actions as configured"""
2750 super (JupyterContribApp , self ).start ()
0 commit comments