Add exclude_dirs config value.

This commit is contained in:
Georg Brandl 2008-05-02 09:15:59 +00:00
parent 9050ba428e
commit 7ad49d5756
6 changed files with 46 additions and 28 deletions

View File

@ -7,6 +7,9 @@ New features added
* If the `pygments_style` config value contains a dot it's treated as the * If the `pygments_style` config value contains a dot it's treated as the
import path of a custom Pygments style class. 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 Bugs fixed
---------- ----------

View File

@ -57,11 +57,6 @@ General configuration
The configuration file itself can be an extension; for that, you only need to The configuration file itself can be an extension; for that, you only need to
provide a :func:`setup` function in it. 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 .. confval:: source_suffix
The file name extension of source files. Only files with this suffix will be 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 toctree. Use this setting to suppress the warning that is normally emitted
in that case. 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 .. confval:: add_function_parentheses
A boolean that decides whether parentheses are appended to function and 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` A boolean that decides whether :dir:`moduleauthor` and :dir:`sectionauthor`
directives produce any output in the built files. 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: .. _html-options:

View File

@ -38,6 +38,7 @@ class Config(object):
master_doc = ('contents', True), master_doc = ('contents', True),
source_suffix = ('.rst', True), source_suffix = ('.rst', True),
unused_docs = ([], True), unused_docs = ([], True),
exclude_dirs = ([], True),
add_function_parentheses = (True, True), add_function_parentheses = (True, True),
add_module_names = (True, True), add_module_names = (True, True),
show_authors = (False, True), show_authors = (False, True),

View File

@ -325,9 +325,10 @@ class BuildEnvironment:
""" """
Find all source files in the source dir and put them in self.found_docs. 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_dirs = [d.replace(SEP, path.sep) for d in config.exclude_dirs]
exclude=set(config.unused_docs), self.found_docs = set(get_matching_docs(
prune=['_sources'])) 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): def get_outdated_files(self, config_changed):
""" """

View File

@ -73,6 +73,10 @@ today_fmt = '%%B %%d, %%Y'
# List of documents that shouldn't be included in the build. # List of documents that shouldn't be included in the build.
#unused_docs = [] #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. # If true, '()' will be appended to :func: etc. cross-reference text.
#add_function_parentheses = True #add_function_parentheses = True

View File

@ -74,7 +74,7 @@ def walk(top, topdown=True, followlinks=False):
yield top, dirs, nondirs 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 Get all file names (without suffix) matching a suffix in a
directory, recursively. directory, recursively.
@ -86,9 +86,11 @@ def get_matching_docs(dirname, suffix, exclude=(), prune=()):
dirname = path.normpath(path.abspath(dirname)) dirname = path.normpath(path.abspath(dirname))
dirlen = len(dirname) + 1 # exclude slash dirlen = len(dirname) + 1 # exclude slash
for root, dirs, files in walk(dirname, followlinks=True): for root, dirs, files in walk(dirname, followlinks=True):
if root[dirlen:] in exclude_dirs:
continue
dirs.sort() dirs.sort()
files.sort() files.sort()
for prunedir in prune: for prunedir in prune_dirs:
if prunedir in dirs: if prunedir in dirs:
dirs.remove(prunedir) dirs.remove(prunedir)
for sfile in files: for sfile in files:
@ -96,7 +98,7 @@ def get_matching_docs(dirname, suffix, exclude=(), prune=()):
continue continue
qualified_name = path.join(root[dirlen:], sfile[:-len(suffix)]) qualified_name = path.join(root[dirlen:], sfile[:-len(suffix)])
qualified_name = qualified_name.replace(os.path.sep, SEP) qualified_name = qualified_name.replace(os.path.sep, SEP)
if qualified_name in exclude: if qualified_name in exclude_docs:
continue continue
yield qualified_name yield qualified_name