Skip to content

Commit 0ddbaf1

Browse files
committed
Merge branch 'master' into ghe-gist-patch
# Conflicts: # nbviewer/providers/gist/handlers.py
2 parents 2237803 + 8a8fd29 commit 0ddbaf1

File tree

6 files changed

+313
-159
lines changed

6 files changed

+313
-159
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $ docker run -p 8080:8080 -e 'GITHUB_OAUTH_KEY=YOURKEY' \
2525
jupyter/nbviewer
2626
```
2727

28-
Or to use your GitHub personal access token, you can set just `GITHUB_API_TOKEN`.
28+
Or to use your GitHub personal access token, you can just set `GITHUB_API_TOKEN`.
2929

3030

3131
## GitHub Enterprise
@@ -70,7 +70,7 @@ $ docker run -p 8080:8080 nbviewer
7070
The Notebook Viewer uses `memcached` in production. To locally try out this
7171
setup, a [docker-compose](https://docs.docker.com/compose/) configuration is
7272
provided to easily start/stop the `nbviewer` and `memcached` containers
73-
together from a your current branch. You will need to install `docker` prior
73+
together from your current branch. You will need to install `docker` prior
7474
to this.
7575

7676
#### Run
@@ -145,7 +145,7 @@ Providers are sources of notebooks and directories of notebooks and directories.
145145
- `local`
146146

147147
#### Writing a new Provider
148-
There are several already additional providers
148+
There are already several providers
149149
[proposed/requested](https://github.com/jupyter/nbviewer/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+label%3Atag%3AProvider). Some providers are more involved than others, and some,
150150
such as those which would require user authentication, will take some work to
151151
support properly.
@@ -183,7 +183,7 @@ Formats are ways to present notebooks to the user.
183183
#### Writing a new Format
184184
If you'd like to write a new format, open a ticket, or speak up on [gitter][]!
185185
We have some work yet to do to support your next big thing in notebook
186-
publishing, and we'd love to here from you.
186+
publishing, and we'd love to hear from you.
187187

188188
#### Config file
189189

@@ -193,7 +193,7 @@ For example, to configure the value of a configurable `foo`, add the line `c.NBV
193193

194194
## Securing the Notebook Viewer
195195

196-
You can run the viewer as a [JupyterHub 0.7+ service](https://jupyterhub.readthedocs.io/en/latest/reference/services.html). Running the viewer as a service prevents users who have not authenticated with the Hub from acccessing the nbviewer instance. This setup can be useful for protecting access to local notebooks rendered with the `--localfiles` option.
196+
You can run the viewer as a [JupyterHub 0.7+ service](https://jupyterhub.readthedocs.io/en/latest/reference/services.html). Running the viewer as a service prevents users who have not authenticated with the Hub from accessing the nbviewer instance. This setup can be useful for protecting access to local notebooks rendered with the `--localfiles` option.
197197

198198
Add an entry like the following to your `jupyterhub_config.py` to have it start nbviewer as a managed service:
199199

nbviewer/providers/base.py

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ class BaseHandler(web.RequestHandler):
5757
"""Base Handler class with common utilities"""
5858

5959
def initialize(self, format=None, format_prefix="", **handler_settings):
60+
# format: str, optional
61+
# Rendering format (e.g. script, slides, html)
6062
self.format = format or self.default_format
6163
self.format_prefix = format_prefix
6264
self.http_client = httpclient.AsyncHTTPClient()
@@ -214,7 +216,6 @@ def statsd(self):
214216
if hasattr(self, '_statsd'):
215217
return self._statsd
216218
if self.settings['statsd_host']:
217-
print(self.settings)
218219
self._statsd = statsd.StatsClient(
219220
self.settings['statsd_host'],
220221
self.settings['statsd_port'],
@@ -263,13 +264,13 @@ def render_template(self, name, **namespace):
263264
namespace.update(self.template_namespace)
264265
template = self.get_template(name)
265266
return template.render(**namespace)
266-
267+
267268
# Wrappers to facilitate custom rendering in subclasses without having to rewrite entire GET methods
268269
# This would seem to mostly involve creating different template namespaces to enable custom logic in
269270
# extended templates, but there might be other possibilities
270271
def render_status_code_template(self, status_code, **namespace):
271272
return self.render_template('%d.html' % status_code, **namespace)
272-
273+
273274
def render_error_template(self, **namespace):
274275
return self.render_template('error.html', **namespace)
275276

@@ -630,6 +631,31 @@ def filter_formats(self, nb, raw):
630631
except Exception as err:
631632
app_log.info("failed to test %s: %s", self.request.uri, name)
632633

634+
# empty methods to be implemented by subclasses to make GET requests more modular
635+
def get_notebook_data(self, **kwargs):
636+
"""
637+
Pass as kwargs variables needed to define those variables which will be necessary for
638+
the provider to find the notebook. (E.g. path for LocalHandler, user and repo for GitHub.)
639+
Return variables the provider needs to find and load the notebook. Then run custom logic
640+
in GET or pass the output of get_notebook_data immediately to deliver_notebook.
641+
642+
First part of any provider's GET method.
643+
644+
Custom logic, if applicable, is middle part of any provider's GET method, and usually
645+
is implemented or overwritten in subclasses, while get_notebook_data and deliver_notebook
646+
will often remain unchanged from the parent class (e.g. for a custom GitHub provider).
647+
"""
648+
pass
649+
650+
def deliver_notebook(self, **kwargs):
651+
"""
652+
Pass as kwargs the return values of get_notebook_data to this method. Get the JSON data
653+
from the provider to render the notebook. Finish with a call to self.finish_notebook.
654+
655+
Last part of any provider's GET method.
656+
"""
657+
pass
658+
633659
# Wrappers to facilitate custom rendering in subclasses without having to rewrite entire GET methods
634660
# This would seem to mostly involve creating different template namespaces to enable custom logic in
635661
# extended templates, but there might be other possibilities
@@ -658,30 +684,10 @@ def finish_notebook(self, json_notebook, download_url, msg=None,
658684
Notebook document in JSON format
659685
download_url: str
660686
URL to download the notebook document
661-
provider_url: str, optional
662-
URL to the notebook document upstream at the provider (e.g., GitHub)
663-
provider_icon: str, optional
664-
CSS classname to apply to the navbar icon linking to the provider
665-
provider_label: str, optional
666-
Text to to apply to the navbar icon linking to the provider
667687
msg: str, optional
668688
Extra information to log when rendering fails
669-
breadcrumbs: list of dict, optional
670-
Breadcrumb 'name' and 'url' to render as links at the top of the notebook page
671689
public: bool, optional
672690
True if the notebook is public and its access indexed, False if not
673-
format: str, optional
674-
Rendering format (e.g., script, slides, html)
675-
request: tornado.httputil.HTTPServerRequest, optional
676-
HTTP request that triggered notebook rendering
677-
title: str, optional
678-
Title to use as the HTML page title (i.e., text on the browser tab)
679-
executor_url: str, optional
680-
URL to execute the notebook document (e.g., Binder)
681-
executor_label: str, optional
682-
Text to apply to the navbar icon linking to the execution service
683-
executor_icon: str, optional
684-
CSS classname to apply to the navbar icon linking to the execution service
685691
"""
686692

687693
if msg is None:

0 commit comments

Comments
 (0)