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-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
|
|
|
|
|
|
|
|
|
|
|
def load_yaml(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
|
|
|
|
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)
|
|
|
|
app.info('[AutoAPI] Loading Data')
|
|
|
|
domain_obj.load(
|
|
|
|
pattern=app.config.autoapi_file_pattern,
|
|
|
|
dir=os.path.normpath(app.config.autoapi_dir),
|
|
|
|
ignore=app.config.autoapi_ignore,
|
|
|
|
)
|
|
|
|
app.info('[AutoAPI] Mapping Data')
|
|
|
|
domain_obj.map()
|
|
|
|
app.info('[AutoAPI] Rendering Data')
|
|
|
|
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:
|
|
|
|
print "Cleaning autoapi out"
|
|
|
|
shutil.rmtree(app.config.autoapi_root)
|
|
|
|
|
|
|
|
|
2015-03-27 19:50:56 +00:00
|
|
|
def setup(app):
|
|
|
|
app.connect('builder-inited', load_yaml)
|
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-04-07 20:35:50 +00:00
|
|
|
app.add_config_value('autoapi_keep_files', True, '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')
|