Rename autoapi_dir to autoapi_dirs to support multiple

This commit is contained in:
Eric Holscher 2015-09-23 16:00:43 -07:00
parent 94757e5dfd
commit 4de4b376ca
12 changed files with 57 additions and 48 deletions

View File

@ -21,18 +21,25 @@ def run_autoapi(app):
Load AutoAPI data from the filesystem.
"""
if not app.config.autoapi_dir:
if not app.config.autoapi_dirs:
raise ExtensionError('You must configure an autodapi_dir setting')
# Make sure the paths are full
if os.path.isabs(app.config.autoapi_dir):
normalized_dir = app.config.autoapi_dir
normalized_dirs = []
for path in app.config.autoapi_dirs:
if os.path.isabs(path):
normalized_dirs.append(app.config.autoapi_dir)
else:
normalized_dir = os.path.normpath(os.path.join(app.confdir, app.config.autoapi_dir))
normalized_dirs.append(
os.path.normpath(os.path.join(app.confdir, path))
)
if not os.path.exists(normalized_dir):
for _dir in normalized_dirs:
if not os.path.exists(_dir):
raise ExtensionError(
'AutoAPI Directory not found. Please check your `autoapi_dir` setting.'
'AutoAPI Directory `{dir}` not found. Please check your `autoapi_dirs` setting.'.format(
dir=_dir
)
)
normalized_root = os.path.normpath(os.path.join(app.confdir, app.config.autoapi_root))
@ -55,7 +62,7 @@ def run_autoapi(app):
app.info(bold('[AutoAPI] ') + darkgreen('Loading Data'))
domain_obj.load(
patterns=file_patterns,
dir=normalized_dir,
dirs=normalized_dirs,
ignore=ignore_patterns,
)
@ -112,7 +119,7 @@ def setup(app):
app.add_config_value('autoapi_ignore', [], 'html')
app.add_config_value('autoapi_options', default_options, 'html')
app.add_config_value('autoapi_file_patterns', None, 'html')
app.add_config_value('autoapi_dir', 'autoapi', 'html')
app.add_config_value('autoapi_dirs', [], 'html')
app.add_config_value('autoapi_keep_files', False, 'html')
app.add_config_value('autoapi_add_toctree_entry', True, 'html')
app.add_config_value('autoapi_template_dir', [], 'html')

View File

@ -167,21 +167,22 @@ class SphinxMapperBase(object):
# Mapping of {namespace id -> Python Object}
self.top_level_objects = OrderedDict()
def load(self, patterns, dir, ignore=None, **kwargs):
def load(self, patterns, dirs, ignore=None, **kwargs):
'''
Load objects from the filesystem into the ``paths`` dictionary.
'''
for path in self.find_files(patterns=patterns, dir=dir, ignore=ignore):
for path in self.find_files(patterns=patterns, dirs=dirs, ignore=ignore):
data = self.read_file(path=path)
if data:
self.paths[path] = data
def find_files(self, patterns, dir, ignore):
def find_files(self, patterns, dirs, ignore):
if not ignore:
ignore = []
files_to_read = []
for root, dirnames, filenames in os.walk(dir):
for _dir in dirs:
for root, dirnames, filenames in os.walk(_dir):
for pattern in patterns:
for filename in fnmatch.filter(filenames, pattern):
skip = False

View File

@ -56,14 +56,14 @@ class DotNetSphinxMapper(SphinxMapperBase):
top_namespaces = {}
def load(self, patterns, dir, ignore=None, **kwargs):
def load(self, patterns, dirs, ignore=None, **kwargs):
'''
Load objects from the filesystem into the ``paths`` dictionary.
'''
raise_error = kwargs.get('raise_error', True)
all_files = set()
for _file in self.find_files(patterns=patterns, dir=dir, ignore=ignore):
for _file in self.find_files(patterns=patterns, dirs=dirs, ignore=ignore):
# Iterating for Sphinx output clarify
all_files.add(_file)
if all_files:
@ -88,7 +88,7 @@ class DotNetSphinxMapper(SphinxMapperBase):
if raise_error:
raise ExtensionError('Failure in docfx while generating AutoAPI output.')
# We now have yaml files
for xdoc_path in self.find_files(patterns=['*.yml'], dir='_api_', ignore=ignore):
for xdoc_path in self.find_files(patterns=['*.yml'], dirs=['_api_'], ignore=ignore):
data = self.read_file(path=xdoc_path)
if data:
self.paths[xdoc_path] = data

View File

@ -13,14 +13,15 @@ class GoSphinxMapper(SphinxMapperBase):
:param app: Sphinx application passed in as part of the extension
'''
def load(self, patterns, dir, ignore=None):
def load(self, patterns, dirs, ignore=None):
'''
Load objects from the filesystem into the ``paths`` dictionary.
'''
data = self.read_file(dir)
for _dir in dirs:
data = self.read_file(_dir)
if data:
self.paths[dir] = data
self.paths[_dir] = data
def read_file(self, path, **kwargs):
'''Read file input into memory, returning deserialized objects

View File

@ -20,11 +20,11 @@ autoapi_type = 'dotnet'
# Turn this on for debugging
# autoapi_keep_files = True
autoapi_dir = 'example/Identity/src/'
autoapi_dirs = ['example/Identity/src/']
import os
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
DIR = os.path.join(SITE_ROOT, autoapi_dir)
DIR = os.path.join(SITE_ROOT, autoapi_dirs[0])
if not os.path.exists(DIR):
os.system('git clone https://github.com/aspnet/Identity %s' % os.path.join(SITE_ROOT, 'example/Identity'))

View File

@ -18,5 +18,5 @@ htmlhelp_basename = 'goexampledoc'
extensions = ['autoapi.extension', 'sphinxcontrib.golangdomain']
autoapi_type = 'go'
autoapi_dir = 'example'
autoapi_dirs = ['example']
autoapi_file_pattern = '*.go'

View File

@ -17,5 +17,5 @@ html_static_path = ['_static']
htmlhelp_basename = 'jsexampledoc'
extensions = ['autoapi.extension']
autoapi_type = 'javascript'
autoapi_dir = 'example'
autoapi_dirs = ['example']
autoapi_file_pattern = '*.js'

View File

@ -17,5 +17,5 @@ html_static_path = ['_static']
htmlhelp_basename = 'pyexampledoc'
extensions = ['autoapi.extension']
autoapi_type = 'python'
autoapi_dir = 'example'
autoapi_dirs = ['example']
autoapi_file_pattern = '*.py'

View File

@ -17,7 +17,7 @@ html_static_path = ['_static']
htmlhelp_basename = 'pyexampledoc'
extensions = ['autoapi.extension']
autoapi_type = 'python'
autoapi_dir = 'example'
autoapi_dirs = ['example']
autoapi_file_pattern = '*.py'
autoapi_template_dir = 'template_overrides'

View File

@ -12,7 +12,7 @@ class DomainTests(unittest.TestCase):
def setUp(self):
'''Test setup'''
class _config(object):
autoapi_dir = '/tmp/autoapi/tmp'
autoapi_dirs = ['/tmp/autoapi/tmp']
autoapi_root = '/tmp/autoapi/root'
class _application(object):

View File

@ -75,7 +75,7 @@ class DotNetTests(LanguageIntegrationTests):
return json.load(open('../fixtures/dotnet.json'))
# Mock this because it's slow otherwise
def _dotnet_load(self, patterns, dir, ignore=[]):
def _dotnet_load(self, patterns, dirs, ignore=[]):
data = self.read_file(path='inmem')
self.paths['inmem'] = data

View File

@ -17,5 +17,5 @@ html_static_path = ['_static']
htmlhelp_basename = 'pyexampledoc'
extensions = ['autoapi.extension']
autoapi_type = 'python'
autoapi_dir = 'example'
autoapi_dirs = ['example']
autoapi_file_pattern = '*.py'