File size: 1,608 Bytes
db5855f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Execute notebooks and convert them to Markdown and HTML
# Output from notebook cells with tag "hide_output" will be hidden in converted notebooks

ignore_list=$*
rstdir=$PWD"/rst_files"
binderlist=$rstdir"/notebooks_with_binder_buttons.txt"
colablist=$rstdir"/notebooks_with_colab_buttons.txt"
notebooklist=$rstdir"/all_notebooks_paths.txt"
tagslist=$rstdir"/notebooks_tags.json"
mkdir -p $rstdir

# List all notebooks that contain binder or colab buttons based on readme
for n in $(git ls-files '*.md'); do
    cat $n | grep -oP "https://mybinder.org/v2.*?-.*?ipynb" | sed 's#%2F#/#g' | sed -e 's|[^/]*/||g' -e 's|.ipynb$||' | sort | uniq >> $binderlist
    cat $n | grep -oP "https://colab.research.google.com/github.*?-.*?ipynb" | sed -e 's|[^/]*/||g' -e 's|.ipynb$||' | sort | uniq >> $colablist
done
find notebooks -maxdepth 2 -name "*.ipynb" | sort > $notebooklist
taggerpath=$(git ls-files "*tagger.py")
notebookspath=$(git ls-files "*.ipynb"| head -n 1)
keywordspath=$(git ls-files "*keywords.json")
python $taggerpath $notebookspath $keywordspath> $tagslist

echo "start converting notebooks"
python $PWD"/.ci/convert_notebooks.py" --rst_dir $rstdir --exclude_execution_file $PWD"/.ci/ignore_convert_execution.txt"

# Remove download links to local files. They only work after executing the notebook
# Replace relative links to other notebooks with relative links to documentation HTML pages
for f in "$rstdir"/*.rst; do
    sed -i "s/<a href=[\'\"][^%].*download>\(.*\)<\/a>/\1/" "$f"
    sed -r -i "s/(<)\.\.\/(.*)\/.*ipynb(>)/\1\2-with-output.html\3/g" "$f"
done