Get autodoc working properly.

With a complete index, only generate needed files, etc.
develop
PeridexisErrant 2015-10-19 13:57:33 +11:00
parent a091ba4a70
commit bd5eb82554
3 changed files with 38 additions and 11 deletions

@ -0,0 +1,12 @@
######################
Complete Scripts Index
######################
This is the complete index of documentation pulled from script source files.
.. toctree::
:glob:
:maxdepth: 2
/scripts/**include-all

@ -15,6 +15,17 @@ or from the init file.
only be interrupted every 256 instructions. Use ``kill-lua force`` to interrupt only be interrupted every 256 instructions. Use ``kill-lua force`` to interrupt
the next instruction. the next instruction.
Here's an index to documentation pulled from script source files:
.. toctree::
:glob:
:maxdepth: 2
/docs/3rdparty/
Here's the contents page for this document:
.. contents:: .. contents::
================= =================

@ -14,32 +14,36 @@
# serve to show the default. # serve to show the default.
import fnmatch import fnmatch
import io from io import open
import os import os
import shlex import shlex
import sys import sys
from os import listdir from os import listdir
from os.path import isfile, join, isdir from os.path import isfile, join, isdir, relpath
#import sys #import sys
currentDir = '@CMAKE_CURRENT_SOURCE_DIR@' currentDir = '@CMAKE_CURRENT_SOURCE_DIR@'
def makeIncludeAll(directory, extension): def makeIncludeAll(directory, extension):
outputFile = join(directory,'include-all.rst') outputFile = join(directory,'include-all.rst')
#print(outputFile)
files = [ f for f in listdir(directory) if isfile(join(directory,f)) and f.endswith(extension) ] files = [ f for f in listdir(directory) if isfile(join(directory,f)) and f.endswith(extension) ]
files.sort() files.sort()
out = open(outputFile, 'w') dname = relpath(directory, relpath('..', currentDir)).replace('\\', '/')
while dname.startswith('..'):
dname = dname[3:]
TEMPLATE = '.. include:: /{}/{}\n :start-after: BEGIN_DOCS\n :end-before: END_DOCS'
out = []
for f in files: for f in files:
#TODO: check if the file contains the BEGIN_DOCS string with open(join(directory,f), 'r', encoding='utf8') as fstream:
#print(join(directory,f)) data = fstream.read().replace('\n','')
fstream = io.open(join(directory,f), 'r', encoding='utf8')
data = fstream.read().replace('\n','')
fstream.close()
if 'BEGIN_DOCS' in data: if 'BEGIN_DOCS' in data:
out.write('.. include:: ' + join(directory,f) + '\n :start-after: BEGIN_DOCS\n :end-before: END_DOCS\n\n') out.append(TEMPLATE.format(dname, f))
out.close() if out:
# Only write the file if the index is not empty
with open(outputFile, 'w') as outfile:
outfile.write(len(dname)*'=' + '\n' + dname + '\n' + len(dname)*'=' + '\n\n')
outfile.write('\n\n'.join(out))
def makeAllIncludeAll(directory, extension): def makeAllIncludeAll(directory, extension):
for root, subdirs, files in os.walk(directory): for root, subdirs, files in os.walk(directory):