build.py revision aaa8b1e0aa5e14765dfa57484e5a2eba8db2184a
1#!/usr/bin/env python2 2# Build the documentation. 3 4from __future__ import print_function 5import os, shutil, tempfile 6from subprocess import check_call, check_output, CalledProcessError, Popen, PIPE 7from distutils.version import LooseVersion 8 9def pip_install(package, commit=None, **kwargs): 10 "Install package using pip." 11 if commit: 12 check_version = kwargs.get('check_version', '') 13 #output = check_output(['pip', 'show', package.split('/')[1]]) 14 #if check_version in output: 15 # print('{} already installed'.format(package)) 16 # return 17 package = 'git+git://github.com/{0}.git@{1}'.format(package, commit) 18 print('Installing {}'.format(package)) 19 check_call(['pip', 'install', '--upgrade', package]) 20 21def build_docs(): 22 # Create virtualenv. 23 doc_dir = os.path.dirname(os.path.realpath(__file__)) 24 virtualenv_dir = 'virtualenv' 25 check_call(['virtualenv', virtualenv_dir]) 26 activate_this_file = os.path.join(virtualenv_dir, 'bin', 'activate_this.py') 27 execfile(activate_this_file, dict(__file__=activate_this_file)) 28 # Upgrade pip because installation of sphinx with pip 1.1 available on Travis 29 # is broken (see #207) and it doesn't support the show command. 30 from pkg_resources import get_distribution, DistributionNotFound 31 pip_version = get_distribution('pip').version 32 if LooseVersion(pip_version) < LooseVersion('1.5.4'): 33 print("Updating pip") 34 check_call(['pip', 'install', '--upgrade', 'pip']) 35 # Upgrade distribute because installation of sphinx with distribute 0.6.24 36 # available on Travis is broken (see #207). 37 try: 38 distribute_version = get_distribution('distribute').version 39 print('distribute version: ' + distribute_version) 40 if LooseVersion(distribute_version) <= LooseVersion('0.6.24'): 41 print("Updating distribute") 42 check_call(['pip', 'install', '--upgrade', 'distribute']) 43 except DistributionNotFound: 44 pass 45 # Install Sphinx and Breathe. 46 pip_install('cppformat/sphinx', 47 '12dde8afdb0a7bb5576e2656692c3478c69d8cc3', 48 check_version='1.4a0.dev-20151013') 49 pip_install('michaeljones/breathe', 50 '511b0887293e7c6b12310bb61b3659068f48f0f4') 51 print(check_output(['pip', '--version'])) 52 print(check_output(['pip', 'show', 'alabaster'])) 53 print(check_output(['sphinx-build', '--version'])) 54 print('PATH:', os.environ['PATH']) 55 print(check_output(['which', 'sphinx-build'])) 56 import sphinx 57 print(sphinx.__version__) 58 # Build docs. 59 cmd = ['doxygen', '-'] 60 p = Popen(cmd, stdin=PIPE) 61 p.communicate(input=r''' 62 PROJECT_NAME = C++ Format 63 GENERATE_LATEX = NO 64 GENERATE_MAN = NO 65 GENERATE_RTF = NO 66 CASE_SENSE_NAMES = NO 67 INPUT = {0}/format.h 68 QUIET = YES 69 JAVADOC_AUTOBRIEF = YES 70 AUTOLINK_SUPPORT = NO 71 GENERATE_HTML = NO 72 GENERATE_XML = YES 73 XML_OUTPUT = doxyxml 74 ALIASES = "rst=\verbatim embed:rst" 75 ALIASES += "endrst=\endverbatim" 76 PREDEFINED = _WIN32=1 \ 77 FMT_USE_VARIADIC_TEMPLATES=1 \ 78 FMT_USE_RVALUE_REFERENCES=1 \ 79 FMT_USE_USER_DEFINED_LITERALS=1 80 EXCLUDE_SYMBOLS = fmt::internal::* StringValue write_str 81 '''.format(os.path.dirname(doc_dir))) 82 if p.returncode != 0: 83 raise CalledProcessError(p.returncode, cmd) 84 check_call(['sphinx-build', '-D', 85 'breathe_projects.format=' + os.path.join(os.getcwd(), 'doxyxml'), 86 '-b', 'html', doc_dir, 'html']) 87 check_call(['lessc', '--clean-css', 88 '--include-path=' + os.path.join(doc_dir, 'bootstrap'), 89 os.path.join(doc_dir, 'cppformat.less'), 90 'html/_static/cppformat.css']) 91 return 'html' 92 93if __name__ == '__main__': 94 build_docs() 95