From 7ad49d5756901a1e47f79fd9ec15e3f85cc582ce Mon Sep 17 00:00:00 2001 From: Georg Brandl Date: Fri, 2 May 2008 09:15:59 +0000 Subject: [PATCH] Add exclude_dirs config value. --- CHANGES | 3 +++ doc/config.rst | 51 +++++++++++++++++++++++------------------ sphinx/config.py | 1 + sphinx/environment.py | 7 +++--- sphinx/quickstart.py | 4 ++++ sphinx/util/__init__.py | 8 ++++--- 6 files changed, 46 insertions(+), 28 deletions(-) diff --git a/CHANGES b/CHANGES index 600d9904b..63ba8d14d 100644 --- a/CHANGES +++ b/CHANGES @@ -7,6 +7,9 @@ New features added * If the `pygments_style` config value contains a dot it's treated as the import path of a custom Pygments style class. +* A new config value, `exclude_dirs`, can be used to exclude whole + directories from the search for source files. + Bugs fixed ---------- diff --git a/doc/config.rst b/doc/config.rst index 162ed9144..cc6f7c338 100644 --- a/doc/config.rst +++ b/doc/config.rst @@ -57,11 +57,6 @@ General configuration The configuration file itself can be an extension; for that, you only need to provide a :func:`setup` function in it. -.. confval:: templates_path - - A list of paths that contain extra templates (or templates that overwrite - builtin templates). - .. confval:: source_suffix The file name extension of source files. Only files with this suffix will be @@ -113,6 +108,35 @@ General configuration toctree. Use this setting to suppress the warning that is normally emitted in that case. +.. confval:: exclude_dirs + + A list of directory names, relative to the source directory, that are to be + excluded from the search for source files. + + .. versionadded:: 0.2.1 + +.. confval:: pygments_style + + The style name to use for Pygments highlighting of source code. Default is + ``'sphinx'``, which is a builtin style designed to match Sphinx' default + style. + + .. versionchanged:: 0.2.1 + If the value is a fully-qualified name of a custom Pygments style class, + this is then used as custom style. + +.. confval:: templates_path + + A list of paths that contain extra templates (or templates that overwrite + builtin templates). + +.. confval:: template_bridge + + A string with the fully-qualified name of a callable (or simply a class) that + returns an instance of :class:`~sphinx.application.TemplateBridge`. This + instance is then used to render HTML documents, and possibly the output of + other builders (currently the changes builder). + .. confval:: add_function_parentheses A boolean that decides whether parentheses are appended to function and @@ -130,23 +154,6 @@ General configuration A boolean that decides whether :dir:`moduleauthor` and :dir:`sectionauthor` directives produce any output in the built files. -.. confval:: pygments_style - - The style name to use for Pygments highlighting of source code. Default is - ``'sphinx'``, which is a builtin style designed to match Sphinx' default - style. - - .. versionchanged:: 0.2.1 - If the value is a fully-qualified name of a custom Pygments style class, - this is then used as custom style. - -.. confval:: template_bridge - - A string with the fully-qualified name of a callable (or simply a class) that - returns an instance of :class:`~sphinx.application.TemplateBridge`. This - instance is then used to render HTML documents, and possibly the output of - other builders (currently the changes builder). - .. _html-options: diff --git a/sphinx/config.py b/sphinx/config.py index ed2204de4..12675dfcb 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -38,6 +38,7 @@ class Config(object): master_doc = ('contents', True), source_suffix = ('.rst', True), unused_docs = ([], True), + exclude_dirs = ([], True), add_function_parentheses = (True, True), add_module_names = (True, True), show_authors = (False, True), diff --git a/sphinx/environment.py b/sphinx/environment.py index a7b0931d8..3a226607a 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -325,9 +325,10 @@ class BuildEnvironment: """ Find all source files in the source dir and put them in self.found_docs. """ - self.found_docs = set(get_matching_docs(self.srcdir, config.source_suffix, - exclude=set(config.unused_docs), - prune=['_sources'])) + exclude_dirs = [d.replace(SEP, path.sep) for d in config.exclude_dirs] + self.found_docs = set(get_matching_docs( + self.srcdir, config.source_suffix, exclude_docs=set(config.unused_docs), + exclude_dirs=exclude_dirs, prune_dirs=['_sources'])) def get_outdated_files(self, config_changed): """ diff --git a/sphinx/quickstart.py b/sphinx/quickstart.py index 624946c5b..a825d047e 100644 --- a/sphinx/quickstart.py +++ b/sphinx/quickstart.py @@ -73,6 +73,10 @@ today_fmt = '%%B %%d, %%Y' # List of documents that shouldn't be included in the build. #unused_docs = [] +# List of directories, relative to source directories, that shouldn't be searched +# for source files. +#exclude_dirs = [] + # If true, '()' will be appended to :func: etc. cross-reference text. #add_function_parentheses = True diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index 94ca66843..762179b0b 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -74,7 +74,7 @@ def walk(top, topdown=True, followlinks=False): yield top, dirs, nondirs -def get_matching_docs(dirname, suffix, exclude=(), prune=()): +def get_matching_docs(dirname, suffix, exclude_docs=(), exclude_dirs=(), prune_dirs=()): """ Get all file names (without suffix) matching a suffix in a directory, recursively. @@ -86,9 +86,11 @@ def get_matching_docs(dirname, suffix, exclude=(), prune=()): dirname = path.normpath(path.abspath(dirname)) dirlen = len(dirname) + 1 # exclude slash for root, dirs, files in walk(dirname, followlinks=True): + if root[dirlen:] in exclude_dirs: + continue dirs.sort() files.sort() - for prunedir in prune: + for prunedir in prune_dirs: if prunedir in dirs: dirs.remove(prunedir) for sfile in files: @@ -96,7 +98,7 @@ def get_matching_docs(dirname, suffix, exclude=(), prune=()): continue qualified_name = path.join(root[dirlen:], sfile[:-len(suffix)]) qualified_name = qualified_name.replace(os.path.sep, SEP) - if qualified_name in exclude: + if qualified_name in exclude_docs: continue yield qualified_name