mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-27 03:21:34 +00:00
46 lines
1.5 KiB
Python
Executable File
46 lines
1.5 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
# A script to invoke mkdocs with the correct environment.
|
|
# Additionally supports deploying via mike:
|
|
# ./mkdocs deploy [mike-deploy-options]
|
|
|
|
import errno, os, shutil, sys
|
|
from subprocess import call
|
|
|
|
support_dir = os.path.dirname(os.path.normpath(__file__))
|
|
build_dir = os.path.join(os.path.dirname(support_dir), 'build')
|
|
|
|
# Set PYTHONPATH for the mkdocstrings handler.
|
|
env = os.environ.copy()
|
|
path = env.get('PYTHONPATH')
|
|
env['PYTHONPATH'] = \
|
|
(path + ':' if path else '') + os.path.join(support_dir, 'python')
|
|
|
|
config_path = os.path.join(support_dir, 'mkdocs.yml')
|
|
args = sys.argv[1:]
|
|
if len(args) > 0:
|
|
command = args[0]
|
|
if command == 'deploy':
|
|
site_repo = 'git@github.com:fmtlib/fmt.dev.git'
|
|
if 'CI' in os.environ:
|
|
site_repo = 'https://github.com/fmtlib/fmt.dev.git'
|
|
|
|
site_dir = os. path.join(build_dir, 'fmt.dev')
|
|
try:
|
|
shutil.rmtree(site_dir)
|
|
except OSError as e:
|
|
if e.errno == errno.ENOENT:
|
|
pass
|
|
ret = call(['git', 'clone', '--depth=1', site_repo, site_dir])
|
|
if ret != 0:
|
|
sys.exit(ret)
|
|
|
|
# Copy the config to the build dir because the site is built relative to it.
|
|
config_build_path = os.path.join(build_dir, 'mkdocs.yml')
|
|
shutil.copyfile(config_path, config_build_path)
|
|
|
|
sys.exit(call(['mike'] + args + ['--config-file', config_build_path,
|
|
'--branch', 'master'], cwd=site_dir, env=env))
|
|
elif not command.startswith('-'):
|
|
args += ['-f', config_path]
|
|
sys.exit(call(['mkdocs'] + args, env=env))
|