diff --git a/doc/build.py b/doc/build.py index c49094be..98dfedab 100755 --- a/doc/build.py +++ b/doc/build.py @@ -51,7 +51,9 @@ def create_build_env(): pip_install('michaeljones/breathe', '1c9d7f80378a92cffa755084823a78bb38ee4acc') -def build_docs(version='dev', doc_dir=os.path.dirname(os.path.realpath(__file__))): +def build_docs(version='dev', **kwargs): + doc_dir = kwargs.get('doc_dir', os.path.dirname(os.path.realpath(__file__))) + include_dir = kwargs.get('include_dir', os.path.join(os.path.dirname(doc_dir), 'fmt')) # Build docs. cmd = ['doxygen', '-'] p = Popen(cmd, stdin=PIPE) @@ -77,7 +79,7 @@ def build_docs(version='dev', doc_dir=os.path.dirname(os.path.realpath(__file__) FMT_USE_USER_DEFINED_LITERALS=1 \ FMT_API= EXCLUDE_SYMBOLS = fmt::internal::* StringValue write_str - '''.format(os.path.join(os.path.dirname(doc_dir), 'fmt')).encode('UTF-8')) + '''.format(include_dir).encode('UTF-8')) if p.returncode != 0: raise CalledProcessError(p.returncode, cmd) check_call(['sphinx-build', diff --git a/support/update-website.py b/support/update-website.py index 1ad24ed5..52a7ff1c 100755 --- a/support/update-website.py +++ b/support/update-website.py @@ -1,6 +1,6 @@ #!/usr/bin/env python -import os, shutil, sys +import os, shutil, sys, tempfile from subprocess import check_call class Git: @@ -22,22 +22,41 @@ sys.path.insert(0, os.path.join(fmt_dir, 'doc')) import build build.create_build_env() -git = Git('fmt') -git.clone('git@github.com:fmtlib/fmt.git') +fmt_repo = Git(tempfile.mkdtemp('fmt')) +try: + fmt_repo.clone('git@github.com:fmtlib/fmt') + doc_repo = Git('fmtlib.github.io') + doc_repo.clone('git@github.com:fmtlib/fmtlib.github.io') -versions = ['1.0.0'] -for version in versions: - git.checkout(version) - target_doc_dir = os.path.join(git.dir, 'doc') - # Remove the old theme. - for entry in os.listdir(target_doc_dir): - path = os.path.join(target_doc_dir, entry) - if os.path.isdir(path): - shutil.rmtree(path) - # Copy the new theme. - for entry in ['_static', '_templates', 'basic-bootstrap', 'bootstrap']: - src = os.path.join(fmt_dir, 'doc', entry) - dst = os.path.join(target_doc_dir, entry) - shutil.copytree(src, dst) - build.build_docs(version, target_doc_dir) - # TODO: copy docs to website + versions = ['1.0.0'] + for version in versions: + fmt_repo.checkout(version) + target_doc_dir = os.path.join(fmt_repo.dir, 'doc') + # Remove the old theme. + for entry in os.listdir(target_doc_dir): + path = os.path.join(target_doc_dir, entry) + if os.path.isdir(path): + shutil.rmtree(path) + # Copy the new theme. + for entry in ['_static', '_templates', 'basic-bootstrap', 'bootstrap', 'conf.py', 'fmt.less']: + src = os.path.join(fmt_dir, 'doc', entry) + dst = os.path.join(target_doc_dir, entry) + copy = shutil.copytree if os.path.isdir(src) else shutil.copyfile + copy(src, dst) + # Rename index to contents. + contents = os.path.join(target_doc_dir, 'contents.rst') + if not os.path.exists(contents): + os.rename(os.path.join(target_doc_dir, 'index.rst'), contents) + # Build the docs. + build.build_docs(version, doc_dir=target_doc_dir, include_dir=fmt_repo.dir) + # Create symlinks for older versions. + for link, target in {'index': 'contents', 'api': 'reference'}.items(): + os.symlink(target + '.html', os.path.join('html', link) + '.html') + # Copy docs to the website. + version_doc_dir = os.path.join(doc_repo.dir, version) + shutil.rmtree(version_doc_dir) + shutil.copytree('html', version_doc_dir, symlinks=True) + # TODO: fix links + # TODO: remove doc repo +except: + shutil.rmtree(fmt_repo.dir)