From 0a457d10165a4bb555deea20d568eeb509276231 Mon Sep 17 00:00:00 2001 From: Eric Holscher Date: Fri, 17 Apr 2015 14:16:12 -0700 Subject: [PATCH] Move find_files to the base class, and recurse. --- autoapi/base.py | 24 ++++++++++++++++++++++++ autoapi/domains/dotnet.py | 11 ----------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/autoapi/base.py b/autoapi/base.py index 8eaa2f2..57bf100 100644 --- a/autoapi/base.py +++ b/autoapi/base.py @@ -1,4 +1,8 @@ +import os import yaml +import fnmatch + +from sphinx.util.console import darkgreen from .settings import env @@ -48,6 +52,7 @@ class UnknownType(AutoAPIBase): class AutoAPIDomain(object): + '''Base class for domain handling :param app: Sphinx application instance @@ -82,3 +87,22 @@ class AutoAPIDomain(object): def get_config(self, key): if self.app.config is not None: return getattr(self.app.config, key, None) + + def find_files(self): + '''Find YAML/JSON files to parse for namespace information''' + # TODO do an intelligent glob here, we're picking up too much + files_to_read = [] + absolute_dir = os.path.normpath(self.get_config('autoapi_dir')) + for root, dirnames, filenames in os.walk(absolute_dir): + for filename in fnmatch.filter(filenames, '*.yaml'): + if os.path.isabs(filename): + files_to_read.append(os.path.join(filename)) + else: + files_to_read.append(os.path.join(root, filename)) + + for _path in self.app.status_iterator( + files_to_read, + '[AutoAPI] Reading files... ', + darkgreen, + len(files_to_read)): + yield _path diff --git a/autoapi/domains/dotnet.py b/autoapi/domains/dotnet.py index ecb128f..8beb3ee 100644 --- a/autoapi/domains/dotnet.py +++ b/autoapi/domains/dotnet.py @@ -17,17 +17,6 @@ class DotNetDomain(AutoAPIDomain): :param app: Sphinx application passed in as part of the extension ''' - def find_files(self): - '''Find YAML/JSON files to parse for namespace information''' - # TODO do an intelligent glob here, we're picking up too much - files_to_read = os.listdir(self.get_config('autoapi_dir')) - for _path in self.app.status_iterator( - files_to_read, - '[AutoAPI] Reading files... ', - darkgreen, - len(files_to_read)): - yield _path - def create_class(self, data): '''Return instance of class based on Roslyn type property