You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 
 
 

51 lines
1.3 KiB

  1. import argparse
  2. import os
  3. import sys
  4. import shutil
  5. import subprocess
  6. def run(*cmd):
  7. print("$", *cmd)
  8. process = subprocess.run(" ".join(cmd), shell=True)
  9. if process.returncode != 0:
  10. sys.exit(1)
  11. def main():
  12. parser = argparse.ArgumentParser()
  13. parser.add_argument("--dev", action="store_true", help="Run with a live server")
  14. parser.add_argument(
  15. "--werror", action="store_true", help="Treat warnings as errors"
  16. )
  17. parser.add_argument("--clean", action="store_true", help="Clean first")
  18. parser.add_argument("--format", help="Output format", default="html")
  19. args = parser.parse_args()
  20. dev = args.dev
  21. werror = args.werror
  22. clean = "--clean" in sys.argv
  23. format = args.format
  24. if dev:
  25. program = "sphinx-autobuild"
  26. else:
  27. program = "sphinx-build"
  28. opts = []
  29. if clean:
  30. if os.path.exists("build"):
  31. shutil.rmtree("build")
  32. if werror:
  33. opts.append("-W")
  34. if format == "html":
  35. builder = "html"
  36. elif format == "pdf":
  37. builder = "latex"
  38. build_path = f"build/{builder}"
  39. run(program, *opts, "-d", "build", "-b", builder, "source", build_path)
  40. if format == "pdf":
  41. run("make", "-C", build_path)
  42. if __name__ == "__main__":
  43. main()