diff options
author | Jenkins <jenkins@review.openstack.org> | 2015-06-07 04:06:15 +0000 |
---|---|---|
committer | Gerrit Code Review <review@openstack.org> | 2015-06-07 04:06:15 +0000 |
commit | dceb9e56dd6ef95e5a188aaee01a43602a569a2c (patch) | |
tree | 3a3229cc9d8c999cce7b8292d8400d3289359b20 | |
parent | d8ee71542efcb0e309e6c75c33b11c45127ede48 (diff) | |
parent | e943f760851d193cc4d808deeef59d1a5f789c03 (diff) | |
download | pbr-dceb9e56dd6ef95e5a188aaee01a43602a569a2c.tar.gz |
Merge "builddoc: allow to use fnmatch-style exclusion for autodoc"1.1.0
-rw-r--r-- | doc/source/index.rst | 3 | ||||
-rw-r--r-- | pbr/builddoc.py | 15 | ||||
-rw-r--r-- | 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 3045414..331a2d3 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -302,7 +302,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 60f2afd..7468f31 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 @@ -84,10 +85,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:: @@ -170,9 +173,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) |