7.4. call_sphinxapidoc.sh

The call_apidoc.sh implements a wrapper for the generation of the API documentation. The curent defaul call is:

sphinx-apidoc

The expected output is the raw output from the tool sphinx-apidoc, which is prepared to be postprocess by adding additional files and modification of the main configuration file conf.py. The finished input source directory is finally processed by sphinx.

7.4.1. Source

  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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
PROJECT='setupdocx'
VERSION=${DOCX_VERSION:-`date +%Y.%m.%d`}
RELEASE=${DOCX_RELEASE:-$VERSION}
AUTHOR='Arno-Can Uestuensoez'
COPYRIGHT='Copyright (C) 2019 Arno-Can Uestuensoez @Ingenieurbuero Arno-Can Uestuensoez'
LICENSE='Artistic-License-2.0 + Forced-Fairplay-Constraints'
STATUS='beta'
MISSION='Support API documentation extensions for setuptools / distutils.'
BUILDDATE=`date`


# the absolute pathname for this source
MYPATH="${BASH_SOURCE%/*}/"
if [ "X${MYPATH#.}" != "X$MYPATH" ];then
	MYPATH="${PWD}/${MYPATH#.}";MYPATH="${MYPATH//\/\//\/}"
fi

MYLIB=${MYPATH%/*/*/}/
source ${MYLIB}libbash.sh


if((DOCX_QUIET == 0));then
	cat <<EOF

################################################################
#                                                              #
# WRAPPER = call_apidoc.sh                                     #
$(printf "# PROJECT = %-51s#" $PROJECT)
#                                                              #
# Generate API documentation - default: sphinx-apidoc          #
#                                                              #
################################################################

EOF
fi


display_state 1 1
if [ $? -ne 0 ];then
	cat <<EOF
#
# ${0##*/}:Called:
#   $0 $@
#
# ${0##*/}:Input Environ Options:
#   DOCX_APIDOC           = '$DOCX_APIDOC'
#   DOCX_APIREF           = '$DOCX_APIREF'
#   DOCX_AUTHOR           = '$DOCX_AUTHOR'
#   DOCX_BUILDDIR         = '$DOCX_BUILDDIR'
#   DOCX_BUILDRELDIR      = '$DOCX_BUILDRELDIR'
#   DOCX_CLEAN            = '$DOCX_CLEAN'
#   DOCX_CONFIGPATH       = '$DOCX_CONFIGPATH'
#   DOCX_COPYRIGHT        = '$DOCX_COPYRIGHT'
#   DOCX_DEBUG            = '$DOCX_DEBUG'
#   DOCX_DOCNAME          = '$DOCX_DOCNAME'
#   DOCX_DOCSRC           = '$DOCX_DOCSRC'
#   DOCX_DOCTEMPLATE      = '$DOCX_DOCTEMPLATE'
#   DOCX_DOCTYPE          = '$DOCX_DOCTYPE'
#   DOCX_EMBED            = '$DOCX_EMBED'
#   DOCX_INDEXSRC         = '$DOCX_INDEXSRC'
#   DOCX_LIB              = '$DOCX_LIB'
#   DOCX_LICENSE          = '$DOCX_LICENSE'
#   DOCX_MISSION          = '$DOCX_MISSION'
#   DOCX_NAME             = '$DOCX_NAME'
#   DOCX_NOEXEC           = '$DOCX_NOEXEC'
#   DOCX_QUIET            = '$DOCX_QUIET'
#   DOCX_RAWDOC           = '$DOCX_RAWDOC'
#   DOCX_RELEASE          = '$DOCX_RELEASE'
#   DOCX_SRCDIR           = '$DOCX_SRCDIR'
#   DOCX_STATUS           = '$DOCX_STATUS'
#   DOCX_VERBOSE          = '$DOCX_VERBOSE'
#   DOCX_VERBOSEX         = '$DOCX_VERBOSEX'
#   DOCX_VERSION          = '$DOCX_VERSION'
#
#   PATH                  = '$PATH'
#
#   PYTHONPATH            = '$PYTHONPATH'
#
#   MYPATH                = '$MYPATH'
#   INDIR                 = '$INDIR'
#
EOF

fi


#----------------------------
#*** command line options *** 
#----------------------------
#
# Extract and optionally filter out known command line options of the wrapper.
# Non-filtered options are transparently passed as appendix to the executable
# anyhow, the executable should be instrumented only via DOCX_EXECOPTS
# see also DOCX_EXECOPTS_RESET.
for x in $@;do
	case $x in
		-v|--verbose)let DOCX_VERBOSE+=1;shift;;
		-d|--debug)let DOCX_DEBUG+=1;shift;;
	esac
	if((DOCX_VERBOSE > 0 || DOCX_DEBUG > 0));then
		# trace it as interface
		echo "got commandline option: $x"
	fi
done


