Reuse virtualenv to speed up builds

This commit is contained in:
Victor Zverovich 2016-05-26 08:00:41 -07:00
parent 9071daebe9
commit 8650c57ccd
2 changed files with 13 additions and 11 deletions

View File

@ -15,11 +15,11 @@ def pip_install(package, commit=None, **kwargs):
def create_build_env(dirname='virtualenv'):
# Create virtualenv.
check_call(['virtualenv', dirname])
if not os.path.exists(dirname):
check_call(['virtualenv', dirname])
import sysconfig
scripts_dir = os.path.basename(sysconfig.get_path('scripts'))
activate_this_file = os.path.join(dirname, scripts_dir,
'activate_this.py')
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))
# Upgrade pip because installation of sphinx with pip 1.1 available on Travis
@ -39,8 +39,7 @@ def create_build_env(dirname='virtualenv'):
except DistributionNotFound:
pass
# Install Sphinx and Breathe.
pip_install('sphinx-doc/sphinx',
'12b83372ac9316e8cbe86e7fed889296a4cc29ee',
pip_install('sphinx-doc/sphinx', '12b83372ac9316e8cbe86e7fed889296a4cc29ee',
check_version='1.4.1.dev20160525')
pip_install('michaeljones/breathe',
'6b1c5bb7a1866f15fc328b8716258354b10c1daa')

View File

@ -26,12 +26,15 @@ class Git:
fmt_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.insert(0, os.path.join(fmt_dir, 'doc'))
workdir = tempfile.mkdtemp('fmt')
work_dir = tempfile.mkdtemp('fmt')
try:
import build
build.create_build_env(os.path.join(workdir, 'virtualenv'))
# The virtualenv is stored in ~/.cache/fmt/virtualenv and reused to speed
# up builds.
build.create_build_env(os.path.join(
os.path.expanduser('~'), '.cache', 'fmt', 'virtualenv'))
fmt_repo = Git(os.path.join(workdir, 'fmt'))
fmt_repo = Git(os.path.join(work_dir, 'fmt'))
fmt_repo.clone('git@github.com:fmtlib/fmt')
doc_repo = Git('fmtlib.github.io')
doc_repo.clone('git@github.com:fmtlib/fmtlib.github.io')
@ -68,7 +71,8 @@ try:
with open(reference, 'w') as f:
f.write(data)
# Build the docs.
build.build_docs(version, doc_dir=target_doc_dir, include_dir=fmt_repo.dir)
build.build_docs(version, doc_dir=target_doc_dir, include_dir=fmt_repo.dir,
work_dir=work_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')
@ -76,8 +80,7 @@ try:
version_doc_dir = os.path.join(doc_repo.dir, version)
shutil.rmtree(version_doc_dir)
shutil.move('html', version_doc_dir)
# TODO: generate 'html' in temp dir
# TODO: update links in navbar
# TODO: remove doc repo
except:
shutil.rmtree(workdir)
shutil.rmtree(work_dir)