-
Notifications
You must be signed in to change notification settings - Fork 23
Expand file tree
/
Copy pathrelease_docs
More file actions
executable file
·230 lines (199 loc) · 6.96 KB
/
release_docs
File metadata and controls
executable file
·230 lines (199 loc) · 6.96 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/bin/bash
set -x
# Note: $2 will now be interpreted as a 'do not commit' flag - SLB doesn't
# use the final commiting logic since she needs to push to upstream not
# origin and also does some checks
if [[ -n $2 && $2 != "no-commit" ]]; then
set +x
echo "Error: second argument can only be 'no-commit'" >&2
exit 1
fi
version=`python -c "import cf; print(cf.__version__)"`
sphinx_version=`python -c "import sphinx; print(sphinx.__version__)"`
echo "NOTE: Using sphinx version: $sphinx_version"
# Main docs cases, where 'main docs' means all docs except the recipes pages
if [[ $1 = "latest" ]] ; then
dir=$PWD/docs
elif [[ $1 = "archive" ]] ; then
dir=$PWD/docs/$version
elif [[ $1 = "dev" || $1 = "dev-clean" ]]; then
# dev:
# For testing: creates separate dir and does not (git) commit. DOES
# NOT delete an existing .doctrees subdirectory, meaning that
# untouched source files (.py or .rst) might not get rebuilt, even
# if conf.py or other styling files have been modified.
# vs.
# dev-clean:
# For testing: creates separate dir and does not (git) commit and
# also deletes an existing .doctrees subdirectory
dir=$PWD/docs/dev
elif [[ $1 = "dev-scrub" ]] ; then
# For testing: creates separate dir and does not (git) commit and
# also completely deletes the new target directory.
dir=$PWD/docs/dev
rm -fr $dir
# Recipes docs cases (five in total, equivalent to main docs options) -
# see comments above for main docs cases for clarifications of intent
elif [[ $1 = "latest-recipes" ]] ; then
dir=$PWD/recipes-docs
elif [[ $1 = "archive-recipes" ]] ; then
dir=$PWD/recipes-docs/$version
elif [[ $1 = "dev-recipes" || $1 = "dev-clean-recipes" ]]; then
# For testing: similar to dev, but specifically for generating recipes.
dir=$PWD/recipes-docs/dev
elif [[ $1 = "dev-scrub-recipes" ]] ; then
dir=$PWD/recipes-docs/dev
rm -fr $dir
else
set +x
echo "\$1 must be one of 'dev', 'dev-clean', 'dev-scrub', 'latest', 'archive',
'dev-recipes', 'dev-clean-recipes', 'dev-scrub-recipes', 'latest-recipes',
or 'archive-recipes'"
exit 2
fi
export PYTHONPATH=$PWD:$PYTHONPATH
# Make zip of example files
cd docs/source/sample_files
zip cf_tutorial_files.zip *.nc *.pp
cd -
# Regerenate tutorial.py field_analysis.py
#if [[ $1 = "latest" ]] || [[ $1 = "archive" ]] ; then
# ./test_tutorial_code
# rc=$?
# if [[ $rc != 0 ]]; then
# echo "test_tutorial_code failed."
# # exit $rc
# fi
# pre-commit run --files tutorial.py field_analysis.py
#fi
# --------------------------------------------------------------------
# Make the latest docs
# --------------------------------------------------------------------
if [[ $1 == *-recipes ]]; then
# Any of: dev-recipes, dev-clean-recipes, dev-scrub-recipes,
# latest-recipes, archive-recipes
is_recipes=true
cd recipes-docs
else
# Non-recipes variants: dev, dev-clean, dev-scrub, latest, archive
is_recipes=false
cd docs
fi
#if [[ $1 = "latest" ]] || [[ $1 = "archive" ]] || [[ $1 = "dev-clean" ]] ; the#n
# rm -fr $dir/.doctrees
#fi
mkdir -p $dir/_downloads
#if [[ $1 = "latest" ]] || [[ $1 = "archive" ]] ; then
# # Force recreation of recipes
# rm source/recipes/*.md5
#fi
recipes_source=source/recipes
if [[ $1 = "dev-recipes-scrub" ]] ; then
# Force recreation of recipes
rm $recipes_source/*.md5
rm $recipes_source/*.ipynb
rm $recipes_source/*_codeobj.pickle
rm $recipes_source/*_recipe.rst
fi
export CF_DOCS_MODE=$1
make html $dir
rc=$?
if [[ $rc != 0 ]]; then
echo "ERROR: Failed in: make html $dir"
exit $rc
fi
if [[ ! $is_recipes ]]; then
echo "Processing download files."
cp -pv source/sample_files/cf_tutorial_files.zip source/tutorial.py source/field_analysis.py $dir/_downloads
for download_file in cf_tutorial_files.zip tutorial.py field_analysis.py cheatsheet.pdf
do
# Remove the hash string component added by GitHub to the link
# where the resources are hosted (GH changes it to something like
# '_downloads/4cd32e1c6bdf28fb61e15ffab2a8d84e/download_file')
sed -i "s/\(href=._downloads\).*\($download_file\)/\1\/\2/" \
$dir/tutorial.html \
$dir/analysis.html \
$dir/cheat_sheet.html
# all pages referencing these resources must be added to this list
done
fi
# --------------------------------------------------------------------
# Process recipes
# --------------------------------------------------------------------
if [[ $is_recipes ]]; then
echo "Setting up for the recipes docs build."
recipes_source="source/recipes"
recipes_files=( "${recipes_source}"/*_{recipe,helper}.{ipynb,py} )
files_to_copy=(
"${recipes_source}/recipes_jupyter.zip"
"${recipes_source}/recipes_python.zip"
"${recipes_files[@]}"
)
destination_dir="$dir/_downloads"
cp -pv "${files_to_copy[@]}" "$destination_dir"
html_files=(
"$dir/recipes/index.html"
"$dir/recipes/"*.html
)
for html_file in "${html_files[@]}"; do
for recipe_file in "${files_to_copy[@]}"; do
sed -i "s|href=\".*\/${recipe_file##*/}\"|href=\"../_downloads/${recipe_file##*/}\"|g" "$html_file"
done
done
# Recipe filters
while IFS= read -r href; do
IFS= read -r div
awk -v href="$href" -v div="$div" '
{
if ($0 ~ href) {
gsub("<div class=\"sphx-glr-thumbcontainer\"[^>]*>", div, prev)
}
print prev
prev = $0
}
END {print prev}
' $dir/recipes/index.html > temp && mv temp $dir/recipes/index.html
done < source/recipes/recipe_list.txt
fi
# --------------------------------------------------------------------
# Process styles and templates
# --------------------------------------------------------------------
if [[ $1 = "latest" ]] ; then
# Copy over our custom stylesheet. It is referenced in the HTML docs
# files but Sphinx with alabaster theme doesn't seem to (?) provide a
# means to transfer it to the created _static dir via the build itself
# *when* the output dir is the top-level one (hence copy works for
# 'dev' & 'archive' builds to sub-dirs). Seemingly relates to the
# build warning:
# WARNING: html_static_path entry '_static' is placed inside outdir
cp source/_static/customise-alabaster.css _static/customise-alabaster.css
else
# For all other cases, copy the templates to the target directory
rm -fr $dir/_templates
cp -pr _templates $dir
fi
# --------------------------------------------------------------------
# Add and commit the latest
# --------------------------------------------------------------------
if [[ $1 = "latest" && $2 != "no-commit" ]] ; then
cd $dir
git add \
*.html \
class/*.html \
function/*.html \
method/*.html \
attribute/*.html \
recipes/*.html \
*.inv \
*.js \
_static \
_templates \
_downloads/*.zip \
_downloads/*.ipynb \
_downloads/*.py \
_images/*.png \
_images/*.svg
git commit -a -m "v$version documentation"
fi
set +x
echo PYTHONPATH=$PYTHONPATH