gecko-dev/tools/docs/mach_commands.py
Gregory Szorc e96948d5a8 Bug 1115278 - Move Sphinx documentation staging into Sphinx extension; r=glandium
Previously, code for staging the Sphinx documentation from moz.build
metadata lived in a mach command and in the moztreedocs module. This
patch moves the invocation to the Sphinx extension.

When the code is part of the Sphinx extension, it will run when executed
with sphinx-build. This is a prerequisite to getting RTD working, since
sphinx-build is the only supported entrypoint for generating
documentation there.

With this patch, we can now invoke sphinx-build to build the
documentation. The `mach build-docs` command is no longer needed.

--HG--
extra : rebase_source : 86e76c7d598ffa23dae858254eecedbdd12706a4
extra : histedit_source : 1826aa5ddfafdff62847cc293d1f0950b236caac
2014-12-24 09:46:41 -08:00

46 lines
1.3 KiB
Python

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, # You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import unicode_literals
import os
from mach.decorators import (
CommandArgument,
CommandProvider,
Command,
)
from mozbuild.base import MachCommandBase
from mozbuild.frontend.reader import BuildReader
@CommandProvider
class Documentation(MachCommandBase):
"""Helps manage in-tree documentation."""
@Command('build-docs', category='build-dev',
description='Generate documentation for the tree.')
@CommandArgument('--format', default='html',
help='Documentation format to write.')
@CommandArgument('outdir', default='<DEFAULT>', nargs='?',
help='Where to write output.')
def build_docs(self, format=None, outdir=None):
self._activate_virtualenv()
self.virtualenv_manager.install_pip_package('sphinx_rtd_theme==0.1.6')
import sphinx
if outdir == '<DEFAULT>':
outdir = os.path.join(self.topobjdir, 'docs')
args = [
'sphinx',
'-b', format,
os.path.join(self.topsrcdir, 'tools', 'docs'),
os.path.join(outdir, format),
]
return sphinx.main(args)