diff options
| author | Monty Taylor <mordred@inaugust.com> | 2012-06-14 13:54:30 -0400 |
|---|---|---|
| committer | Monty Taylor <mordred@inaugust.com> | 2012-06-14 13:56:46 -0400 |
| commit | c092bd596287a2a66938d01152ea8dbade1926b6 (patch) | |
| tree | 2b8542f5bf3520e33ebc11884fd37591f500a4a2 /openstack/common/setup.py | |
| parent | 23d78dddf216cba0471b092fa615e6da6b1b4ebb (diff) | |
| download | oslo-c092bd596287a2a66938d01152ea8dbade1926b6.tar.gz oslo-c092bd596287a2a66938d01152ea8dbade1926b6.tar.xz oslo-c092bd596287a2a66938d01152ea8dbade1926b6.zip | |
Add autodoc generation to the build_sphinx command
The logic is pulled from the nova code, but has been abstracted
from being nova specific. It allows us to duplicate less info,
because we know a lot of the meta information in setup.py anyway.
Once this is in, we'll get autodoc module information everywhere
pretty much for free, and we can delete the doc/ext dir and the
doc/*sh from nova. (thanks to bcwaldon for pushing things to be
better)
Change-Id: I4c55c370ea6c3790958b5412e21e3378f4474104
Diffstat (limited to 'openstack/common/setup.py')
| -rw-r--r-- | openstack/common/setup.py | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/openstack/common/setup.py b/openstack/common/setup.py index 79b5a62..429ba35 100644 --- a/openstack/common/setup.py +++ b/openstack/common/setup.py @@ -164,12 +164,27 @@ def generate_authors(): with open(old_authors, "r") as old_authors_fh: new_authors_fh.write('\n' + old_authors_fh.read()) +_rst_template = """%(heading)s +%(underline)s + +.. automodule:: %(module)s + :members: + :undoc-members: + :show-inheritance: +""" + def get_cmdclass(): """Return dict of commands to run from setup.py.""" cmdclass = dict() + def _find_modules(arg, dirname, files): + for filename in files: + if filename.endswith('.py') and filename != '__init__.py': + arg["%s.%s" % (dirname.replace('/', '.'), + filename[:-3])] = True + class LocalSDist(sdist.sdist): """Builds the ChangeLog and Authors files from VC first.""" @@ -188,10 +203,47 @@ def get_cmdclass(): from sphinx.setup_command import BuildDoc class LocalBuildDoc(BuildDoc): + def generate_autoindex(self): + print "**Autodocumenting from %s" % os.path.abspath(os.curdir) + modules = {} + option_dict = self.distribution.get_option_dict('build_sphinx') + source_dir = os.path.join(option_dict['source_dir'][1], 'api') + if not os.path.exists(source_dir): + os.makedirs(source_dir) + for pkg in self.distribution.packages: + if '.' not in pkg: + os.path.walk(pkg, _find_modules, modules) + module_list = modules.keys() + module_list.sort() + autoindex_filename = os.path.join(source_dir, 'autoindex.rst') + with open(autoindex_filename, 'w') as autoindex: + autoindex.write(""".. toctree:: + :maxdepth: 1 + +""") + for module in module_list: + output_filename = os.path.join(source_dir, + "%s.rst" % module) + heading = "The :mod:`%s` Module" % module + underline = "=" * len(heading) + values = dict(module=module, heading=heading, + underline=underline) + + print "Generating %s" % output_filename + with open(output_filename, 'w') as output_file: + output_file.write(_rst_template % values) + autoindex.write(" %s.rst\n" % module) + def run(self): + if not os.getenv('SPHINX_DEBUG'): + self.generate_autoindex() + for builder in ['html', 'man']: self.builder = builder self.finalize_options() + self.project = self.distribution.get_name() + self.version = self.distribution.get_version() + self.release = self.distribution.get_version() BuildDoc.run(self) cmdclass['build_sphinx'] = LocalBuildDoc except ImportError: |
