Skip to content

Commit d49e41c

Browse files
committed
Add those traitlets as attributes which require uncomplicated default values
1 parent 094a55e commit d49e41c

File tree

1 file changed

+74
-5
lines changed

1 file changed

+74
-5
lines changed

nbviewer/app.py

Lines changed: 74 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def nrfoot():
7777

7878
class NBViewer(Application):
7979

80-
name = Unicode('nbviewer')
80+
name = Unicode('NBViewer')
8181

8282
aliases = Dict({
8383
'base-url' : 'NBViewer.base_url',
@@ -166,13 +166,34 @@ class NBViewer(Application):
166166
url_handler = Unicode(default_value="nbviewer.providers.url.handlers.URLHandler", help="The Tornado handler to use for viewing notebooks accessed via URL").tag(config=True)
167167
user_gists_handler = Unicode(default_value="nbviewer.providers.gist.handlers.UserGistsHandler", help="The Tornado handler to use for viewing directory containing all of a user's Gists").tag(config=True)
168168

169+
answer_yes = Bool(default_value=False, help="Answer yes to any questions (e.g. confirm overwrite).").tag(config=True)
170+
171+
# base_url specified by the user
172+
base_url = Unicode(default_value="/", help='URL base for the server').tag(config=True)
173+
174+
binder_base_url = Unicode(default_value="https://mybinder.org/v2", help="URL base for binder notebook execution service.").tag(config=True)
175+
176+
cache_expiry_max = Int(default_value=2*60*60, help="Maximum cache expiry (seconds).").tag(config=True)
177+
178+
cache_expiry_min = Int(default_value=10*60, help="Minimum cache expiry (seconds).").tag(config=True)
179+
169180
client = Any().tag(config=True)
170181
@default('client')
171182
def _default_client(self):
172183
client = HTTPClientClass(log=self.log)
173184
client.cache = self.cache
174185
return client
175186

187+
config_file = Unicode(default_value='nbviewer_config.py', help="The config file to load.").tag(config=True)
188+
189+
content_security_policy = Unicode(default_value="connect-src 'none';", help="Content-Security-Policy header setting.").tag(config=True)
190+
191+
default_format = Unicode(default_value="html", help="Format to use for legacy / URLs.").tag(config=True)
192+
193+
frontpage = Unicode(default_value=FRONTPAGE_JSON, help="Path to json file containing frontpage content.").tag(config=True)
194+
195+
generate_config = Bool(default_value=False, help="Generate default config file.").tag(config=True)
196+
176197
index = Any().tag(config=True)
177198
@default('index')
178199
def _load_index(self):
@@ -186,6 +207,20 @@ def _load_index(self):
186207
indexer = NoSearch()
187208
return indexer
188209

210+
ipywidgets_base_url = Unicode(default_value="https://unpkg.com/", help="URL base for ipywidgets JS package.").tag(config=True)
211+
212+
jupyter_js_widgets_version = Unicode(default_value="*", help="Version specifier for jupyter-js-widgets JS package.").tag(config=True)
213+
214+
jupyter_widgets_html_manager_version = Unicode(default_value="*", help="Version specifier for @jupyter-widgets/html-manager JS package.").tag(config=True)
215+
216+
localfile_any_user = Bool(default_value=False, help="Also serve files that are not readable by 'Other' on the local file system.").tag(config=True)
217+
218+
localfile_follow_symlinks = Bool(default_value=False, help="Resolve/follow symbolic links to their target file using realpath.").tag(config=True)
219+
220+
localfiles = Unicode(default_value="", help="Allow to serve local files under /localfile/* this can be a security risk.").tag(config=True)
221+
222+
mathjax_url = Unicode(default_value="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/", help="URL base for mathjax package.").tag(config=True)
223+
189224
# cache frontpage links for the maximum allowed time
190225
max_cache_uris = Set().tag(config=True)
191226
@default('max_cache_uris')
@@ -196,7 +231,31 @@ def _load_max_cache_uris(self):
196231
max_cache_uris.add('/' + link['target'])
197232
return max_cache_uris
198233

199-
processes = Int(default_value=0, help="use processes instead of threads for rendering").tag(config=True)
234+
mc_threads = Int(default_value=1, help="Number of threads to use for Async Memcache.").tag(config=True)
235+
236+
no_cache = Bool(default_value=False, help="Do not cache results.").tag(config=True)
237+
238+
no_check_certificate = Bool(default_value=False, help="Do not validate SSL certificates.").tag(config=True)
239+
240+
processes = Int(default_value=0, help="Use processes instead of threads for rendering.").tag(config=True)
241+
242+
provider_rewrites = List(trait=Unicode, default_value=default_rewrites, help="Full dotted package(s) that provide `uri_rewrites`.").tag(config=True)
243+
244+
providers = List(trait=Unicode, default_value=default_providers, help="Full dotted package(s) that provide `default_handlers`.").tag(config=True)
245+
246+
proxy_host = Unicode(default_value="", help="The proxy URL.").tag(config=True)
247+
248+
proxy_port = Int(default_value=-1, help="The proxy port.").tag(config=True)
249+
250+
rate_limit = Int(default_value=60, help="Number of requests to allow in rate_limit_interval before limiting. Only requests that trigger a new render are counted.").tag(config=True)
251+
252+
rate_limit_interval = Int(default_value=600, help="Interval (in seconds) for rate limiting.").tag(config=True)
253+
254+
render_timeout = Int(default_value=15, help="Time to wait for a render to complete before showing the 'Working...' page.").tag(config=True)
255+
256+
sslcert = Unicode(help="Path to ssl .crt file.").tag(config=True)
257+
258+
sslkey = Unicode(help="Path to ssl .key file.").tag(config=True)
200259

201260
static_path = Unicode(default_value=os.environ.get("NBVIEWER_STATIC_PATH", ""), help="Custom path for loading additional static files.").tag(config=True)
202261

@@ -208,6 +267,16 @@ def _load_static_url_prefix(self):
208267
# Last '/' ensures that NBViewer still works regardless of whether user chooses e.g. '/static2/' or '/static2' as their custom prefix
209268
return url_path_join(self._base_url, self.static_url_prefix, '/')
210269

270+
statsd_host = Unicode(default_value="", help="Host running statsd to send metrics to.").tag(config=True)
271+
272+
statsd_port = Int(default_value=8125, help="Port on which statsd is listening for metrics on statsd_host.").tag(config=True)
273+
274+
statsd_prefix = Unicode(default_value='nbviewer', help="Prefix to use for naming metrics sent to statsd.").tag(config=True)
275+
276+
template_path = Unicode(default_value=os.environ.get("NBVIEWER_TEMPLATE_PATH", ""), help="Custom template path for the nbviewer app (not rendered notebooks).").tag(config=True)
277+
278+
threads = Int(default_value=1, help="Number of threads to use for rendering.").tag(config=True)
279+
211280
# prefer the JupyterHub defined service prefix over the CLI
212281
@cached_property
213282
def _base_url(self):
@@ -466,7 +535,7 @@ def init_logging(self):
466535

467536
# This prevents double log messages because tornado use a root logger that
468537
# self.log is a child of. The logging module dispatches log messages to a log
469-
# and all of its ancestors until propagate is set to False
538+
# and all of its ancestors until propagate is set to False.
470539
self.log.propagate = False
471540

472541
tornado_log = logging.getLogger('tornado')
@@ -482,7 +551,7 @@ def init_logging(self):
482551
curl_log.setLevel(
483552
max(self.log_level, logging.INFO))
484553

485-
# Mostly copied from JupyterHub because if it isn't broken then don't fix it
554+
# Mostly copied from JupyterHub because if it isn't broken then don't fix it.
486555
def write_config_file(self):
487556
"""Write our default config to a .py config file"""
488557
config_file_dir = os.path.dirname(os.path.abspath(options.config_file))
@@ -521,7 +590,7 @@ def __init__(self, *args, **kwargs):
521590
if options.generate_config:
522591
self.write_config_file()
523592

524-
# Inherited method from traitlets.Application
593+
# Inherited method from traitlets.config.Application
525594
self.load_config_file(options.config_file)
526595
self.init_logging()
527596
self.init_tornado_application()

0 commit comments

Comments
 (0)