2015-03-27 19:50:56 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
Sphinx Auto-API
|
|
|
|
"""
|
|
|
|
|
2015-06-06 23:11:49 +00:00
|
|
|
import os
|
2015-04-01 00:01:41 +00:00
|
|
|
import fnmatch
|
2015-04-07 20:35:50 +00:00
|
|
|
import shutil
|
2015-03-27 19:50:56 +00:00
|
|
|
|
2015-06-10 18:35:54 +00:00
|
|
|
from sphinx.util.console import darkgreen, bold
|
|
|
|
|
2015-06-06 20:08:44 +00:00
|
|
|
from .domains import DotNetDomain, PythonDomain, GoDomain, JavaScriptDomain
|
2015-04-01 00:01:41 +00:00
|
|
|
|
|
|
|
|
|
|
|
def ignore_file(app, filename):
|
|
|
|
for pat in app.config.autoapi_ignore:
|
|
|
|
if fnmatch.fnmatch(filename, pat):
|
|
|
|
return True
|
|
|
|
return False
|
2015-03-27 19:50:56 +00:00
|
|
|
|
|
|
|
|
2015-06-10 18:35:54 +00:00
|
|
|
def run_autoapi(app):
|
2015-04-23 20:31:03 +00:00
|
|
|
"""
|
|
|
|
Load AutoAPI data from the filesystem.
|
|
|
|
"""
|
|
|
|
|
2015-03-27 19:50:56 +00:00
|
|
|
if not app.config.autoapi_dir:
|
2015-04-08 05:54:53 +00:00
|
|
|
print "You must configure an autodapi_dir setting."
|
2015-03-27 19:50:56 +00:00
|
|
|
return
|
2015-06-10 18:35:54 +00:00
|
|
|
|
2015-03-27 19:50:56 +00:00
|
|
|
app.env.autoapi_data = []
|
2015-04-01 00:01:41 +00:00
|
|
|
|
2015-06-06 23:11:49 +00:00
|
|
|
mapping = {
|
|
|
|
'python': PythonDomain,
|
|
|
|
'dotnet': DotNetDomain,
|
|
|
|
'go': GoDomain,
|
|
|
|
'javascript': JavaScriptDomain,
|
|
|
|
}
|
|
|
|
|
|
|
|
domain = mapping[app.config.autoapi_type]
|
|
|
|
domain_obj = domain(app)
|
2015-06-10 18:35:54 +00:00
|
|
|
|
|
|
|
app.info(bold('[AutoAPI] ') + darkgreen('Loading Data'))
|
2015-06-06 23:11:49 +00:00
|
|
|
domain_obj.load(
|
|
|
|
pattern=app.config.autoapi_file_pattern,
|
|
|
|
dir=os.path.normpath(app.config.autoapi_dir),
|
|
|
|
ignore=app.config.autoapi_ignore,
|
|
|
|
)
|
2015-06-10 18:35:54 +00:00
|
|
|
|
|
|
|
app.info(bold('[AutoAPI] ') + darkgreen('Mapping Data'))
|
2015-06-06 23:11:49 +00:00
|
|
|
domain_obj.map()
|
2015-06-10 18:35:54 +00:00
|
|
|
|
|
|
|
app.info(bold('[AutoAPI] ') + darkgreen('Rendering Data'))
|
2015-06-06 23:11:49 +00:00
|
|
|
domain_obj.output_rst(
|
|
|
|
root=app.config.autoapi_root,
|
|
|
|
# TODO: Better way to determine suffix?
|
|
|
|
source_suffix=app.config.source_suffix[0]
|
|
|
|
)
|
2015-03-27 19:50:56 +00:00
|
|
|
|
|
|
|
|
2015-04-07 20:35:50 +00:00
|
|
|
def build_finished(app, exception):
|
|
|
|
if not app.config.autoapi_keep_files:
|
|
|
|
if app.verbosity > 1:
|
2015-06-10 18:35:54 +00:00
|
|
|
app.info(bold('[AutoAPI] ') + darkgreen('Cleaning generated .rst files'))
|
2015-04-07 20:35:50 +00:00
|
|
|
shutil.rmtree(app.config.autoapi_root)
|
|
|
|
|
|
|
|
|
2015-03-27 19:50:56 +00:00
|
|
|
def setup(app):
|
2015-06-10 18:35:54 +00:00
|
|
|
app.connect('builder-inited', run_autoapi)
|
2015-04-07 20:35:50 +00:00
|
|
|
app.connect('build-finished', build_finished)
|
2015-06-01 18:29:19 +00:00
|
|
|
app.add_config_value('autoapi_type', 'python', 'html')
|
2015-03-27 19:50:56 +00:00
|
|
|
app.add_config_value('autoapi_root', 'autoapi', 'html')
|
2015-04-01 00:01:41 +00:00
|
|
|
app.add_config_value('autoapi_ignore', ['*migrations*'], 'html')
|
2015-04-23 20:31:03 +00:00
|
|
|
app.add_config_value('autoapi_file_pattern', '*', 'html')
|
2015-04-01 00:01:41 +00:00
|
|
|
app.add_config_value('autoapi_dir', '', 'html')
|
2015-06-10 18:35:54 +00:00
|
|
|
app.add_config_value('autoapi_keep_files', False, 'html')
|
2015-06-10 17:33:18 +00:00
|
|
|
app.add_config_value('autoapi_template_dir', [], 'html')
|
2015-04-21 05:54:32 +00:00
|
|
|
app.add_stylesheet('autoapi.css')
|