2024-06-02 16:29:07 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
# A script to invoke mkdocs with the correct environment.
|
2024-06-09 22:53:16 +00:00
|
|
|
# Additionally supports deploying:
|
|
|
|
# ./mkdocs deploy ...
|
2024-06-02 16:29:07 +00:00
|
|
|
|
2024-06-09 22:53:16 +00:00
|
|
|
import errno, os, shutil, sys
|
2024-06-09 20:17:13 +00:00
|
|
|
from subprocess import call
|
2024-06-02 16:29:07 +00:00
|
|
|
|
2024-06-09 22:53:16 +00:00
|
|
|
support_dir = os.path.dirname(os.path.normpath(__file__))
|
|
|
|
build_dir = os.path.join(os.path.dirname(support_dir), 'build')
|
2024-06-02 16:47:52 +00:00
|
|
|
|
2024-06-02 16:29:07 +00:00
|
|
|
# Set PYTHONPATH for the mkdocstrings handler.
|
|
|
|
env = os.environ.copy()
|
|
|
|
path = env.get('PYTHONPATH')
|
2024-06-09 20:17:13 +00:00
|
|
|
env['PYTHONPATH'] = \
|
2024-06-09 22:53:16 +00:00
|
|
|
(path + ':' if path else '') + os.path.join(support_dir, 'python')
|
2024-06-02 16:29:07 +00:00
|
|
|
|
2024-06-09 22:53:16 +00:00
|
|
|
config_path = os.path.join(support_dir, 'mkdocs.yml')
|
2024-06-09 18:37:18 +00:00
|
|
|
args = sys.argv[1:]
|
2024-06-09 20:17:13 +00:00
|
|
|
if len(args) > 0:
|
|
|
|
command = args[0]
|
|
|
|
if command == 'deploy':
|
2024-06-09 22:53:16 +00:00
|
|
|
site_dir = os. path.join(build_dir, 'fmt.dev')
|
|
|
|
try:
|
|
|
|
shutil.rmtree(site_dir)
|
|
|
|
except OSError as e:
|
|
|
|
if e.errno == errno.ENOENT:
|
|
|
|
pass
|
2024-06-09 20:17:13 +00:00
|
|
|
ret = call(['git', 'clone', '--depth=1',
|
2024-06-09 22:53:16 +00:00
|
|
|
'git@github.com:fmtlib/fmt.dev.git', site_dir])
|
2024-06-09 20:17:13 +00:00
|
|
|
if ret != 0:
|
|
|
|
sys.exit(ret)
|
2024-06-09 23:10:26 +00:00
|
|
|
sys.exit(call(['mike'] + args + ['--config-file', config_path,
|
|
|
|
'--branch', 'master'],
|
2024-06-09 20:17:13 +00:00
|
|
|
cwd=site_dir, env=env))
|
|
|
|
elif not command.startswith('-'):
|
2024-06-09 18:37:18 +00:00
|
|
|
args += ['-f', config_path]
|
2024-06-09 20:17:13 +00:00
|
|
|
sys.exit(call(['mkdocs'] + args, env=env))
|