blob: 86b15eeb1c91ebf0df58ad5b9280317156336114 [file] [log] [blame]
James Kuszmaul31a7f602022-10-04 16:56:24 -07001#!/usr/bin/env python3
2"""This is a small wrapper to allow bazel to call mkdocs as a script.
3
4Because the mkdocs library handles consuming command-line arguments directly,
5we (rather than attempting to mess with arguments ourselves), use environment
6variables to communicate certain flags. Namely:
7If the OUTPUT environment variable is set, then we will tar up the output of
8the SITE_DIR directory into the OUTPUT file. This is used to make the mkdocs
9output bazel-friendly by only outputting a single file.
10"""
11from mkdocs.__main__ import cli
12import os
13import sys
14import tarfile
15try:
16 cli()
17except SystemExit as err:
18 if err.code != 0:
19 raise err
20if "OUTPUT" in os.environ:
21 with tarfile.open(os.environ["OUTPUT"], "w") as tarball:
22 tarball.add(os.environ["SITE_DIR"], arcname="")