fmtlegacy/doc/build.py

121 lines
5.1 KiB
Python
Raw Normal View History

#!/usr/bin/env python
# Build the documentation.
from __future__ import print_function
2020-11-08 14:13:56 +00:00
import errno, os, re, shutil, sys, tempfile
2020-11-08 14:16:49 +00:00
from subprocess import check_call, check_output, CalledProcessError, Popen
from subprocess import PIPE, STDOUT
2015-10-14 15:17:39 +00:00
from distutils.version import LooseVersion
2020-11-04 14:50:09 +00:00
versions = ['1.0.0', '1.1.0', '2.0.0', '3.0.2', '4.0.0', '4.1.0', '5.0.0', '5.1.0', '5.2.0', '5.2.1', '5.3.0', '6.0.0', '6.1.0', '6.1.1', '6.1.2', '6.2.0', '6.2.1', '7.0.0', '7.0.1', '7.0.2', '7.0.3', '7.1.0', '7.1.1', '7.1.2']
2017-07-01 14:30:51 +00:00
def pip_install(package, commit=None, **kwargs):
"Install package using pip."
if commit:
package = 'git+https://github.com/{0}.git@{1}'.format(package, commit)
2016-06-03 14:19:05 +00:00
print('Installing {0}'.format(package))
check_call(['pip', 'install', package])
def create_build_env(dirname='virtualenv'):
# Create virtualenv.
2016-05-26 15:00:41 +00:00
if not os.path.exists(dirname):
check_call(['virtualenv', dirname])
import sysconfig
scripts_dir = os.path.basename(sysconfig.get_path('scripts'))
2016-05-26 15:00:41 +00:00
activate_this_file = os.path.join(dirname, scripts_dir, 'activate_this.py')
with open(activate_this_file) as f:
exec(f.read(), dict(__file__=activate_this_file))
# Import get_distribution after activating virtualenv to get info about
# the correct packages.
from pkg_resources import get_distribution, DistributionNotFound
# 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.
pip_version = get_distribution('pip').version
if LooseVersion(pip_version) < LooseVersion('1.5.4'):
2015-10-15 13:41:16 +00:00
print("Updating pip")
2015-10-15 14:40:34 +00: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
2020-10-07 15:11:59 +00:00
# Install Sphinx and Breathe. Require the exact version of Sphinx which is
# compatible with Breathe.
pip_install('sphinx-doc/sphinx', '12b83372ac9316e8cbe86e7fed889296a4cc29ee')
2015-10-21 23:08:50 +00:00
pip_install('michaeljones/breathe',
'129222318f7c8f865d2631e7da7b033567e7f56a')
2016-05-08 15:03:01 +00:00
def build_docs(version='dev', **kwargs):
2016-05-09 15:36:16 +00:00
doc_dir = kwargs.get('doc_dir', os.path.dirname(os.path.realpath(__file__)))
2016-05-26 14:35:10 +00:00
work_dir = kwargs.get('work_dir', '.')
2018-02-11 17:23:17 +00:00
include_dir = kwargs.get(
'include_dir', os.path.join(os.path.dirname(doc_dir), 'include', 'fmt'))
# Build docs.
2015-05-20 15:06:12 +00:00
cmd = ['doxygen', '-']
2020-11-08 14:16:49 +00:00
p = Popen(cmd, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
2016-05-26 14:35:10 +00:00
doxyxml_dir = os.path.join(work_dir, 'doxyxml')
2020-11-08 14:13:56 +00:00
out, _ = p.communicate(input=r'''
2016-04-28 14:00:22 +00:00
PROJECT_NAME = fmt
GENERATE_LATEX = NO
GENERATE_MAN = NO
GENERATE_RTF = NO
CASE_SENSE_NAMES = NO
2020-10-07 15:11:59 +00:00
INPUT = {0}/chrono.h {0}/color.h {0}/core.h {0}/compile.h \
{0}/format.h {0}/os.h {0}/ostream.h {0}/printf.h
QUIET = YES
JAVADOC_AUTOBRIEF = YES
AUTOLINK_SUPPORT = NO
GENERATE_HTML = NO
GENERATE_XML = YES
2016-05-26 14:35:10 +00:00
XML_OUTPUT = {1}
ALIASES = "rst=\verbatim embed:rst"
ALIASES += "endrst=\endverbatim"
MACRO_EXPANSION = YES
PREDEFINED = _WIN32=1 \
FMT_USE_VARIADIC_TEMPLATES=1 \
FMT_USE_RVALUE_REFERENCES=1 \
2015-12-18 15:13:43 +00:00
FMT_USE_USER_DEFINED_LITERALS=1 \
2018-10-07 14:48:27 +00:00
FMT_USE_ALIAS_TEMPLATES=1 \
2018-05-12 19:57:16 +00:00
FMT_API= \
2018-05-12 20:12:04 +00:00
"FMT_BEGIN_NAMESPACE=namespace fmt {{" \
2018-09-13 14:20:43 +00:00
"FMT_END_NAMESPACE=}}" \
2018-12-13 01:50:50 +00:00
"FMT_STRING_ALIAS=1" \
2019-06-05 01:02:55 +00:00
"FMT_ENABLE_IF(B)="
EXCLUDE_SYMBOLS = fmt::formatter fmt::printf_formatter fmt::arg_join \
fmt::basic_format_arg::handle
2016-05-26 14:35:10 +00:00
'''.format(include_dir, doxyxml_dir).encode('UTF-8'))
2020-11-08 14:13:56 +00:00
out = re.sub(
2020-11-08 14:20:53 +00:00
".*warning: Member .* of class fmt::detail::.* is not documented.\n",
"", out)
2020-11-08 14:13:56 +00:00
print(out)
if p.returncode != 0:
2015-05-20 15:06:12 +00:00
raise CalledProcessError(p.returncode, cmd)
2020-11-08 14:13:56 +00:00
2016-05-26 14:35:10 +00:00
html_dir = os.path.join(work_dir, 'html')
2017-07-01 14:30:51 +00:00
main_versions = reversed(versions[-3:])
check_call(['sphinx-build',
'-Dbreathe_projects.format=' + os.path.abspath(doxyxml_dir),
'-Dversion=' + version, '-Drelease=' + version,
2017-07-01 14:30:51 +00:00
'-Aversion=' + version, '-Aversions=' + ','.join(main_versions),
2016-06-02 13:41:25 +00:00
'-b', 'html', doc_dir, html_dir])
try:
2020-11-07 17:27:06 +00:00
check_call(['lessc', '--verbose', '--clean-css',
'--include-path=' + os.path.join(doc_dir, 'bootstrap'),
os.path.join(doc_dir, 'fmt.less'),
os.path.join(html_dir, '_static', 'fmt.css')])
except OSError as e:
if e.errno != errno.ENOENT:
raise
print('lessc not found; make sure that Less (http://lesscss.org/) ' +
'is installed')
sys.exit(1)
2016-05-26 14:35:10 +00:00
return html_dir
2015-05-20 15:06:12 +00:00
if __name__ == '__main__':
2016-05-08 15:03:01 +00:00
create_build_env()
build_docs(sys.argv[1])