7
7
from textwrap import dedent
8
8
from urllib .parse import urlparse
9
9
10
+ from jupyter_core .application import JupyterApp
10
11
from jupyterhub .services .auth import HubOAuthCallbackHandler
11
12
from jupyterhub .utils import make_ssl_context
12
13
from tornado import httpclient , httpserver , ioloop , web
13
14
from tornado .web import RedirectHandler
14
- from traitlets .config import Application as TraitletsApplication
15
15
from traitlets .traitlets import Bool , Int , Unicode , default , validate
16
16
17
17
from ..config import ServerProcess
18
18
from .activity import start_activity_update
19
19
from .proxy import make_standalone_proxy
20
20
21
21
22
- class StandaloneProxyServer (TraitletsApplication , ServerProcess ):
22
+ class StandaloneProxyServer (JupyterApp , ServerProcess ):
23
23
name = "jupyter-standalone-proxy"
24
24
description = """
25
25
Wrap an arbitrary web service so it can be used in place of 'jupyterhub-singleuser'
26
26
in a JupyterHub setting.
27
27
28
28
Usage: jupyter standaloneproxy [options] -- <command>
29
29
30
- The <command> will be executed to start the web service once the proxy receives the first request. The command can
31
- contain the placeholders '{{port}}', '{{unix_socket}}' and '{{base_url}}', which will be replaced with the
32
- appropriate values once the application starts.
33
-
34
30
For more details, see the jupyter-server-proxy documentation.
35
31
"""
32
+ examples = "jupyter standaloneproxy -- voila --port={port} --no-browser /path/to/notebook.ipynb"
36
33
37
34
base_url = Unicode (
38
35
help = """
@@ -152,19 +149,21 @@ def __init__(self, **kwargs):
152
149
# exeptions we do not need, for easier use of the CLI
153
150
# We don't need "command" here, as we will take it from the extra_args
154
151
ignore_traits = [
152
+ "name" ,
155
153
"launcher_entry" ,
156
154
"new_browser_tab" ,
157
155
"rewrite_response" ,
158
156
"update_last_activity" ,
159
157
"command" ,
160
158
]
161
159
server_process_aliases = {
162
- trait : f"ServerProcess .{ trait } "
160
+ trait : f"StandaloneProxyServer .{ trait } "
163
161
for trait in ServerProcess .class_traits (config = True )
164
162
if trait not in ignore_traits and trait not in self .flags
165
163
}
166
164
167
165
self .aliases = {
166
+ ** super ().aliases ,
168
167
** server_process_aliases ,
169
168
"base_url" : "StandaloneProxyServer.base_url" ,
170
169
"address" : "StandaloneProxyServer.address" ,
@@ -174,6 +173,17 @@ def __init__(self, **kwargs):
174
173
"websocket_max_message_size" : "StandaloneProxyServer.websocket_max_message_size" ,
175
174
}
176
175
176
+ def emit_alias_help (self ):
177
+ yield from super ().emit_alias_help ()
178
+ yield ""
179
+
180
+ # Manually yield the help for command, which we will get from extra_args
181
+ command_help = StandaloneProxyServer .class_get_trait_help (
182
+ ServerProcess .command
183
+ ).split ("\n " )
184
+ yield command_help [0 ].replace ("--StandaloneProxyServer.command" , "command" )
185
+ yield from command_help [1 :]
186
+
177
187
def get_proxy_base_class (self ) -> tuple [type | None , dict ]:
178
188
cls , kwargs = super ().get_proxy_base_class ()
179
189
if cls is None :
0 commit comments