forked from iterorganization/imas-data-dictionary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
generate_docs.py
84 lines (67 loc) · 2.34 KB
/
generate_docs.py
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from pathlib import Path
import os
import shutil
import subprocess
def generate_sphinx_documentation():
from sphinx.cmd.build import main as sphinx_main
from setuptools_scm import get_version
git_describe_output = get_version()
os.chdir("docs")
idsdef_path = os.path.join(".", "_static/IDSDefxml.js")
with open(idsdef_path, "w") as file:
file.write("const xmlString=`\n")
idsdef_command = ["java", "net.sf.saxon.Transform", "-t", "-s:../IDSDef.xml", "-xsl:generate_js_IDSDef.xsl"]
with open(idsdef_path, "a") as file:
subprocess.run(idsdef_command, stdout=file, check=True)
with open(idsdef_path, "a") as file:
file.write("`;")
source_dir = os.path.join(".")
build_dir = os.path.join(".", "_build/html")
directory = Path(build_dir)
if directory.exists():
shutil.rmtree(build_dir)
sphinx_args = [
"-b",
"html",
source_dir,
build_dir,
"-D",
"dd_changelog_generate=1",
"-D",
"dd_autodoc_generate=1",
"-W",
"--keep-going",
]
sphinx_main(sphinx_args)
# if ret != 0:
# raise RuntimeError(f"Sphinx build failed with return code {ret}")
try:
from git import Repo
output_file_path = os.path.join("docs", "_build", "html", "version.txt")
repo = Repo("..")
git_describe_output = repo.git.describe().strip()
except Exception as _: # noqa: F841
pass
os.makedirs(os.path.dirname(output_file_path), exist_ok=True)
with open(output_file_path, "w") as version_file:
version_file.write(git_describe_output)
os.chdir("..")
if __name__ == "__main__":
from generate import (
generate_dd_data_dictionary,
generate_dd_data_dictionary_validation,
generate_html_documentation,
generate_ids_cocos_transformations_symbolic_table,
generate_idsnames,
saxon_version,
)
# Can we use threads in this version of Saxon?
threads = ""
if saxon_version() >= 904:
threads = " -threads:4"
generate_dd_data_dictionary(extra_opts=threads)
generate_html_documentation(extra_opts=threads)
generate_ids_cocos_transformations_symbolic_table(extra_opts=threads)
generate_idsnames()
generate_dd_data_dictionary_validation(extra_opts=threads)
generate_sphinx_documentation()