|
1 | | -from .version import __version__ # noqa |
2 | | -from .pull import GitPuller # noqa |
3 | | -from jupyter_server.utils import url_path_join |
4 | | -from tornado.web import StaticFileHandler |
5 | | -import os |
| 1 | +from .application import NbGitPuller |
6 | 2 |
|
7 | 3 |
|
8 | 4 | def _jupyter_server_extension_points(): |
9 | | - """ |
10 | | - This function is detected by `notebook` and `jupyter_server` because they |
11 | | - are explicitly configured to inspect the nbgitpuller module for it. That |
12 | | - explicit configuration is passed via setup.py's declared data_files. |
13 | | -
|
14 | | - Returns a list of dictionaries with metadata describing where to find the |
15 | | - `_load_jupyter_server_extension` function. |
16 | | - """ |
17 | 5 | return [{ |
18 | 6 | 'module': 'nbgitpuller', |
| 7 | + 'app': NbGitPuller |
19 | 8 | }] |
20 | | - |
21 | | - |
22 | | -def _load_jupyter_server_extension(app): |
23 | | - """ |
24 | | - This function is a hook for `notebook` and `jupyter_server` that we use to |
25 | | - register additional endpoints to be handled by nbgitpuller. |
26 | | -
|
27 | | - Note that as this function is used as a hook for both notebook and |
28 | | - jupyter_server, the argument passed may be a NotebookApp or a ServerApp. |
29 | | -
|
30 | | - Related documentation: |
31 | | - - notebook: https://jupyter-notebook.readthedocs.io/en/stable/extending/handlers.htmland |
32 | | - - notebook: https://jupyter-notebook.readthedocs.io/en/stable/examples/Notebook/Distributing%20Jupyter%20Extensions%20as%20Python%20Packages.html#Example---Server-extension |
33 | | - - jupyter_server: https://jupyter-server.readthedocs.io/en/latest/developers/extensions.html |
34 | | - """ |
35 | | - # identify base handler by app class |
36 | | - # must do this before importing from .handlers |
37 | | - from ._compat import get_base_handler |
38 | | - |
39 | | - get_base_handler(app) |
40 | | - |
41 | | - from .handlers import ( |
42 | | - SyncHandler, |
43 | | - UIHandler, |
44 | | - LegacyInteractRedirectHandler, |
45 | | - LegacyGitSyncRedirectHandler, |
46 | | - ) |
47 | | - |
48 | | - web_app = app.web_app |
49 | | - base_url = url_path_join(web_app.settings['base_url'], 'git-pull') |
50 | | - handlers = [ |
51 | | - (url_path_join(base_url, 'api'), SyncHandler), |
52 | | - (base_url, UIHandler), |
53 | | - (url_path_join(web_app.settings['base_url'], 'git-sync'), LegacyGitSyncRedirectHandler), |
54 | | - (url_path_join(web_app.settings['base_url'], 'interact'), LegacyInteractRedirectHandler), |
55 | | - ( |
56 | | - url_path_join(base_url, 'static', '(.*)'), |
57 | | - StaticFileHandler, |
58 | | - {'path': os.path.join(os.path.dirname(__file__), 'static')} |
59 | | - ) |
60 | | - ] |
61 | | - # FIXME: See note on how to stop relying on settings to pass information: |
62 | | - # https://github.com/jupyterhub/nbgitpuller/pull/242#pullrequestreview-854968180 |
63 | | - # |
64 | | - web_app.settings['nbapp'] = app |
65 | | - web_app.add_handlers('.*', handlers) |
66 | | - |
67 | | - |
68 | | -# For compatibility with both notebook and jupyter_server, we define |
69 | | -# _jupyter_server_extension_paths alongside _jupyter_server_extension_points. |
70 | | -# |
71 | | -# "..._paths" is used by notebook and still supported by jupyter_server as of |
72 | | -# jupyter_server 1.13.3, but was renamed to "..._points" in jupyter_server |
73 | | -# 1.0.0. |
74 | | -# |
75 | | -_jupyter_server_extension_paths = _jupyter_server_extension_points |
76 | | - |
77 | | -# For compatibility with both notebook and jupyter_server, we define both |
78 | | -# load_jupyter_server_extension alongside _load_jupyter_server_extension. |
79 | | -# |
80 | | -# "load..." is used by notebook and "_load..." is used by jupyter_server. |
81 | | -# |
82 | | -load_jupyter_server_extension = _load_jupyter_server_extension |
0 commit comments