aboutsummaryrefslogtreecommitdiffstats
path: root/maintenance/gen-doc.sh
blob: 904862bc8a1f27c7ae8fccb693726f85305db2e7 (plain)
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
#!/bin/sh
#
# Generate documentation
#


basedir="$(dirname "$0")"
[ "$(echo "$basedir" | cut -c1)" = '/' ] || basedir="$PWD/$basedir"

srcdir="$basedir/.."


die()
{
	echo "$*" >&2
	exit 1
}

gen_rst()
{
	local rst="$1"
	local docname="$(basename "$rst" .rst)"
	local dir="$(dirname "$rst")"
	local html="$dir/$docname.html"

	echo "Generating $(realpath --relative-to="$srcdir" "$html") from $(realpath --relative-to="$srcdir" "$rst") ..."
	python3 -m readme_renderer -o "$html" "$rst" ||\
		die "Failed to generate"
}

gen_pydoc()
{
	local py="$1"
	local basename="$(basename "$py" .py)"
	local dir="$(dirname "$py")"
	local reldir="$(realpath --relative-to="$srcdir" "$dir")"
	local targetdoc="$srcdir/doc/api/$reldir"

	if [ "$reldir" = "tests" -o \
	     "$basename" = "__init__" -o \
	     "$basename" = "__main__" -o \
	     "$basename" = "setup" -o \
	     "$basename" = "examplescript" ]; then
		return
	fi

	(
		mkdir -p "$targetdoc" || die "Failed to create target dir"
		cd "$targetdoc" || die "Failed to cd"
		export PYTHONPATH="$srcdir"
		pydoc3 -w "$py" || die "Failed to generate pydoc3"
	) || die
}

opt_genrst=1
opt_genpydoc=1

while [ $# -ge 1 ]; do
	case "$1" in
	-r)
		opt_genrst=0
		;;
	-p)
		opt_genpydoc=0
		;;
	*)
		die "Unknown option: $1"
		;;
	esac
	shift
done

if [ $opt_genrst -ne 0 ]; then
	for i in $(find "$srcdir" -name '*.rst' -print); do
		gen_rst "$i"
	done
fi

if [ $opt_genpydoc -ne 0 ]; then
	for i in $(find "$srcdir" -name '*.py' -print); do
		gen_pydoc "$i"
	done
fi

exit 0
bues.ch cgit interface