convert-markdown-into-ipynb-and-test.sh 1.4 KB
Newer Older
G
gongweibao 已提交
1
#!/bin/bash
G
gongweibao 已提交
2
command -v go >/dev/null 2>&1
G
gongweibao 已提交
3
if [[ $? -ne 0 ]]; then
G
gongweibao 已提交
4 5 6 7
    echo >&2 "Please install go https://golang.org/doc/install#install"
    exit 1
fi

Y
Yancey1989 已提交
8
export GOPATH=~/go; go get -u github.com/wangkuiyi/ipynb/markdown-to-ipynb
G
gongweibao 已提交
9

G
gongweibao 已提交
10
cur_path="$(cd "$(dirname "$0")" && pwd -P)"
G
gongweibao 已提交
11 12 13 14
cd $cur_path/../

#convert md to ipynb
for file in */{README,README\.en}.md ; do
Y
Yancey1989 已提交
15
    ~/go/bin/markdown-to-ipynb < $file > ${file%.*}".ipynb"
G
gongweibao 已提交
16
    if [[ $? -ne 0 ]]; then
G
gongweibao 已提交
17 18 19 20 21
        echo >&2 "markdown-to-ipynb $file error"
        exit 1
    fi
done

G
gongweibao 已提交
22
if [[ -z $TEST_EMBEDDED_PYTHON_SCRIPTS ]]; then
G
gongweibao 已提交
23 24 25 26 27 28 29 30 31
    exit 0
fi

#exec ipynb's py file
for file in */{README,README\.en}.ipynb ; do
    pushd $PWD > /dev/null
    cd $(dirname $file) > /dev/null

    echo "begin test $file"
G
gongweibao 已提交
32 33 34 35 36 37 38 39 40 41 42 43 44
    if [[ $(dirname $file) == "08.recommender_system" ]]; then
       timeout -s SIGKILL 30 bash -c \
           "jupyter nbconvert --to python $(basename $file) --stdout  | \
           sed  's/get_ipython()\.magic(.*'\''matplotlib inline'\'')/\#matplotlib inline/g' | \
           sed '/^# coding: utf-8/a\import matplotlib\nmatplotlib.use('\''Agg'\'')' | python"
    else
       timeout -s SIGKILL 30  bash -c "jupyter nbconvert --to python $(basename $file) --stdout | python" 
    fi

    if [[ $? -ne 0 && $? -ne 124 && $? -ne 137 ]]; then
        echo >&2 "exec $file error!"
        exit 1
    fi
G
gongweibao 已提交
45 46 47 48

    popd > /dev/null
    #break
done