Skip to content

Commit

Permalink
Bash scripts as notebooks #127
Browse files Browse the repository at this point in the history
  • Loading branch information
mwouts committed Nov 12, 2018
1 parent 074339e commit 4c3a8bf
Show file tree
Hide file tree
Showing 5 changed files with 123 additions and 1 deletion.
3 changes: 2 additions & 1 deletion jupytext/languages.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
'.r': {'language': 'R', 'comment': '#'},
'.jl': {'language': 'julia', 'comment': '#'},
'.cpp': {'language': 'c++', 'comment': '//'},
'.ss': {'language': 'scheme', 'comment': ';;'}}
'.ss': {'language': 'scheme', 'comment': ';;'},
'.sh': {'language': 'bash', 'comment': '#'}}


def default_language_from_metadata_and_ext(notebook, ext):
Expand Down
70 changes: 70 additions & 0 deletions tests/notebooks/ipynb_bash/sample_bash_notebook.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
" \u001b[0m\u001b[01;32mREADME.md\u001b[0m \u001b[01;32m'Sample bash notebook.ipynb'\u001b[0m \u001b[34;42mbinder\u001b[0m \u001b[34;42mdemo\u001b[0m \u001b[34;42mnotebook\u001b[0m \u001b[34;42mslides\u001b[0m\n"
]
}
],
"source": [
"ls"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"# https://coderwall.com/p/euwpig/a-better-git-log\n",
"git config --global alias.lg \"log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit\""
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"* \u001b[31m64accf1\u001b[m -\u001b[33m (HEAD -> master, origin/master, origin/HEAD)\u001b[m Slides reviewed \u001b[32m(23 hours ago) \u001b[1;34m<Marc Wouts>\u001b[m\n",
"* \u001b[31mbf3d0ab\u001b[m -\u001b[33m\u001b[m README \u001b[32m(23 hours ago) \u001b[1;34m<Marc Wouts>\u001b[m\n",
"* \u001b[31md1116f6\u001b[m -\u001b[33m\u001b[m Use Binder \u001b[32m(23 hours ago) \u001b[1;34m<Marc Wouts>\u001b[m\n",
"* \u001b[31m3526fc6\u001b[m -\u001b[33m\u001b[m Demo notebook has data in the metric explorer \u001b[32m(23 hours ago) \u001b[1;34m<Marc Wouts>\u001b[m\n",
"* \u001b[31mf4139fd\u001b[m -\u001b[33m\u001b[m Ignore more patterns \u001b[32m(23 hours ago) \u001b[1;34m<Marc Wouts>\u001b[m\n",
"* \u001b[31m984ccd1\u001b[m -\u001b[33m\u001b[m Demo script updated \u001b[32m(2 days ago) \u001b[1;34m<Marc Wouts>\u001b[m\n",
"* \u001b[31m6874a22\u001b[m -\u001b[33m\u001b[m Updated final notebook \u001b[32m(2 days ago) \u001b[1;34m<Marc Wouts>\u001b[m\n",
"* \u001b[31ma6b8f88\u001b[m -\u001b[33m\u001b[m Slides and demo are getting ready \u001b[32m(4 days ago) \u001b[1;34m<Marc Wouts>\u001b[m"
]
}
],
"source": [
"git lg"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Bash",
"language": "bash",
"name": "bash"
},
"language_info": {
"codemirror_mode": "shell",
"file_extension": ".sh",
"mimetype": "text/x-sh",
"name": "bash"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
22 changes: 22 additions & 0 deletions tests/notebooks/mirror/ipynb_to_percent/sample_bash_notebook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# ---
# jupyter:
# kernelspec:
# display_name: Bash
# language: bash
# name: bash
# language_info:
# codemirror_mode: shell
# file_extension: .sh
# mimetype: text/x-sh
# name: bash
# ---

# %%
ls

# %%
# https://coderwall.com/p/euwpig/a-better-git-log
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

# %%
git lg
19 changes: 19 additions & 0 deletions tests/notebooks/mirror/ipynb_to_script/sample_bash_notebook.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# ---
# jupyter:
# kernelspec:
# display_name: Bash
# language: bash
# name: bash
# language_info:
# codemirror_mode: shell
# file_extension: .sh
# mimetype: text/x-sh
# name: bash
# ---

ls

# https://coderwall.com/p/euwpig/a-better-git-log
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"

git lg
10 changes: 10 additions & 0 deletions tests/test_mirror.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ def test_ipynb_to_scheme(nb_file):
assert_conversion_same_as_mirror(nb_file, '.ss', 'ipynb_to_script')


@pytest.mark.parametrize('nb_file', list_notebooks('ipynb_bash'))
def test_ipynb_to_bash(nb_file):
assert_conversion_same_as_mirror(nb_file, '.sh', 'ipynb_to_script')


@pytest.mark.parametrize('nb_file', list_notebooks('ipynb_cpp'))
def test_ipynb_to_cpp(nb_file):
assert_conversion_same_as_mirror(nb_file, '.cpp', 'ipynb_to_script')
Expand Down Expand Up @@ -153,6 +158,11 @@ def test_ipynb_to_scheme_percent(nb_file):
assert_conversion_same_as_mirror(nb_file, '.ss', 'ipynb_to_percent', format_name='percent')


@pytest.mark.parametrize('nb_file', list_notebooks('ipynb_bash'))
def test_ipynb_to_bash_percent(nb_file):
assert_conversion_same_as_mirror(nb_file, '.sh', 'ipynb_to_percent', format_name='percent')


@pytest.mark.parametrize('nb_file', list_notebooks('percent'))
def test_percent_to_ipynb(nb_file):
assert_conversion_same_as_mirror(nb_file, '.ipynb', 'script_to_ipynb', format_name='percent')
Expand Down

0 comments on commit 4c3a8bf

Please sign in to comment.