File: buildme.py

package info (click to toggle)
deepdiff 8.1.1-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,716 kB
  • sloc: python: 14,702; makefile: 164; sh: 9
file content (38 lines) | stat: -rwxr-xr-x 1,173 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env python
"""
Create a .env file in this folder that has BUILD_PATH defined, otherwise the _build will be used.
Then run ./buildme.py
It will remove the contents of the BUILD_PATH folder and recreate it.
"""
import os
import datetime
import shutil
from dotenv import load_dotenv
from sphinx.cmd.build import main as sphinx_main

CACHE_PATH = '/tmp/sphinx_doctree'


def ensure_dir(file_path):
    directory = os.path.dirname(file_path)
    if not os.path.exists(directory):
        os.makedirs(directory)


def delete_dir_contents(directory):
    if os.path.exists(directory):
        shutil.rmtree(directory)


if __name__ == "__main__":
    load_dotenv(override=True)
    build_path = os.environ.get('BUILD_PATH', '_build')
    doc_version = os.environ.get('DOC_VERSION', '')
    if not build_path.endswith('/'):
        build_path = build_path + '/'
    build_path += doc_version
    argv = ['-b', 'html', '-d', CACHE_PATH, '.', build_path]
    ensure_dir(build_path)
    delete_dir_contents(build_path)
    delete_dir_contents('/tmp/sphinx_doctree')  # Disable this for faster build time but it might not properly invalidate the cache
    sphinx_main(argv)