# input base directory
INDIR="${INDIR:-$PWD}"
if [ "X${INDIR#.}" != "X$INDIR" ];then
	INDIR="${PWD}/${INDIR#.}";INDIR="${INDIR//\/\//\/}"
fi
INDIR="${INDIR}/"

# builder - for casual readout, even though defined by directory
DOCX_BUILDER="${DOCX_BUILDER:-sphinx}"

# output base directory
DOCX_BUILDDIR="${DOCX_BUILDDIR:-build}/"
if [ ! -e "${DOCX_BUILDDIR}" ];then
	exec_call mkdir -p "${DOCX_BUILDDIR}"
fi
if [ "X${DOCX_BUILDDIR#/}" != "X${DOCX_BUILDDIR}" ];then
	DOCX_BUILDDIR_ABS="${DOCX_BUILDDIR}"
else
	DOCX_BUILDDIR_ABS="${PWD}/${DOCX_BUILDDIR_ABS#.}";DOCX_BUILDDIR_ABS="${DOCX_BUILDDIR_ABS//\/\//\/}"
fi
export PYTHONPATH="$PWD:$PYTHONPATH"


# document source directory
DOCX_DOCSRC="${DOCX_DOCSRC:-docsrc}"
DOCX_DOCSRC="${DOCX_DOCSRC%%/}"

DOCX_DOCTYPE="${DOCX_DOCTYPE:-html}"

# document source directory
DOCX_DOCNAME="${DOCX_DOCNAME:-$PROJECT}"

# executable
DOCX_EXEC=${DOCX_EXEC:-sphinx-apidoc}


DOCX_VERBOSE=${DOCX_VERBOSE:-0}


display_state 2 2
if [ $? -ne 0 ];then
	cat <<EOF
#
# ${0##*/}:Called:"
#   $0 $@"
#
# ${0##*/}:Input Environ Options:"
#   DOCX_APIDOC           = '$DOCX_APIDOC'"
#   DOCX_APIREF           = '$DOCX_APIREF'"
#   DOCX_AUTHOR           = '$DOCX_AUTHOR'"
#   DOCX_BUILDDIR         = '$DOCX_BUILDDIR'"
#   DOCX_BUILDRELDIR      = '$DOCX_BUILDDIR'"
#   DOCX_CLEAN            = '$DOCX_CLEAN'"
#   DOCX_CONFIGPATH       = '$DOCX_CONFIGPATH'"
#   DOCX_COPYRIGHT        = '$DOCX_COPYRIGHT'"
#   DOCX_DEBUG            = '$DOCX_DEBUG'"
#   DOCX_DOCNAME          = '$DOCX_DOCNAME'"
#   DOCX_DOCSRC           = '$DOCX_DOCSRC'"
#   DOCX_DOCTYPE          = '$DOCX_DOCTYPE'"
#   DOCX_DOCTEMPLATE      = '$DOCX_DOCTEMPLATE'"
#   DOCX_EMBED            = '$DOCX_EMBED'"
#   DOCX_INDEXSRC         = '$DOCX_INDEXSRC'"
#   DOCX_LIB              = '$DOCX_LIB'"
#   DOCX_LICENSE          = '$DOCX_LICENSE'"
#   DOCX_MISSION          = '$DOCX_MISSION'"
#   DOCX_NAME             = '$DOCX_NAME'"
#   DOCX_NOEXEC           = '$DOCX_NOEXEC'"
#   DOCX_QUIET            = '$DOCX_QUIET'"
#   DOCX_RAWDOC           = '$DOCX_RAWDOC'"
#   DOCX_RELEASE          = '$DOCX_RELEASE'"
#   DOCX_SRCDIR           = '$DOCX_SRCDIR'"
#   DOCX_STATUS           = '$DOCX_STATUS'"
#   DOCX_VERBOSE          = '$DOCX_VERBOSE'"
#   DOCX_VERBOSEX         = '$DOCX_VERBOSEX'"
#   DOCX_VERSION          = '$DOCX_VERSION'"	
#
EOF
fi

display_state 2 2
if [ $? -ne 0 ];then
	IFSO=$IFS
	IFS=':'
	_F=0
	for p in ${PATH};do
		if((_F==0));then
			_F=1
			echo "#  PATH                    = '$p'"
		else
			echo "#                          : '$p'"
		fi
	done

	echo "#"

	_F=0
	for p in ${PYTHONPATH};do
		if((_F==0));then
			_F=1
			echo "#  PYTHONPATH              = '$p'"
		else
			echo "#                          : '$p'"
		fi
	done

	echo "#"
	echo "#  MYPATH                  = '$MYPATH'"
	echo "#  INDIR                   = '$INDIR'"
	echo "#"
	
	IFS=$IFSO
fi

display_state 4 4
if [ $? -ne 0 ];then
	cat <<EOF
#   PATH                   = '$PATH'"
#
#   PYTHONPATH             = '$PYTHONPATH'"
#
#   MYPATH                 = '$MYPATH'"
#   INDIR                  = '$INDIR'"
#
EOF
fi


