| 1 |
#!/usr/bin/env python |
| 2 |
""" |
| 3 |
Create a .env file in this folder that has BUILD_PATH defined, otherwise the _build will be used. |
| 4 |
Then run ./buildme.py |
| 5 |
It will remove the contents of the BUILD_PATH folder and recreate it. |
| 6 |
""" |
| 7 |
import os |
| 8 |
import datetime |
| 9 |
import shutil |
| 10 |
from dotenv import load_dotenv |
| 11 |
from sphinx.cmd.build import main as sphinx_main |
| 12 |
|
| 13 |
CACHE_PATH = '/tmp/sphinx_doctree' |
| 14 |
|
| 15 |
|
| 16 |
def ensure_dir(file_path): |
| 17 |
directory = os.path.dirname(file_path) |
| 18 |
if not os.path.exists(directory): |
| 19 |
os.makedirs(directory) |
| 20 |
|
| 21 |
|
| 22 |
def delete_dir_contents(directory): |
| 23 |
if os.path.exists(directory): |
| 24 |
shutil.rmtree(directory) |
| 25 |
|
| 26 |
|
| 27 |
if __name__ == "__main__": |
| 28 |
load_dotenv(override=True) |
| 29 |
build_path = os.environ.get('BUILD_PATH', '_build') |
| 30 |
doc_version = os.environ.get('DOC_VERSION', '') |
| 31 |
if not build_path.endswith('/'): |
| 32 |
build_path = build_path + '/' |
| 33 |
build_path += doc_version |
| 34 |
argv = ['-b', 'html', '-d', CACHE_PATH, '.', build_path] |
| 35 |
ensure_dir(build_path) |
| 36 |
delete_dir_contents(build_path) |
| 37 |
delete_dir_contents('/tmp/sphinx_doctree') # Disable this for faster build time but it might not properly invalidate the cache |
| 38 |
sphinx_main(argv) |