fmt/doc/build.py

87 lines
3.4 KiB
Python
Raw Normal View History

#!/usr/bin/env python2
# Build the documentation.
from __future__ import print_function
import os, shutil, tempfile
from subprocess import check_call, check_output, CalledProcessError, Popen, PIPE
2015-10-14 18:17:39 +03:00
from distutils.version import LooseVersion
def pip_install(package, commit=None, **kwargs):
"Install package using pip."
if commit:
check_version = kwargs.get('check_version', '')
#output = check_output(['pip', 'show', package.split('/')[1]])
#if check_version in output:
# print('{} already installed'.format(package))
# return
package = 'git+git://github.com/{0}.git@{1}'.format(package, commit)
print('Installing {}'.format(package))
2015-10-14 16:52:07 +03:00
check_call(['pip', 'install', '--upgrade', package])
2015-05-20 18:06:12 +03:00
def build_docs():
# Create virtualenv.
2015-05-20 18:06:12 +03:00
doc_dir = os.path.dirname(os.path.realpath(__file__))
virtualenv_dir = 'virtualenv'
check_call(['virtualenv', virtualenv_dir])
activate_this_file = os.path.join(virtualenv_dir, 'bin', 'activate_this.py')
execfile(activate_this_file, dict(__file__=activate_this_file))
# Upgrade pip because installation of sphinx with pip 1.1 available on Travis
# is broken (see #207) and it doesn't support the show command.
from pkg_resources import get_distribution, DistributionNotFound
pip_version = get_distribution('pip').version
if LooseVersion(pip_version) < LooseVersion('1.5.4'):
2015-10-15 16:41:16 +03:00
print("Updating pip")
2015-10-15 17:40:34 +03:00
check_call(['pip', 'install', '--upgrade', 'pip'])
# Upgrade distribute because installation of sphinx with distribute 0.6.24
# available on Travis is broken (see #207).
try:
distribute_version = get_distribution('distribute').version
if LooseVersion(distribute_version) <= LooseVersion('0.6.24'):
print("Updating distribute")
check_call(['pip', 'install', '--upgrade', 'distribute'])
except DistributionNotFound:
pass
2015-05-19 18:13:13 +03:00
# Install Sphinx and Breathe.
pip_install('cppformat/sphinx',
'12dde8afdb0a7bb5576e2656692c3478c69d8cc3',
check_version='1.4a0.dev-20151013')
pip_install('michaeljones/breathe',
'511b0887293e7c6b12310bb61b3659068f48f0f4')
# Build docs.
2015-05-20 18:06:12 +03:00
cmd = ['doxygen', '-']
p = Popen(cmd, stdin=PIPE)
p.communicate(input=r'''
PROJECT_NAME = C++ Format
GENERATE_LATEX = NO
GENERATE_MAN = NO
GENERATE_RTF = NO
CASE_SENSE_NAMES = NO
INPUT = {0}/format.h
QUIET = YES
JAVADOC_AUTOBRIEF = YES
AUTOLINK_SUPPORT = NO
GENERATE_HTML = NO
GENERATE_XML = YES
XML_OUTPUT = doxyxml
ALIASES = "rst=\verbatim embed:rst"
ALIASES += "endrst=\endverbatim"
PREDEFINED = _WIN32=1 \
FMT_USE_VARIADIC_TEMPLATES=1 \
FMT_USE_RVALUE_REFERENCES=1 \
FMT_USE_USER_DEFINED_LITERALS=1
EXCLUDE_SYMBOLS = fmt::internal::* StringValue write_str
'''.format(os.path.dirname(doc_dir)))
if p.returncode != 0:
2015-05-20 18:06:12 +03:00
raise CalledProcessError(p.returncode, cmd)
check_call(['sphinx-build', '-D',
'breathe_projects.format=' + os.path.join(os.getcwd(), 'doxyxml'),
'-b', 'html', doc_dir, 'html'])
check_call(['lessc', '--clean-css',
'--include-path=' + os.path.join(doc_dir, 'bootstrap'),
os.path.join(doc_dir, 'cppformat.less'),
'html/_static/cppformat.css'])
return 'html'
2015-05-20 18:06:12 +03:00
if __name__ == '__main__':
build_docs()