mirror of
https://github.com/readthedocs/sphinx-autoapi
synced 2024-11-11 19:10:58 +00:00
Rename autoapi_dir
to autoapi_dirs
to support multiple
This commit is contained in:
parent
94757e5dfd
commit
4de4b376ca
@ -21,19 +21,26 @@ def run_autoapi(app):
|
|||||||
Load AutoAPI data from the filesystem.
|
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')
|
raise ExtensionError('You must configure an autodapi_dir setting')
|
||||||
|
|
||||||
# Make sure the paths are full
|
# Make sure the paths are full
|
||||||
if os.path.isabs(app.config.autoapi_dir):
|
normalized_dirs = []
|
||||||
normalized_dir = app.config.autoapi_dir
|
for path in app.config.autoapi_dirs:
|
||||||
else:
|
if os.path.isabs(path):
|
||||||
normalized_dir = os.path.normpath(os.path.join(app.confdir, app.config.autoapi_dir))
|
normalized_dirs.append(app.config.autoapi_dir)
|
||||||
|
else:
|
||||||
|
normalized_dirs.append(
|
||||||
|
os.path.normpath(os.path.join(app.confdir, path))
|
||||||
|
)
|
||||||
|
|
||||||
if not os.path.exists(normalized_dir):
|
for _dir in normalized_dirs:
|
||||||
raise ExtensionError(
|
if not os.path.exists(_dir):
|
||||||
'AutoAPI Directory not found. Please check your `autoapi_dir` setting.'
|
raise ExtensionError(
|
||||||
)
|
'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))
|
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'))
|
app.info(bold('[AutoAPI] ') + darkgreen('Loading Data'))
|
||||||
domain_obj.load(
|
domain_obj.load(
|
||||||
patterns=file_patterns,
|
patterns=file_patterns,
|
||||||
dir=normalized_dir,
|
dirs=normalized_dirs,
|
||||||
ignore=ignore_patterns,
|
ignore=ignore_patterns,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -112,7 +119,7 @@ def setup(app):
|
|||||||
app.add_config_value('autoapi_ignore', [], 'html')
|
app.add_config_value('autoapi_ignore', [], 'html')
|
||||||
app.add_config_value('autoapi_options', default_options, 'html')
|
app.add_config_value('autoapi_options', default_options, 'html')
|
||||||
app.add_config_value('autoapi_file_patterns', None, '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_keep_files', False, 'html')
|
||||||
app.add_config_value('autoapi_add_toctree_entry', True, 'html')
|
app.add_config_value('autoapi_add_toctree_entry', True, 'html')
|
||||||
app.add_config_value('autoapi_template_dir', [], 'html')
|
app.add_config_value('autoapi_template_dir', [], 'html')
|
||||||
|
@ -167,40 +167,41 @@ class SphinxMapperBase(object):
|
|||||||
# Mapping of {namespace id -> Python Object}
|
# Mapping of {namespace id -> Python Object}
|
||||||
self.top_level_objects = OrderedDict()
|
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.
|
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)
|
data = self.read_file(path=path)
|
||||||
if data:
|
if data:
|
||||||
self.paths[path] = data
|
self.paths[path] = data
|
||||||
|
|
||||||
def find_files(self, patterns, dir, ignore):
|
def find_files(self, patterns, dirs, ignore):
|
||||||
if not ignore:
|
if not ignore:
|
||||||
ignore = []
|
ignore = []
|
||||||
files_to_read = []
|
files_to_read = []
|
||||||
for root, dirnames, filenames in os.walk(dir):
|
for _dir in dirs:
|
||||||
for pattern in patterns:
|
for root, dirnames, filenames in os.walk(_dir):
|
||||||
for filename in fnmatch.filter(filenames, pattern):
|
for pattern in patterns:
|
||||||
skip = False
|
for filename in fnmatch.filter(filenames, pattern):
|
||||||
|
skip = False
|
||||||
|
|
||||||
# Skip ignored files
|
# Skip ignored files
|
||||||
for ignore_pattern in ignore:
|
for ignore_pattern in ignore:
|
||||||
if fnmatch.fnmatch(os.path.join(root, filename), ignore_pattern):
|
if fnmatch.fnmatch(os.path.join(root, filename), ignore_pattern):
|
||||||
self.app.info(
|
self.app.info(
|
||||||
bold('[AutoAPI] ') + darkgreen("Ignoring %s/%s" % (root, filename))
|
bold('[AutoAPI] ') + darkgreen("Ignoring %s/%s" % (root, filename))
|
||||||
)
|
)
|
||||||
skip = True
|
skip = True
|
||||||
|
|
||||||
if skip:
|
if skip:
|
||||||
continue
|
continue
|
||||||
# Make sure the path is full
|
# Make sure the path is full
|
||||||
if os.path.isabs(filename):
|
if os.path.isabs(filename):
|
||||||
files_to_read.append(filename)
|
files_to_read.append(filename)
|
||||||
else:
|
else:
|
||||||
files_to_read.append(os.path.join(root, filename))
|
files_to_read.append(os.path.join(root, filename))
|
||||||
|
|
||||||
for _path in self.app.status_iterator(
|
for _path in self.app.status_iterator(
|
||||||
files_to_read,
|
files_to_read,
|
||||||
|
@ -56,14 +56,14 @@ class DotNetSphinxMapper(SphinxMapperBase):
|
|||||||
|
|
||||||
top_namespaces = {}
|
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.
|
Load objects from the filesystem into the ``paths`` dictionary.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
raise_error = kwargs.get('raise_error', True)
|
raise_error = kwargs.get('raise_error', True)
|
||||||
all_files = set()
|
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
|
# Iterating for Sphinx output clarify
|
||||||
all_files.add(_file)
|
all_files.add(_file)
|
||||||
if all_files:
|
if all_files:
|
||||||
@ -88,7 +88,7 @@ class DotNetSphinxMapper(SphinxMapperBase):
|
|||||||
if raise_error:
|
if raise_error:
|
||||||
raise ExtensionError('Failure in docfx while generating AutoAPI output.')
|
raise ExtensionError('Failure in docfx while generating AutoAPI output.')
|
||||||
# We now have yaml files
|
# 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)
|
data = self.read_file(path=xdoc_path)
|
||||||
if data:
|
if data:
|
||||||
self.paths[xdoc_path] = data
|
self.paths[xdoc_path] = data
|
||||||
|
@ -13,14 +13,15 @@ class GoSphinxMapper(SphinxMapperBase):
|
|||||||
:param app: Sphinx application passed in as part of the extension
|
: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.
|
Load objects from the filesystem into the ``paths`` dictionary.
|
||||||
|
|
||||||
'''
|
'''
|
||||||
data = self.read_file(dir)
|
for _dir in dirs:
|
||||||
if data:
|
data = self.read_file(_dir)
|
||||||
self.paths[dir] = data
|
if data:
|
||||||
|
self.paths[_dir] = data
|
||||||
|
|
||||||
def read_file(self, path, **kwargs):
|
def read_file(self, path, **kwargs):
|
||||||
'''Read file input into memory, returning deserialized objects
|
'''Read file input into memory, returning deserialized objects
|
||||||
|
@ -20,11 +20,11 @@ autoapi_type = 'dotnet'
|
|||||||
# Turn this on for debugging
|
# Turn this on for debugging
|
||||||
# autoapi_keep_files = True
|
# autoapi_keep_files = True
|
||||||
|
|
||||||
autoapi_dir = 'example/Identity/src/'
|
autoapi_dirs = ['example/Identity/src/']
|
||||||
|
|
||||||
import os
|
import os
|
||||||
|
|
||||||
SITE_ROOT = os.path.dirname(os.path.realpath(__file__))
|
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):
|
if not os.path.exists(DIR):
|
||||||
os.system('git clone https://github.com/aspnet/Identity %s' % os.path.join(SITE_ROOT, 'example/Identity'))
|
os.system('git clone https://github.com/aspnet/Identity %s' % os.path.join(SITE_ROOT, 'example/Identity'))
|
||||||
|
@ -18,5 +18,5 @@ htmlhelp_basename = 'goexampledoc'
|
|||||||
extensions = ['autoapi.extension', 'sphinxcontrib.golangdomain']
|
extensions = ['autoapi.extension', 'sphinxcontrib.golangdomain']
|
||||||
|
|
||||||
autoapi_type = 'go'
|
autoapi_type = 'go'
|
||||||
autoapi_dir = 'example'
|
autoapi_dirs = ['example']
|
||||||
autoapi_file_pattern = '*.go'
|
autoapi_file_pattern = '*.go'
|
||||||
|
@ -17,5 +17,5 @@ html_static_path = ['_static']
|
|||||||
htmlhelp_basename = 'jsexampledoc'
|
htmlhelp_basename = 'jsexampledoc'
|
||||||
extensions = ['autoapi.extension']
|
extensions = ['autoapi.extension']
|
||||||
autoapi_type = 'javascript'
|
autoapi_type = 'javascript'
|
||||||
autoapi_dir = 'example'
|
autoapi_dirs = ['example']
|
||||||
autoapi_file_pattern = '*.js'
|
autoapi_file_pattern = '*.js'
|
@ -17,5 +17,5 @@ html_static_path = ['_static']
|
|||||||
htmlhelp_basename = 'pyexampledoc'
|
htmlhelp_basename = 'pyexampledoc'
|
||||||
extensions = ['autoapi.extension']
|
extensions = ['autoapi.extension']
|
||||||
autoapi_type = 'python'
|
autoapi_type = 'python'
|
||||||
autoapi_dir = 'example'
|
autoapi_dirs = ['example']
|
||||||
autoapi_file_pattern = '*.py'
|
autoapi_file_pattern = '*.py'
|
@ -17,7 +17,7 @@ html_static_path = ['_static']
|
|||||||
htmlhelp_basename = 'pyexampledoc'
|
htmlhelp_basename = 'pyexampledoc'
|
||||||
extensions = ['autoapi.extension']
|
extensions = ['autoapi.extension']
|
||||||
autoapi_type = 'python'
|
autoapi_type = 'python'
|
||||||
autoapi_dir = 'example'
|
autoapi_dirs = ['example']
|
||||||
autoapi_file_pattern = '*.py'
|
autoapi_file_pattern = '*.py'
|
||||||
autoapi_template_dir = 'template_overrides'
|
autoapi_template_dir = 'template_overrides'
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@ class DomainTests(unittest.TestCase):
|
|||||||
def setUp(self):
|
def setUp(self):
|
||||||
'''Test setup'''
|
'''Test setup'''
|
||||||
class _config(object):
|
class _config(object):
|
||||||
autoapi_dir = '/tmp/autoapi/tmp'
|
autoapi_dirs = ['/tmp/autoapi/tmp']
|
||||||
autoapi_root = '/tmp/autoapi/root'
|
autoapi_root = '/tmp/autoapi/root'
|
||||||
|
|
||||||
class _application(object):
|
class _application(object):
|
||||||
|
@ -75,7 +75,7 @@ class DotNetTests(LanguageIntegrationTests):
|
|||||||
return json.load(open('../fixtures/dotnet.json'))
|
return json.load(open('../fixtures/dotnet.json'))
|
||||||
|
|
||||||
# Mock this because it's slow otherwise
|
# 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')
|
data = self.read_file(path='inmem')
|
||||||
self.paths['inmem'] = data
|
self.paths['inmem'] = data
|
||||||
|
|
||||||
|
@ -17,5 +17,5 @@ html_static_path = ['_static']
|
|||||||
htmlhelp_basename = 'pyexampledoc'
|
htmlhelp_basename = 'pyexampledoc'
|
||||||
extensions = ['autoapi.extension']
|
extensions = ['autoapi.extension']
|
||||||
autoapi_type = 'python'
|
autoapi_type = 'python'
|
||||||
autoapi_dir = 'example'
|
autoapi_dirs = ['example']
|
||||||
autoapi_file_pattern = '*.py'
|
autoapi_file_pattern = '*.py'
|
||||||
|
Loading…
Reference in New Issue
Block a user