Commit 6ddf7bd3 authored by Christoph Ruegge's avatar Christoph Ruegge
Browse files

Cleanup, generate nb links from pre-commit

parent eef7c3e3
#!/bin/bash
set -e
cd "$(git rev-parse --show-toplevel)"
git rm -qf exercises/*.ipynb
for nb in exercises/solutions/*.ipynb; do
target="exercises/$(basename "$nb")"
filter=$(git check-attr filter "$target" | sed 's/.* //')
if [[ -n "$filter" ]]; then
cat "$nb" | $(git config filter."$filter".clean) > "$target"
else
cp "$nb" "$target"
fi
done
#!/usr/bin/python3
from plumbum import local
from plumbum.cmd import git
local.cwd.chdir(git('rev-parse', '--show-toplevel').strip())
readme = local.cwd / 'README.md'
tmp = local.cwd / 'README.md.tmp'
# jump to correct place and save stuff up to start of list
with readme.open('r') as f, tmp.open('w') as fout:
flag = True
for line in f:
if flag:
fout.write(line)
if not flag and line.find("## ") != -1:
flag = True
fout.write(line)
if flag and line.find("## lecture notes") != -1:
flag = False
fout.write("\n")
for nb in sorted(local.path("lecture/") // "*.ipynb"):
title = nb.basename.replace(".ipynb", "")
link = "* [{}](http://nbviewer.jupyter.org/urls/gitlab.gwdg.de/jschulz1/haskell_labcourse/raw/master/lecture/{}.ipynb)\n".format(title, title)
print(link)
fout.write(link)
fout.write("\n")
tmp.rename(readme)
#!/usr/bin/python3
from plumbum import local
from os import rename
header = "## lecture notes\nviewed in nbviewer directly from the repository\n\n"
f = open('README.md', 'r')
fout = open('README_tmp.md', 'w')
# jump to correct place and save stuff up to start of list
flag = True
for line in f:
if flag:
fout.write(line)
if not flag and line.find("## ") != -1:
flag = True
fout.write(line)
if flag and line.find("## lecture notes") != -1:
flag = False
fout.write("\n")
for nb in sorted(local.path("lecture/") // "*.ipynb"):
title = nb.basename.replace(".ipynb", "")
link = "* [{}](http://nbviewer.jupyter.org/urls/gitlab.gwdg.de/jschulz1/haskell_labcourse/raw/master/lecture/{}.ipynb)\n".format(title, title)
print(link)
fout.write(link)
fout.write("\n")
f.close()
fout.close()
rename("README_tmp.md", "README.md")
#!/bin/bash
set -e
exec 2>&1
cd "$(git rev-parse --show-toplevel)"
stashed=false
stash() {
if ! $stashed; then
git stash -q --keep-index
stashed=true
fi
}
stash-pop() {
$stashed && git stash pop -q
}
trap stash-pop EXIT
if git diff --cached --name-only | grep -q '^exercises/'; then
git stash -q --keep-index
git rm -f exercises/*.ipynb
for nb in exercises/solutions/*.ipynb; do
target="exercises/$(basename "$nb")"
cat "$nb" | $(git config filter.ipynb-codecells.clean) > "$target"
git add "$target"
done
git stash pop -q
stash
scripts/make-exercises.sh || exit 1
git add exercises/*.ipynb
fi
if git diff --cached --name-only | grep -q '^lecture/'; then
stash
# TODO: Ignore errors here for now, in case plumbum is not available.
scripts/make-nb-links.py
git add README.md
fi
exit 0
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment