Skip to content

Commit 622ccba

Browse files
committed
docs: add docstrings to notebook/jupyter_server hooks
1 parent eca43f1 commit 622ccba

File tree

1 file changed

+35
-3
lines changed

1 file changed

+35
-3
lines changed

nbgitpuller/__init__.py

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,30 @@
66
import os
77

88

9-
def _jupyter_server_extension_paths():
9+
def _jupyter_server_extension_points():
10+
"""
11+
This function is detected by `notebook` and `jupyter_server` because they
12+
are explicitly configured to inspect the nbgitpuller module for it. That
13+
explicit configuration is passed via setup.py's declared data_files.
14+
15+
Returns a list of dictionaries with metadata describing where to find the
16+
`_load_jupyter_server_extension` function.
17+
"""
1018
return [{
1119
'module': 'nbgitpuller',
1220
}]
1321

1422

15-
def load_jupyter_server_extension(nbapp):
23+
def _load_jupyter_server_extension(nbapp):
24+
"""
25+
This function is a hook for `notebook` and `jupyter_server` that we use to
26+
register additional endpoints to be handled by nbgitpuller.
27+
28+
Related documentation:
29+
- notebook: https://jupyter-notebook.readthedocs.io/en/stable/extending/handlers.htmland
30+
- notebook: https://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/Distributing%20Jupyter%20Extensions%20as%20Python%20Packages.html#Example---Server-extension
31+
- jupyter_server: https://jupyter-server.readthedocs.io/en/latest/developers/extensions.html
32+
"""
1633
web_app = nbapp.web_app
1734
base_url = url_path_join(web_app.settings['base_url'], 'git-pull')
1835
handlers = [
@@ -29,4 +46,19 @@ def load_jupyter_server_extension(nbapp):
2946
web_app.settings['nbapp'] = nbapp
3047
web_app.add_handlers('.*', handlers)
3148

32-
_load_jupyter_server_extension = load_jupyter_server_extension
49+
50+
# For compatibility with both notebook and jupyter_server, we define
51+
# _jupyter_server_extension_paths alongside _jupyter_server_extension_points.
52+
#
53+
# "..._paths" is used by notebook and still supported by jupyter_server as of
54+
# jupyter_server 1.13.3, but was renamed to "..._points" in jupyter_server
55+
# 1.0.0.
56+
#
57+
_jupyter_server_extension_paths = _jupyter_server_extension_points
58+
59+
# For compatibility with both notebook and jupyter_server, we define both
60+
# load_jupyter_server_extension alongside _load_jupyter_server_extension.
61+
#
62+
# "load..." is used by notebook and "_load..." is used by jupyter_server.
63+
#
64+
load_jupyter_server_extension = _load_jupyter_server_extension

0 commit comments

Comments
 (0)