From 4de4b376ca0d20c9b5468ef775a0fd13cb84036b Mon Sep 17 00:00:00 2001 From: Eric Holscher Date: Wed, 23 Sep 2015 16:00:43 -0700 Subject: [PATCH] Rename `autoapi_dir` to `autoapi_dirs` to support multiple --- autoapi/extension.py | 29 +++++++++++++-------- autoapi/mappers/base.py | 47 ++++++++++++++++++----------------- autoapi/mappers/dotnet.py | 6 ++--- autoapi/mappers/go.py | 9 ++++--- tests/dotnetexample/conf.py | 4 +-- tests/goexample/conf.py | 2 +- tests/jsexample/conf.py | 2 +- tests/pyexample/conf.py | 2 +- tests/templateexample/conf.py | 2 +- tests/test_domains.py | 2 +- tests/test_integration.py | 2 +- tests/toctreeexample/conf.py | 2 +- 12 files changed, 59 insertions(+), 50 deletions(-) diff --git a/autoapi/extension.py b/autoapi/extension.py index a3d2f61..f8c84d7 100644 --- a/autoapi/extension.py +++ b/autoapi/extension.py @@ -21,19 +21,26 @@ 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 - else: - normalized_dir = os.path.normpath(os.path.join(app.confdir, 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_dirs.append( + os.path.normpath(os.path.join(app.confdir, path)) + ) - if not os.path.exists(normalized_dir): - raise ExtensionError( - 'AutoAPI Directory not found. Please check your `autoapi_dir` setting.' - ) + for _dir in normalized_dirs: + if not os.path.exists(_dir): + 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)) @@ -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') diff --git a/autoapi/mappers/base.py b/autoapi/mappers/base.py index 12156be..5ae2cc0 100644 --- a/autoapi/mappers/base.py +++ b/autoapi/mappers/base.py @@ -167,40 +167,41 @@ 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 pattern in patterns: - for filename in fnmatch.filter(filenames, pattern): - skip = False - - # Skip ignored files - for ignore_pattern in ignore: - if fnmatch.fnmatch(os.path.join(root, filename), ignore_pattern): - self.app.info( - bold('[AutoAPI] ') + darkgreen("Ignoring %s/%s" % (root, filename)) - ) - skip = True - - if skip: - continue - # Make sure the path is full - if os.path.isabs(filename): - files_to_read.append(filename) - else: - files_to_read.append(os.path.join(root, filename)) + 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 + + # Skip ignored files + for ignore_pattern in ignore: + if fnmatch.fnmatch(os.path.join(root, filename), ignore_pattern): + self.app.info( + bold('[AutoAPI] ') + darkgreen("Ignoring %s/%s" % (root, filename)) + ) + skip = True + + if skip: + continue + # Make sure the path is full + if os.path.isabs(filename): + files_to_read.append(filename) + else: + files_to_read.append(os.path.join(root, filename)) for _path in self.app.status_iterator( files_to_read, diff --git a/autoapi/mappers/dotnet.py b/autoapi/mappers/dotnet.py index efdf10f..4905dd2 100644 --- a/autoapi/mappers/dotnet.py +++ b/autoapi/mappers/dotnet.py @@ -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 diff --git a/autoapi/mappers/go.py b/autoapi/mappers/go.py index 2ea8b36..bd5871f 100644 --- a/autoapi/mappers/go.py +++ b/autoapi/mappers/go.py @@ -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) - if data: - self.paths[dir] = data + for _dir in dirs: + data = self.read_file(_dir) + if data: + self.paths[_dir] = data def read_file(self, path, **kwargs): '''Read file input into memory, returning deserialized objects diff --git a/tests/dotnetexample/conf.py b/tests/dotnetexample/conf.py index db7b4a6..bce6ed1 100644 --- a/tests/dotnetexample/conf.py +++ b/tests/dotnetexample/conf.py @@ -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')) diff --git a/tests/goexample/conf.py b/tests/goexample/conf.py index 6df49b2..babb462 100644 --- a/tests/goexample/conf.py +++ b/tests/goexample/conf.py @@ -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' diff --git a/tests/jsexample/conf.py b/tests/jsexample/conf.py index 1875806..14a1bd2 100644 --- a/tests/jsexample/conf.py +++ b/tests/jsexample/conf.py @@ -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' \ No newline at end of file diff --git a/tests/pyexample/conf.py b/tests/pyexample/conf.py index 71485a7..73604c2 100644 --- a/tests/pyexample/conf.py +++ b/tests/pyexample/conf.py @@ -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' \ No newline at end of file diff --git a/tests/templateexample/conf.py b/tests/templateexample/conf.py index 15dc48b..94e45bf 100644 --- a/tests/templateexample/conf.py +++ b/tests/templateexample/conf.py @@ -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' diff --git a/tests/test_domains.py b/tests/test_domains.py index dd299ad..e3d42c7 100644 --- a/tests/test_domains.py +++ b/tests/test_domains.py @@ -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): diff --git a/tests/test_integration.py b/tests/test_integration.py index 798f1ad..cee218b 100644 --- a/tests/test_integration.py +++ b/tests/test_integration.py @@ -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 diff --git a/tests/toctreeexample/conf.py b/tests/toctreeexample/conf.py index d2edf89..a577f61 100644 --- a/tests/toctreeexample/conf.py +++ b/tests/toctreeexample/conf.py @@ -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'