#
# *** start exec ***
#

# import directory for entries of static reference
STATIC="${DOCX_BUILDDIR}/sphinx/apidoc/_static"

# source entities
FILEDIRS=""
if [ "X${DOCX_SRCDIR}" != "X" ];then
	OIFS=$IFS
	IFS='
'
	for f in ${DOCX_SRCDIR//\;/$IFS};do
		FILEDIRS+=" ${INDIR}${f}"
	done
	IFS=$OIFS
else
	FILEDIRS+=" ${INDIR}setupdocx"
fi

CALL=""
CALL="$CALL export PYTHONPATH=$PWD:$PYTHONPATH;"
CALL="$CALL $DOCX_EXEC "
if((DOCX_EXECOPTS_RESET == 0));then
	CALL="$CALL -A '$AUTHOR'"
	CALL="$CALL -H '$PROJECT'"
	CALL="$CALL -V '$VERSION'"
	CALL="$CALL -R '$RELEASE'"
	CALL="$CALL -o ${DOCX_BUILDDIR}/${DOCX_BUILDRELDIR}"

	CALL="$CALL -f "
	CALL="$CALL -M "
	CALL="$CALL -d 5 "
	CALL="$CALL -e "

	if((DOCX_GENDOC > 0));then
		CALL="$CALL -F "
	fi

fi


#
# clear options
#
if((DOCX_EXECOPTS_RESET != 0));then
	# remaining options are by default passed to the exec-call, 
	# thus suppressed here for reset
	CALL="$CALL $@"
fi


#
# append extra options
#
CALL="$CALL ${DOCX_EXECOPTS} "

EXCLUDE="  "

RES=0


#
# generate final API documentation 
#
if((RES==0 && DOCX_GENDOC>0));then
	if [ "X${DOCX_TEMPLATE}" != "X" ];then
	SPHINXOPTS+=" -c ${DOCX_CONFIGPATH}/${DOCX_BUILDER}/${DOCX_TEMPLATE}/${DOCX_DOCTYPE}/docsrc"
	fi
fi


#
#build=patches
DOCHTMLDIR="${DOCX_BUILDDIR}sphinx/apidoc/_build/"
DOCHTML="${DOCHTMLDIR}html/index.html"

IFSO=$IFS
IFS=';'
FX=( ${FILEDIRS} )
IFS=$IFSO
for fx in ${FX[@]};do
	if((DOCX_DEBUG > 0));then
		echo "${0##*/}:EXECUTABLE = '$(which ${DOCX_EXEC})'"
		echo "${0##*/}:SOURCE-DIR = '$fx'"
		echo
		echo "${0##*/}:CALL       = <$CALL '$fx' '${EXCLUDE}'>"
	elif((DOCX_VERBOSE > 2));then
		echo "${0##*/}:EXECUTABLE = '$(which ${DOCX_EXEC})'"
		echo "${0##*/}:SOURCE-DIR = '$fx'"
		echo

		IFSO=$IFS
		IFS=';'
		_F=0
		for p in ${CALL};do
			if((_F==0));then
				_F=1
				echo "  CALL                    = '$p'"
			else
				echo "                          ; '$p'"
			fi
		done
		echo "                            '$fx'"
		echo "                            '${EXCLUDE}'"
		echo

		IFS=$IFSO

	elif((DOCX_VERBOSE > 1));then
		echo "${0##*/}:EXECUTABLE = '${DOCX_EXEC}'"
		_f=${fx::-1}
		echo "${0##*/}:SOURCE-DIR = '${_f##*/}'"
	fi

	if((DOCX_NOEXEC == 1));then
		echo "$CALL $fx ${EXCLUDE}"
		RES=0;

	else
		echo
		echo "${0##*/}:Calling executable sphinx-apidoc"
		eval $CALL "$fx" "${EXCLUDE}"
		RES=$?;
		if((RES==0 && DOCX_GENDOC>0));then
			echo "${0##*/}:Calling build of document 'make ${DOCX_DOCTYPE}'"
			if((DOCX_DEBUG > 0));then
				echo "${0##*/}:CD:            <${DOCX_BUILDDIR}/${DOCX_BUILDRELDIR}>"
				echo "${0##*/}:SPHINXOPTS:    <${SPHINXOPTS}>"
				echo "${0##*/}:CALL:          <make ${DOCX_DOCTYPE}>"
			fi
			cd  ${DOCX_BUILDDIR}/${DOCX_BUILDRELDIR}
			SPHINXOPTS="${SPHINXOPTS}" make ${DOCX_DOCTYPE}
			RES=$?;
			cd -
		else
			echo "${0##*/}:Result: $RES"
		fi
	fi
	if((DOCX_VERBOSE > 1));then
		echo
	fi
done

echo

exit $RES

7.4.2. Download

call_apidoc.sh