apidoc-saltmods.sh 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/sh
  2. MOD_DIRS='
  3. auth
  4. beacons
  5. clouds
  6. engines
  7. executors
  8. file_server
  9. modules
  10. netapi
  11. output
  12. pillar
  13. proxy
  14. queues
  15. renderers
  16. returners
  17. roster
  18. runners
  19. sdb
  20. thorium
  21. serializers
  22. states
  23. tops
  24. wheel'
  25. build_stubs() {
  26. [ $# -eq 0 ] && { printf 'Module names are required.' 1>&2; return 1; }
  27. local outdir
  28. while [ -n $1 ]; do
  29. outdir="ref/${1}/all"
  30. mkdir -p "$outdir"
  31. sphinx-apidoc --separate -o "${outdir}" $(get_excludes "$1")
  32. find "$outdir" '(' \
  33. -path 'ref/*/all/salt.*.*.rst' \
  34. -o -name 'index.rst' \
  35. ')' -prune \
  36. -o -type f -print0 \
  37. | xargs -0 rm
  38. find "$outdir" -type f -print0 \
  39. | xargs -0 -r -I@ -n1 sh -c \
  40. 'sed -e "/:show-inheritance:/d" @ > "@.new" && mv -- "@.new" "@"'
  41. shift
  42. done
  43. }
  44. get_excludes() {
  45. # This is a tad convoluted. We need to list all top-level files and
  46. # directories in the main Salt dir _except_ for the main __init__.py file
  47. # and the module directory for the module we're building for.
  48. # ...that way sphinx-apidoc will exclude them from the build. (o_O)
  49. exclude="${1:?Dirname to exclude is required.}"
  50. find ../ \
  51. '(' \
  52. -path '*/.git' \
  53. -o -path '../[!s]*/*' \
  54. -o -path '../salt/__init__.py' \
  55. -o -path '../*/*/*' \
  56. ')' -prune \
  57. -o '(' \
  58. -type d \
  59. -o -path '../*.py' \
  60. -o -path '../salt/*.py' \
  61. ')' -print \
  62. | sed -e '/^\.\.\/salt$/d' \
  63. | sed -e '/^\.\.\/salt\/'"$exclude"'$/d'
  64. }
  65. main() {
  66. build_stubs $(printf '%s\n' "$MOD_DIRS")
  67. }
  68. main "$@"