Merge "builddoc: allow to use fnmatch-style exclusion for autodoc"
This commit is contained in:
commit
dceb9e56dd
|
@ -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
|
||||
===============
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue