diff options
| author | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-05-30 18:39:05 +0100 |
|---|---|---|
| committer | Gertjan van den Burg <gertjanvandenburg@gmail.com> | 2019-05-30 18:39:05 +0100 |
| commit | 47116a4682edb1f22d00da06802cc3eff40bf5bd (patch) | |
| tree | 1f8bcbb1b86e112eefed5a6dd4fe0ea1541183d7 /docs/generate_autodocs.py | |
| parent | Merge branch 'master' of github.com:GjjvdBurg/PyGenSVM (diff) | |
| download | pygensvm-47116a4682edb1f22d00da06802cc3eff40bf5bd.tar.gz pygensvm-47116a4682edb1f22d00da06802cc3eff40bf5bd.zip | |
Update documentation
Diffstat (limited to 'docs/generate_autodocs.py')
| -rw-r--r-- | docs/generate_autodocs.py | 92 |
1 files changed, 56 insertions, 36 deletions
diff --git a/docs/generate_autodocs.py b/docs/generate_autodocs.py index b2c9fb6..1aa8f7d 100644 --- a/docs/generate_autodocs.py +++ b/docs/generate_autodocs.py @@ -15,52 +15,64 @@ import os from docutils.statemachine import StringList, ViewList -from sphinx.ext.autodoc import (AutoDirective, ClassDocumenter, Options, - FunctionDocumenter) +from sphinx.ext.autodoc import ( + AutoDirective, + ClassDocumenter, + Options, + FunctionDocumenter, +) from sphinx.application import Sphinx from sphinx.environment import BuildEnvironment -BASE_DIR = '/home/gertjan/Dropbox/phd/research/msvm/python/start_here/' -DOCDIR = os.path.join(BASE_DIR, 'gensvm', 'docs') +HERE_DIR = os.path.dirname(os.path.abspath(__file__)) +BASE_DIR = os.path.abspath(os.path.join(HERE_DIR, "..", "..")) -CLASSES = [ - 'GenSVMGridSearchCV', - 'GenSVM' - ] +DOCDIR = os.path.join(BASE_DIR, "gensvm", "docs") -FUNCTIONS = [ - 'load_default_grid' - ] +CLASSES = ["GenSVMGridSearchCV", "GenSVM"] + +FUNCTIONS = ["load_grid_tiny", "load_grid_small", "load_grid_full"] FULL_NAMES = { - 'GenSVM': 'gensvm.core.GenSVM', - 'GenSVMGridSearchCV': 'gensvm.gridsearch.GenSVMGridSearchCV', - 'load_default_grid': 'gensvm.gridsearch.load_default_grid' - } + "GenSVM": "gensvm.core.GenSVM", + "GenSVMGridSearchCV": "gensvm.gridsearch.GenSVMGridSearchCV", + "load_grid_tiny": "gensvm.gridsearch.load_grid_tiny", + "load_grid_small": "gensvm.gridsearch.load_grid_small", + "load_grid_full": "gensvm.gridsearch.load_grid_full", +} OUTPUT_FILES = { - 'GenSVMGridSearchCV': os.path.join(DOCDIR, 'cls_gridsearch.rst'), - 'GenSVM': os.path.join(DOCDIR, 'cls_gensvm.rst'), - 'load_default_grid': os.path.join(DOCDIR, 'auto_functions.rst') - } + "GenSVMGridSearchCV": os.path.join(DOCDIR, "cls_gridsearch.rst"), + "GenSVM": os.path.join(DOCDIR, "cls_gensvm.rst"), + "load_grid_tiny": os.path.join(DOCDIR, "auto_functions.rst"), + "load_grid_small": os.path.join(DOCDIR, "auto_functions.rst"), + "load_grid_full": os.path.join(DOCDIR, "auto_functions.rst"), +} def load_app(): srcdir = DOCDIR[:] confdir = DOCDIR[:] - outdir = os.path.join(BASE_DIR, 'gensvm_docs', 'html') - doctreedir = os.path.join(BASE_DIR, 'gensvm_docs', 'doctrees') - buildername = 'html' + outdir = os.path.join(BASE_DIR, "gensvm_docs", "html") + doctreedir = os.path.join(BASE_DIR, "gensvm_docs", "doctrees") + buildername = "html" app = Sphinx(srcdir, confdir, outdir, doctreedir, buildername) return app def generate_class_autodoc(app, cls): - ad = AutoDirective(name='autoclass', arguments=[FULL_NAMES[cls]], - options={'noindex': True}, content=StringList([], items=[]), - lineno=0, content_offset=1, block_text='', state=None, - state_machine=None) + ad = AutoDirective( + name="autoclass", + arguments=[FULL_NAMES[cls]], + options={"noindex": True}, + content=StringList([], items=[]), + lineno=0, + content_offset=1, + block_text="", + state=None, + state_machine=None, + ) ad.env = BuildEnvironment(app) ad.genopt = Options(noindex=True) @@ -70,16 +82,23 @@ def generate_class_autodoc(app, cls): documenter = ClassDocumenter(ad, ad.arguments[0]) documenter.generate(all_members=True) - with open(OUTPUT_FILES[cls], 'w') as fid: + with open(OUTPUT_FILES[cls], "w") as fid: for line in ad.result: - fid.write(line + '\n') + fid.write(line + "\n") def generate_func_autodoc(app, func): - ad = AutoDirective(name='autofunc', arguments=[FULL_NAMES[func]], - options={'noindex': True}, content=StringList([], items=[]), - lineno=0, content_offset=1, block_text='', state=None, - state_machine=None) + ad = AutoDirective( + name="autofunc", + arguments=[FULL_NAMES[func]], + options={"noindex": True}, + content=StringList([], items=[]), + lineno=0, + content_offset=1, + block_text="", + state=None, + state_machine=None, + ) ad.env = BuildEnvironment(app) ad.genopt = Options(noindex=True) @@ -89,15 +108,16 @@ def generate_func_autodoc(app, func): documenter = FunctionDocumenter(ad, ad.arguments[0]) documenter.generate(all_members=True) - with open(OUTPUT_FILES[func], 'a') as fid: + with open(OUTPUT_FILES[func], "a") as fid: for line in ad.result: - fid.write(line + '\n') + fid.write(line + "\n") def main(): for of in OUTPUT_FILES: fname = OUTPUT_FILES[of] - os.unlink(fname) + if os.path.exists(fname): + os.unlink(fname) app = load_app() for cls in CLASSES: generate_class_autodoc(app, cls) @@ -105,5 +125,5 @@ def main(): generate_func_autodoc(app, func) -if __name__ == '__main__': +if __name__ == "__main__": main() |
