diff options
| author | Georg Brandl <georg@python.org> | 2010-01-06 15:48:39 +0100 |
|---|---|---|
| committer | Georg Brandl <georg@python.org> | 2010-01-06 15:48:39 +0100 |
| commit | d8ecadd172a7b6bb42540da4543301279846d521 (patch) | |
| tree | 0f9148fe0ec29595e684696ae45f9f2818598448 /sphinx | |
| parent | 818b990fcd3fbcfddb5d8fb84e5f23ffc75ed1ed (diff) | |
| download | sphinx-d8ecadd172a7b6bb42540da4543301279846d521.tar.gz | |
Add new universal config value ``exclude_patterns``, with glob-style exclude patterns.
This makes the old ``unused_docs``, ``exclude_trees`` and ``exclude_dirnames`` obsolete.
Diffstat (limited to 'sphinx')
| -rw-r--r-- | sphinx/config.py | 2 | ||||
| -rw-r--r-- | sphinx/environment.py | 11 | ||||
| -rw-r--r-- | sphinx/quickstart.py | 13 | ||||
| -rw-r--r-- | sphinx/util/__init__.py | 60 |
4 files changed, 48 insertions, 38 deletions
diff --git a/sphinx/config.py b/sphinx/config.py index b86083f7..5fe3f63f 100644 --- a/sphinx/config.py +++ b/sphinx/config.py @@ -38,6 +38,8 @@ class Config(object): master_doc = ('contents', 'env'), source_suffix = ('.rst', 'env'), source_encoding = ('utf-8-sig', 'env'), + exclude_patterns = ([], 'env'), + # the next three are all deprecated now unused_docs = ([], 'env'), exclude_trees = ([], 'env'), exclude_dirnames = ([], 'env'), diff --git a/sphinx/environment.py b/sphinx/environment.py index 77c84bc6..781d8b5c 100644 --- a/sphinx/environment.py +++ b/sphinx/environment.py @@ -393,12 +393,13 @@ class BuildEnvironment: """ Find all source files in the source dir and put them in self.found_docs. """ - exclude_trees = [d.replace(SEP, path.sep) for d in config.exclude_trees] + patterns = config.exclude_patterns[:] + patterns += config.exclude_trees + patterns += [d + config.source_suffix for d in config.unused_docs] + patterns += ['**/' + d for d in config.exclude_dirnames] + patterns += ['**/_sources'] self.found_docs = set(get_matching_docs( - self.srcdir, config.source_suffix, - exclude_docs=set(config.unused_docs), - exclude_trees=exclude_trees, - exclude_dirnames=['_sources'] + config.exclude_dirnames)) + self.srcdir, config.source_suffix, exclude_patterns=patterns)) def get_outdated_files(self, config_changed): """ diff --git a/sphinx/quickstart.py b/sphinx/quickstart.py index 51103b5a..faea2c2e 100644 --- a/sphinx/quickstart.py +++ b/sphinx/quickstart.py @@ -84,12 +84,9 @@ release = '%(release_str)s' # Else, today_fmt is used as the format for a strftime call. #today_fmt = '%%B %%d, %%Y' -# List of documents that shouldn't be included in the build. -#unused_docs = [] - -# List of directories, relative to source directory, that shouldn't be searched -# for source files. -exclude_trees = [%(exclude_trees)s] +# List of patterns, relative to source directory, that match files and +# directories to ignore when looking for source files. +exclude_patterns = [%(exclude_patterns)s] # The reST default role (used for this markup: `text`) to use for all documents. #default_role = None @@ -743,10 +740,10 @@ directly.''' mkdir_p(srcdir) if d['sep']: builddir = path.join(d['path'], 'build') - d['exclude_trees'] = '' + d['exclude_patterns'] = '' else: builddir = path.join(srcdir, d['dot'] + 'build') - d['exclude_trees'] = repr(d['dot'] + 'build') + d['exclude_patterns'] = repr(d['dot'] + 'build') mkdir_p(builddir) mkdir_p(path.join(srcdir, d['dot'] + 'templates')) mkdir_p(path.join(srcdir, d['dot'] + 'static')) diff --git a/sphinx/util/__init__.py b/sphinx/util/__init__.py index e04137ee..0d88ddea 100644 --- a/sphinx/util/__init__.py +++ b/sphinx/util/__init__.py @@ -101,38 +101,48 @@ def walk(top, topdown=True, followlinks=False): yield top, dirs, nondirs -def get_matching_docs(dirname, suffix, exclude_docs=(), exclude_dirs=(), - exclude_trees=(), exclude_dirnames=()): +def get_matching_files(dirname, exclude_patterns=()): """ - Get all file names (without suffix) matching a suffix in a - directory, recursively. + Get all file names in a directory, recursively. - Exclude docs in *exclude_docs*, exclude dirs in *exclude_dirs*, - prune dirs in *exclude_trees*, prune dirnames in *exclude_dirnames*. + Exclude files and dirs matching a pattern in *exclude_patterns*. """ - pattern = '*' + suffix # dirname is a normalized absolute path. dirname = path.normpath(path.abspath(dirname)) - dirlen = len(dirname) + 1 # exclude slash + dirlen = len(dirname) + 1 # exclude final os.path.sep + + matchers = [re.compile(_translate_pattern(pat)).match + for pat in exclude_patterns] + for root, dirs, files in walk(dirname, followlinks=True): - if root[dirlen:] in exclude_dirs: - continue - if root[dirlen:] in exclude_trees: - del dirs[:] + relativeroot = root[dirlen:] + + qdirs = enumerate(path.join(relativeroot, dir).replace(os.path.sep, SEP) + for dir in dirs) + qfiles = enumerate(path.join(relativeroot, file).replace(os.path.sep, SEP) + for file in files) + for matcher in matchers: + qdirs = [entry for entry in qdirs if not matcher(entry[1])] + qfiles = [entry for entry in qfiles if not matcher(entry[1])] + + dirs[:] = sorted(dirs[i] for (i, _) in qdirs) + + for i, filename in sorted(qfiles): + yield filename + + +def get_matching_docs(dirname, suffix, exclude_patterns=()): + """ + Get all file names (without suffix) matching a suffix in a + directory, recursively. + + Exclude files and dirs matching a pattern in *exclude_patterns*. + """ + suffixpattern = '*' + suffix + for filename in get_matching_files(dirname, exclude_patterns): + if not fnmatch.fnmatch(filename, suffixpattern): continue - dirs.sort() - files.sort() - for prunedir in exclude_dirnames: - if prunedir in dirs: - dirs.remove(prunedir) - for sfile in files: - if not fnmatch.fnmatch(sfile, pattern): - continue - qualified_name = path.join(root[dirlen:], sfile[:-len(suffix)]) - qualified_name = qualified_name.replace(os.path.sep, SEP) - if qualified_name in exclude_docs: - continue - yield qualified_name + yield filename[:-len(suffix)] def mtimes_of_files(dirnames, suffix): |
