From 0d6bfaf2e3f839704f07b265ba81e224936a2b49 Mon Sep 17 00:00:00 2001 From: David Stanek Date: Tue, 9 Sep 2014 20:25:27 +0000 Subject: [PATCH] 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 --- pbr/packaging.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/pbr/packaging.py b/pbr/packaging.py index 412d5911..bae75709 100644 --- a/pbr/packaging.py +++ b/pbr/packaging.py @@ -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'