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