Adds option for excluding files from autodoc trees

The arguments originally being passed into sphinx.apidoc specify '.'
as the path to index. Unfortunately this includes the setup.py module.
This causes Sphinx to complain or break depending on the configuration.

This patch ignores setup.py by default and allows the project to
override it in their setup.cfg.

Change-Id: I7c164d42a096ba1a0daf314a689cc3252ca81c49
Closes-Bug: #1260495
This commit is contained in:
David Stanek 2014-09-09 20:25:27 +00:00
parent 4cecec5c78
commit 0d6bfaf2e3
1 changed files with 18 additions and 1 deletions

View File

@ -687,7 +687,8 @@ try:
def _sphinx_tree(self):
source_dir = self._get_source_dir()
apidoc.main(['apidoc', '.', '-H', 'Modules', '-o', source_dir])
cmd = ['apidoc', '.', '-H', 'Modules', '-o', source_dir]
apidoc.main(cmd + self.autodoc_tree_excludes)
def _sphinx_run(self):
if not self.verbose:
@ -755,6 +756,14 @@ try:
else:
setup_command.BuildDoc.run(self)
def initialize_options(self):
# Not a new style class, super keyword does not work.
setup_command.BuildDoc.initialize_options(self)
# NOTE(dstanek): exclude setup.py from the autodoc tree index
# builds because all projects will have an issue with it
self.autodoc_tree_excludes = ['setup.py']
def finalize_options(self):
# Not a new style class, super keyword does not work.
setup_command.BuildDoc.finalize_options(self)
@ -762,6 +771,14 @@ try:
if not isinstance(self.builders, list) and self.builders:
self.builders = self.builders.split(',')
# NOTE(dstanek): check for autodoc tree exclusion overrides
# in the setup.cfg
opt = 'autodoc_tree_excludes'
option_dict = self.distribution.get_option_dict('pbr')
if opt in option_dict:
self.autodoc_tree_excludes = option_dict[opt][1]
self.ensure_string_list(opt)
class LocalBuildLatex(LocalBuildDoc):
builders = ['latex']
command_name = 'build_sphinx_latex'