Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Jochen Schulz
haskell_labcourse
Commits
6ddf7bd3
Commit
6ddf7bd3
authored
Mar 14, 2016
by
Christoph Ruegge
Browse files
Cleanup, generate nb links from pre-commit
parent
eef7c3e3
Changes
4
Hide whitespace changes
Inline
Side-by-side
scripts/make-exercises.sh
0 → 100755
View file @
6ddf7bd3
#!/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
scripts/make-nb-links.py
0 → 100755
View file @
6ddf7bd3
#!/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
)
scripts/makenblinks.py
deleted
100755 → 0
View file @
eef7c3e3
#!/usr/bin/python3
from
plumbum
import
local
from
os
import
rename
header
=
"## lecture notes
\n
viewed 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"
)
scripts/pre-commit.sh
View file @
6ddf7bd3
#!/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
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment