-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Proposal: separate template and config
The existence of a notebook template is a very nice thing, since we can define common blocks of code that we always rely on... However the current implementation have a huge chunk right in the beginning of the file with all the boilerplate code (e.g. configuring jupyter extensions and the way things are displayed in the notebook). I wonder if using a single file to centralise all this "boilerplate jupyter configuration" makes sense... The idea is not to replace the template, but rather get unimportant things (like configuring how many columns pandas will display), out of the way. This way a person can have a single line on top of the file: ```ipynb %run ./config.ipynb ``` and start writing some text for good'old literal programming, and the readers will not be distracted by the usual chores... This approach also allow users to change things in one place (e.g. font size for the graphs) and have it automatically changing in all the notebooks, which can be quite neat.
- Loading branch information
1 parent
3ac6c33
commit a7488a2
Showing
3 changed files
with
160 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
142 changes: 142 additions & 0 deletions
142
src/pyscaffoldext/dsproject/templates/config_ipynb.template
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
{ | ||
"cells": [ | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"# General configuration for your notebooks\n", | ||
"\n", | ||
"This file is designed as a place to store configuration that you don't want to keep repeating all over in your notebook files,\n", | ||
"such as loading extensions or setting up matplotlib.\n", | ||
"\n", | ||
"To use it in your files just add the followin a magic comment:\n", | ||
"\n", | ||
"```ipynb\n", | ||
"%run ./config.ipynb\n", | ||
"```\n", | ||
"\n", | ||
"Although the `run` magic directive will make any variable defined in the `config.ipynb` (or module imported) also available in the notebook, please refrain yourself in using these capability...\n", | ||
"It is good to make things as explicit as possible and `config.ipynb` should only be used to configure things that usually stay behind the scenes anyway." | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Load Jupyter extensions" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%load_ext autoreload\n", | ||
"%autoreload 2" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Configure Python's logger" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import sys\n", | ||
"import logging\n", | ||
"logging.basicConfig(level=logging.INFO, stream=sys.stdout)" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Configure `matplotlib` to display nice plots inside the notebook itself" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"%matplotlib inline\n", | ||
"%config InlineBackend.figure_format = 'retina'" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"The `seaborn` library can be used to make `matplotlib` graphs look even nicer..." | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import seaborn\n", | ||
"seaborn.set_context(\"poster\")\n", | ||
"seaborn.set(rc={\"figure.figsize\": (16, 9.)})\n", | ||
"seaborn.set_style(\"whitegrid\")" | ||
] | ||
}, | ||
{ | ||
"cell_type": "markdown", | ||
"metadata": {}, | ||
"source": [ | ||
"### Configure `pandas` to display tables nicely" | ||
] | ||
}, | ||
{ | ||
"cell_type": "code", | ||
"execution_count": null, | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": [ | ||
"import pandas\n", | ||
"pandas.set_option(\"display.max_rows\", 120)\n", | ||
"pandas.set_option(\"display.max_columns\", 120)" | ||
] | ||
} | ||
], | ||
"metadata": { | ||
"kernelspec": { | ||
"display_name": "Python 3", | ||
"language": "python", | ||
"name": "python3" | ||
}, | ||
"language_info": { | ||
"codemirror_mode": { | ||
"name": "ipython", | ||
"version": 3 | ||
}, | ||
"file_extension": ".py", | ||
"mimetype": "text/x-python", | ||
"name": "python", | ||
"nbconvert_exporter": "python", | ||
"pygments_lexer": "ipython3", | ||
"version": "3.9.2" | ||
}, | ||
"pycharm": { | ||
"stem_cell": { | ||
"cell_type": "raw", | ||
"metadata": { | ||
"collapsed": false | ||
}, | ||
"source": [] | ||
} | ||
} | ||
}, | ||
"nbformat": 4, | ||
"nbformat_minor": 4 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters