From e943f760851d193cc4d808deeef59d1a5f789c03 Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Tue, 5 May 2015 14:21:56 +0200 Subject: builddoc: allow to use fnmatch-style exclusion for autodoc This allows to use patterns such as heat.tests.* to exlude modules from autodoc genereation. Change-Id: Ibfc4161670fd9344da88c4a85a3aea992fcdf519 --- doc/source/index.rst | 3 ++- pbr/builddoc.py | 15 +++++++++------ pbr/tests/test_setup.py | 6 ++++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/doc/source/index.rst b/doc/source/index.rst index 8b4240c..5da6eba 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -298,7 +298,8 @@ should generate an index of modules using `sphinx-apidoc`. The `autodoc_index_modules` is a boolean option controlling whether pbr should itself generates documentation for Python modules of the project. By default, all found Python modules are included; some of them can be excluded by listing -them in `autodoc_exclude_modules`. +them in `autodoc_exclude_modules`. This list of modules can contains `fnmatch` +style pattern (e.g. `myapp.tests.*`) to exclude some modules. Additional Docs =============== diff --git a/pbr/builddoc.py b/pbr/builddoc.py index 7c9916b..3c9a9a1 100644 --- a/pbr/builddoc.py +++ b/pbr/builddoc.py @@ -15,6 +15,7 @@ # under the License. from distutils import log +import fnmatch import os import sys @@ -85,10 +86,12 @@ class LocalBuildDoc(setup_command.BuildDoc): if '.' not in pkg: for dirpath, dirnames, files in os.walk(pkg): _find_modules(modules, dirpath, files) - module_list = set(modules.keys()) - if excluded_modules is not None: - module_list -= set(excluded_modules) - module_list = sorted(module_list) + + def include(module): + return not any(fnmatch.fnmatch(module, pat) + for pat in excluded_modules) + + module_list = sorted(mod for mod in modules.keys() if include(mod)) autoindex_filename = os.path.join(source_dir, 'autoindex.rst') with open(autoindex_filename, 'w') as autoindex: autoindex.write(""".. toctree:: @@ -171,9 +174,9 @@ class LocalBuildDoc(setup_command.BuildDoc): self._sphinx_tree() if auto_index: self.generate_autoindex( - option_dict.get( + set(option_dict.get( "autodoc_exclude_modules", - [None, ""])[1].split()) + [None, ""])[1].split())) for builder in self.builders: self.builder = builder diff --git a/pbr/tests/test_setup.py b/pbr/tests/test_setup.py index 252658c..3aec296 100644 --- a/pbr/tests/test_setup.py +++ b/pbr/tests/test_setup.py @@ -195,6 +195,7 @@ class BuildSphinxTest(base.BaseTestCase): ('true_autodoc_caps_with_excludes', dict(has_opt=True, autodoc='True', has_autodoc=True, excludes="fake_package.fake_private_module\n" + "fake_package.another_fake_*\n" "fake_package.unknown_module")), ('true_autodoc_lower', dict(has_opt=True, autodoc='true', has_autodoc=True)), @@ -216,6 +217,7 @@ class BuildSphinxTest(base.BaseTestCase): "source_dir": ["a", "."]} pkg_fixture = fixtures.PythonPackage( "fake_package", [("fake_module.py", b""), + ("another_fake_module_for_testing.py", b""), ("fake_private_module.py", b"")]) self.useFixture(pkg_fixture) self.useFixture(base.DiveDir(pkg_fixture.base)) @@ -224,6 +226,7 @@ class BuildSphinxTest(base.BaseTestCase): self.distr.command_options["pbr"]["autodoc_exclude_modules"] = ( 'setup.cfg', "fake_package.fake_private_module\n" + "fake_package.another_fake_*\n" "fake_package.unknown_module") if self.has_opt: options = self.distr.command_options["pbr"] @@ -245,6 +248,9 @@ class BuildSphinxTest(base.BaseTestCase): assertion( os.path.exists( "api/fake_package.fake_private_module.rst")) + assertion( + os.path.exists( + "api/fake_package.another_fake_module_for_testing.rst")) def test_builders_config(self): build_doc = packaging.LocalBuildDoc(self.distr) -- cgit v1.2.1