2 # A script to invoke mkdocs with the correct environment.
3 # Additionally supports deploying via mike:
4 # ./mkdocs deploy [mike-deploy-options]
6 import errno, os, shutil, sys
7 from subprocess import call
9 support_dir = os.path.dirname(os.path.normpath(__file__))
10 build_dir = os.path.join(os.path.dirname(support_dir), 'build')
12 # Set PYTHONPATH for the mkdocstrings handler.
13 env = os.environ.copy()
14 path = env.get('PYTHONPATH')
16 (path + ':' if path else '') + os.path.join(support_dir, 'python')
18 config_path = os.path.join(support_dir, 'mkdocs.yml')
22 if command == 'deploy':
23 git_url = 'https://github.com/' if 'CI' in os.environ else 'git@github.com:'
24 site_repo = git_url + 'fmtlib/fmt.dev.git'
26 site_dir = os. path.join(build_dir, 'fmt.dev')
28 shutil.rmtree(site_dir)
30 if e.errno == errno.ENOENT:
32 ret = call(['git', 'clone', '--depth=1', site_repo, site_dir])
36 # Copy the config to the build dir because the site is built relative to it.
37 config_build_path = os.path.join(build_dir, 'mkdocs.yml')
38 shutil.copyfile(config_path, config_build_path)
40 sys.exit(call(['mike'] + args + ['--config-file', config_build_path,
41 '--branch', 'master'], cwd=site_dir, env=env))
42 elif not command.startswith('-'):
43 args += ['-f', config_path]
44 sys.exit(call(['mkdocs'] + args, env=env))