File: preprocess.py

package info (click to toggle)
numpy 1%3A2.2.4%2Bds-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 83,420 kB
  • sloc: python: 248,499; asm: 232,365; ansic: 216,874; cpp: 135,657; f90: 1,540; sh: 938; fortran: 558; makefile: 409; sed: 139; xml: 109; java: 92; perl: 79; cs: 54; javascript: 53; objc: 29; lex: 13; yacc: 9
file content (49 lines) | stat: -rwxr-xr-x 1,452 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
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python3
import os
from string import Template

def main():
    doxy_gen(os.path.abspath(os.path.join('..')))

def doxy_gen(root_path):
    """
    Generate Doxygen configuration file.
    """
    confs = doxy_config(root_path)
    build_path = os.path.join(root_path, "doc", "build", "doxygen")
    gen_path = os.path.join(build_path, "Doxyfile")
    if not os.path.exists(build_path):
        os.makedirs(build_path)
    with open(gen_path, 'w') as fd:
        fd.write("#Please Don't Edit! This config file was autogenerated by ")
        fd.write(f"doxy_gen({root_path}) in doc/preprocess.py.\n")
        for c in confs:
            fd.write(c)

class DoxyTpl(Template):
    delimiter = '@'

def doxy_config(root_path):
    """
    Fetch all Doxygen sub-config files and gather it with the main config file.
    """
    confs = []
    dsrc_path = os.path.join(root_path, "doc", "source")
    sub = dict(ROOT_DIR=root_path)
    with open(os.path.join(dsrc_path, "doxyfile")) as fd:
        conf = DoxyTpl(fd.read())
        confs.append(conf.substitute(CUR_DIR=dsrc_path, **sub))

    for dpath, _, files in os.walk(root_path):
        if ".doxyfile" not in files:
            continue
        conf_path = os.path.join(dpath, ".doxyfile")
        with open(conf_path) as fd:
            conf = DoxyTpl(fd.read())
            confs.append(conf.substitute(CUR_DIR=dpath, **sub))
    return confs


if __name__ == "__main__":
    main()