Skip to content

Commit 8f3e71a

Browse files
committed
Get app subcommands from pkg_resources entrypoints.
1 parent abfc3e1 commit 8f3e71a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Changes
1919
0.3.0
2020
-----
2121

22+
* Get `jupyter contrib` app subcommands from `pkg_resources` entrypoints
2223
* Add `_maybe_copy` and `_should_copy` to nbextensions private API, since the
2324
`logger` keyword arg was only added after notebook 4.1
2425

src/jupyter_contrib_core/application.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import sys
1111

12+
import pkg_resources
1213
from jupyter_core.application import JupyterApp
1314

1415
from 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

Comments
 (0)