This repository has been archived by the owner on Aug 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathmake_docs_without_docker.sh
executable file
·144 lines (120 loc) · 3.11 KB
/
make_docs_without_docker.sh
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
#!/bin/bash
# file to setup documentation building pipeline without docker
# $1 : Path to the library being documented
# --no-cleanup disable the backup/cleanup procedure
# --git-add stage changed files before generating the docs
PROGNAME=$0
usage() {
cat << EOF >&2
Usage: $PROGNAME [options] <project path>
-h, --help : Show this help
-C, --no-cleanup : Disable the backup/cleanup procedure
-g, --git-add : Stage changed files before generating the docs
-s, --skip-dependencies-install : Skip installing dependencies using pip
-j, --jobs N : Build in parallel with N processes where possible (special value "auto" will set N to cpu-count)
-D setting=value : Override a setting in conf.py
EOF
exit 0
}
cleanup=true
gitadd=false
installdependencies=true
build_args=""
doc_builder_dir=$(dirname $0)
dependency_installer="install_dependencies.sh"
cd $doc_builder_dir
while [ "${1:-}" != "" ]; do
case "$1" in
"-h" | "--help")
usage
;;
"-C" | "--no-cleanup")
cleanup=false
shift
;;
"-g" | "--git-add")
gitadd=true
shift
;;
"-s" | "--skip-dependencies-install")
installdependencies=false
shift
;;
"-j" | "--jobs")
build_args="$build_args $1 $2"
shift 2
;;
"-D")
build_args="$build_args $1 $2"
shift 2
;;
*)
break
;;
esac
done
if [ $# -eq 0 ]
then
echo "Project directory is required"
exit 1
fi
if [[ $1 == -* ]]; then
echo "Unknown option $1"
exit 1
fi
if [ $# -gt 1 ]
then
echo "Too many arguments, only one project directory is required"
exit 1
fi
# If -j is not specified, use all available cores
if [[ $build_args != *"-j"* ]]; then
build_args="$build_args -j auto"
fi
if [ $installdependencies = true ]; then
# install libraries for the doc-builder
pip install -r ./requirements.txt || exit 1
# Run a prebuild script if exists
if [ -f $1/docs/prebuild.sh ]; then
bash $1/docs/prebuild.sh $1
fi
# run the dependency installer script
(cd $1 && [ -x ./$dependency_installer ] && ./$dependency_installer)
fi
# delete any previously generated pages
rm -rf $1/docs/build
function cleanup {
if [ $cleanup = true ]; then
echo "Cleaning up"
# Restore the original docs
rm -rf $1/docs/
mv $1/docs.old/ $1/docs/
fi
# Give read and write permissions to the docs folder, as docker root take ownership of
# the files
echo "Fixing permissions"
chmod -R a+rw $1/docs
}
function error_exit {
echo "Error in building docs"
cleanup $1
exit 1
}
if [ $gitadd = true ]; then
echo "Staging changed files"
cd $1 && git add docs
cd -
fi
if [ $cleanup = true ]; then
echo "Creating backup"
# Backing up the docs folder
cp -r $1/docs/ $1/docs.old/ || exit 1
fi
# syncing ivy folder with the doc-builder folder
rsync -rav docs/ $1/docs/ || error_exit $1
sphinx-build -b html $build_args $1/docs $1/docs/build || error_exit $1
if [ $cleanup = true ]; then
# Move the build to docs.old
mv $1/docs/build $1/docs.old/build || error_exit $1
fi
cleanup $1