File save hooks—docs & question
- Dominant language
- Jupyter Notebook
- Stars
- 13.3k
- Forks
- 5.8k
- Avg merge
- 6d 11h
- Merged PRs (30d)
- 7
Description
`notebook/docs/source/extending/savehooks.rst` gives an example of a post-save hook for exporting a script, one that I find very useful! Two issues and a question about this:
1. As far as I can tell, this is code from elsewhere in the code base that could be just imported, e.g. a user can set the hook in `jupyter_notebook_config.py` with:
``` python
from notebook.services.contents.filemanager import _post_save_script
c.FileContentsManager.post_save_hook = _post_save_script
```
2. The example in `savehooks.rst` is out of date—flake8 warns that `py_fname` is defined but not used.
3. In using this code, the `ScriptExporter` that's created seems to eventually create a `PythonExporter` (at least, for IPython notebooks). It seems not possible to configure this Exporter through the normal configuration mechanism. For instance adding any of the following lines to `jupyter_notebook_config.py` seems to have no effect:
``` python
c.Exporter.template_file = 'custom.tpl'
c.TemplateExporter.template_file = 'custom.tpl'
c.PythonExporter.template_file = 'custom.tpl'
```
Some of these appear in the [nbconvert docs](http://nbconvert.readthedocs.org/en/latest/config_options.html), but that is for `jupyter_nbconvert_config.py`, not loaded by the notebook. I've also tried hacking `_post_save_script` to pass or set the template_file or template_path options, and looked in vain for documentation about configuring custom exporters for `ScriptExporter`. (My ultimate goal here is to use a custom .tpl file for this export so that I can suppress prompt numbers.)
Contributor guide
Research direction
Start with notebook/docs/source/extending/savehooks.rst and compare its post-save example with notebook.services.contents.filemanager._post_save_script. Reproduce the flake8 warning and the exporter configuration attempts from jupyter_notebook_config.py, then document the supported behavior and update the example so the reported issues and custom-template goal are addressed.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- jupyter-notebook, python
- Domain
- backend, documentation
- Issue type
- Documentation
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100