Skip to content

Commit 2999deb

Browse files
committed
Fix missing import statement in test and expand README to talk about new feature somewhat
1 parent 28ff6f9 commit 2999deb

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

README.md

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,9 +193,13 @@ publishing, and we'd love to hear from you.
193193

194194
#### Config file
195195

196-
Newer versions of NBViewer will be configurable using a config file, `nbviewer_config.py`. In the directory where you run the command `python -m nbviewer` to start NBViewer, also add a file `nbviewer_config.py` which uses [the standard configuration syntax for Jupyter projects](https://traitlets.readthedocs.io/en/stable/config.html).
196+
NBViewer is configurable using a config file, by default called `nbviewer_config.py`. You can modify the name and location of the config file that NBViewer looks for using the `--config-file` command line flag. (The location is always a relative path, i.e. relative to where the command `python -m nbviewer` is run, and never an absolute path.)
197197

198-
For example, to configure the value of a configurable `foo`, add the line `c.NBViewer.foo = 'bar'` to the `nbviewer_config.py` file located where you run `python -m nbviewer`. Again, currently very few features of NBViewer are configurable this way, but we hope to steadily increase the number of configurable characteristics of NBViewer in future releases.
198+
If you don't know which attributes of NBViewer you can configure using the config file, run `python -m nbviewer --generate-config` (or `python -m nbviewer --generate-config --config-file="my_custom_name.py"`) to write a default config file which has all of the configurable options commented out and set to their default values. To change a configurable option to a new value, uncomment the corresponding line and change the default value to the new value.
199+
200+
The config file uses [the standard configuration syntax for Jupyter projects](https://traitlets.readthedocs.io/en/stable/config.html).
201+
202+
One thing this allows you to do, for example, is to write your custom implementations of any of the standard page rendering [handlers](https://www.tornadoweb.org/en/stable/guide/structure.html#subclassing-requesthandler) included in NBViewer, e.g. by subclassing the original handlers to include custom logic along with custom output possibilities, and then have these custom handlers always loaded by default, by modifying the corresponding lines in the config file. This is effectively another way to extend NBViewer.
199203

200204
## Securing the Notebook Viewer
201205

nbviewer/app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def init_tornado_application(self):
334334
self.tornado_application = web.Application(handlers, debug=options.debug, **settings)
335335

336336
# Mostly copied from JupyterHub because if it isn't broken then don't fix it
337-
def write_config(self):
337+
def write_config_file(self):
338338
"""Write our default config to a .py config file"""
339339
config_file_dir = os.path.dirname(os.path.abspath(options.config_file))
340340
if not os.path.isdir(config_file_dir):

nbviewer/tests/test_app.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import sys
33

44
from tempfile import NamedTemporaryFile
5+
from subprocess import PIPE
56
from subprocess import Popen
67

78
# Also copied mostly from JupyterHub since again -- if not broken, don't fix.
@@ -34,5 +35,6 @@ def test_generate_config():
3435
cfg_text = f.read()
3536
os.remove(cfg_file)
3637
assert cfg_file in out
37-
assert 'NBViewer.name' in cfg_text
38+
assert 'NBViewer.name' not in cfg_text # This shouldn't be configurable
39+
assert 'NBViewer.local_handler' in cfg_text
3840
assert 'NBViewer.static_path' in cfg_text

0 commit comments

Comments
 (0)