Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a getting started notebook for jupytext (and Binder) #257

Merged
merged 5 commits into from
Jun 20, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ The languages that are currently supported by Jupytext are: Julia, Python, R, Ba

[![Introducing Jupytext](https://img.shields.io/badge/TDS-Introducing%20Jupytext-blue.svg)](https://towardsdatascience.com/introducing-jupytext-9234fdff6c57)
[![PyParis](https://img.shields.io/badge/YouTube-PyParis-red.svg)](https://www.youtube.com/watch?v=y-VEZenk824)
[![Binder](https://img.shields.io/badge/Binder-Try%20it!-blue.svg)](https://mybinder.org/v2/gh/mwouts/jupytext/master?filepath=demo)
[![Binder](https://img.shields.io/badge/Binder-Try%20it!-blue.svg)](https://mybinder.org/v2/gh/mwouts/jupytext/master?urlpath=lab/tree/demo/get_started.ipynb)

Looking for a demo?
- Read the original [announcement](https://towardsdatascience.com/introducing-jupytext-9234fdff6c57) in Towards Data Science,
- Watch the [PyParis talk](https://github.com/mwouts/jupytext_pyparis_2018/blob/master/README.md),
- or, try Jupytext online with [binder](https://mybinder.org/v2/gh/mwouts/jupytext/master?filepath=demo)!
- or, try Jupytext online with [binder](https://mybinder.org/v2/gh/mwouts/jupytext/master?urlpath=lab/tree/demo/get_started.ipynb)!

## Installation

Expand Down
5 changes: 5 additions & 0 deletions binder/postBuild
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,8 @@ python -m bash_kernel.install

# Trust our notebook
jupyter trust demo/World\ population.ipynb

# Set up extensions for JupyterLab and Notebook
jupyter labextension install jupyterlab-jupytext
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's correct. If we don't include that line, then we get asked if the jupytext extension for jupyterlab should be built, so it's better to do that in advance

jupyter nbextension install --py jupytext --user
jupyter nbextension enable --py jupytext --user
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think these two lines are not needed: the notebook extension is already available in the current binder

119 changes: 119 additions & 0 deletions demo/get_started.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Getting started with Jupytext\n",
"\n",
"This small notebook shows you how to activate Jupytext in the JupyterLab\n",
"environment. We'll show you a few things that you can do with Jupytext and\n",
"a bit of what happens under the hood.\n",
"\n",
"**Note: to run this notebook locally, you need to first follow the Jupytext\n",
"installation instructions and activate the JupyterLab plugin. If you're on\n",
"Binder, it should already work.**\n",
"\n",
"## Enabling Jupytext in a new notebook\n",
"\n",
"This notebook is brand new - it hasn't had any special extra metadata added\n",
"to it. \n",
"\n",
"If we want Jupytext to save files in multiple formats automatically,\n",
"we can use the JupyterLab **command palette** to do so.\n",
"\n",
"* Click on the little 🎨 icon to the left\n",
"* Then type **`Jupytext`**. You should see a number of commands come up. Each\n",
" one tells Jupytext to save the notebook in a different\n",
" file format automatically.\n",
"* Select **Pair notebook with Markdown**\n",
"\n",
"That's it! If you have Jupytext installed, it will now save your notebook in\n",
"markdown format automatically when you save this `.ipynb` file.\n",
"\n",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would add something like 'in addition'. It is important to make it clear that Jupyter will continue to save the original notebook as well! Also, maybe we can mention that the two files really point to the same document, and that the Markdown file can be edited as well.

"After you've done this, save the notebook. You should now see a new file called\n",
"**`get_started.md`** in the same directory as this notebook.\n",
"\n",
"## How does Jupytext know to do this?\n",
"\n",
"Jupytext uses notebook-level metadata to keep track of what languages are paired\n",
"with a notebook. Below we'll print the metadata of this notebook so you can see\n",
"what the Jupytext metadata looks like."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import nbformat as nbf\n",
"from IPython.display import JSON\n",
"notebook = nbf.read('./get_started.ipynb', nbf.NO_CONVERT)\n",
"JSON(notebook['metadata'])"
]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice example! Thanks

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Chris, one meta-question... would you mind if we stored this notebook in its Markdown representation in the demo folder, and generate the ipynb in the postBuild with Jupytext? This way we would'nt need to review an ipynb file any more 😄

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ooh that's a cool idea - yeah sounds good

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More explicitly: I was thinking of adding these lines to postBuild:

cd demo
jupytext get_started.md --to ipynb --update-metadata '{"jupytext":null}'
rm get_started.md

},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As you select different languages from the command palette (following the instructions\n",
"above) and save the notebook, you'll see this metadata change."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## That's it!\n",
"\n",
"Play around with different kinds of code and outputs to see how each is\n",
"converted into its corresponding text format. Here's a little Python code\n",
"to get you started:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"\n",
"plt.scatter(*np.random.randn(2, 100), c=np.random.randn(100), s=np.random.rand(100)*100)"
]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes me think that we do not have an explicit mention that Jupytext works with every kind of notebook, even the most interactive notebooks with widgets, etc... Maybe we could write a FAQ section in the help and include typical questions like that one.

},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Experiment with other notebooks\n",
"\n",
"There are several other demo notebooks for you to explore Jupytext's functionality,\n",
"try them out!"
]
}
],
"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.6.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
4 changes: 2 additions & 2 deletions docs/introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ In short: the Markdown representation of notebooks fits well the notebooks that

[![](https://img.shields.io/badge/TDS-Introducing%20Jupytext-blue.svg)](https://towardsdatascience.com/introducing-jupytext-9234fdff6c57)
[![](https://img.shields.io/badge/YouTube-PyParis-red.svg)](https://www.youtube.com/watch?v=y-VEZenk824)
[![](https://img.shields.io/badge/Binder-Try%20it!-blue.svg)](https://mybinder.org/v2/gh/mwouts/jupytext/master?filepath=demo)
[![](https://img.shields.io/badge/Binder-Try%20it!-blue.svg)](https://mybinder.org/v2/gh/mwouts/jupytext/master?urlpath=lab/tree/demo/get_started.ipynb)

Looking for a demo?
- Read the original [announcement](https://towardsdatascience.com/introducing-jupytext-9234fdff6c57) in Towards Data Science,
- Watch the [PyParis talk](https://github.com/mwouts/jupytext_pyparis_2018/blob/master/README.md),
- or, try Jupytext online with [binder](https://mybinder.org/v2/gh/mwouts/jupytext/master?filepath=demo)!
- or, try Jupytext online with [binder](https://mybinder.org/v2/gh/mwouts/jupytext/master?urlpath=lab/tree/demo/get_started.ipynb)!

## Want to contribute?

Expand Down