From 8aaf237382848dd2de370392cdb11c5f218a370e Mon Sep 17 00:00:00 2001 From: Doug Hellmann Date: Wed, 17 Jan 2018 14:42:48 -0500 Subject: [PATCH] future-proof invocation of apidoc Newer versions of Sphinx have moved the apidoc module into sphinx.ext and the API is slightly different (the function expects sys.argv[1:] instead of sys.argv[:]. So, figure out where we can import it from and set a flag so we can invoke it properly. See this change in sphinx for details: https://github.com/sphinx-doc/sphinx/commit/87630c8ae8bff8c0e23187676e6343d8903003a6 Change-Id: I8235968f8a474c9e6088d935d0868570b2917c07 Signed-off-by: Doug Hellmann --- pbr/builddoc.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/pbr/builddoc.py b/pbr/builddoc.py index cd75792e..9f619205 100644 --- a/pbr/builddoc.py +++ b/pbr/builddoc.py @@ -26,7 +26,18 @@ except ImportError: try: import sphinx - from sphinx import apidoc + # NOTE(dhellmann): Newer versions of Sphinx have moved the apidoc + # module into sphinx.ext and the API is slightly different (the + # function expects sys.argv[1:] instead of sys.argv[:]. So, figure + # out where we can import it from and set a flag so we can invoke + # it properly. See this change in sphinx for details: + # https://github.com/sphinx-doc/sphinx/commit/87630c8ae8bff8c0e23187676e6343d8903003a6 + try: + from sphinx.ext import apidoc + apidoc_use_padding = False + except ImportError: + from sphinx import apidoc + apidoc_use_padding = True from sphinx import application from sphinx import setup_command except Exception as e: @@ -119,7 +130,9 @@ class LocalBuildDoc(setup_command.BuildDoc): def _sphinx_tree(self): source_dir = self._get_source_dir() - cmd = ['apidoc', '.', '-H', 'Modules', '-o', source_dir] + cmd = ['-H', 'Modules', '-o', source_dir, '.'] + if apidoc_use_padding: + cmd.insert(0, 'apidoc') apidoc.main(cmd + self.autodoc_tree_excludes) def _sphinx_run(self):