set_inheritance_diagram.py 1.64 KB
Newer Older
1
2
3
4
5
from os import remove
import os
from tempfile import mkstemp
from shutil import move, copy

6
directory = os.path.abspath(os.path.join('..', 'documentation'))
7
8

if 'conf.py' in os.listdir(directory):
9
    conf_file = os.path.abspath(os.path.join(directory, 'conf.py'))
10
11
12
13
14
    real_conf_file = os.path.abspath('real_conf.py')
    remove(conf_file)
    copy(real_conf_file, conf_file)

if 'index.rst' in os.listdir(directory):
15
    index_file = os.path.abspath(os.path.join(directory, 'index.rst'))
16
17
18
19
20
21
22
23
24
25
    real_index_file = os.path.abspath('real_index.rst')
    remove(index_file)
    copy(real_index_file, index_file)


for file in os.listdir(directory):
    if file.endswith(".rst"):
        file_path = os.path.abspath(file)
        fh, abs_path = mkstemp()
        with open(fh, 'w') as new_file:
26
            with open(os.path.join(directory, file)) as old_file:
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
                for line in old_file:
                    if 'undoc-members' in line:
                        continue
                    else:
                        new_file.write(line)
                        if 'automodule' in line:
                            name = line.split('::')[1]
                        elif 'show-inheritance' in line:
                            new_file.write('Inheritance Diagram:\n')
                            new_file.write('""""""""""""""""""""\n')
                            new_file.write('.. inheritance-diagram:: ' + name)
                            new_file.write('    :parts: 1')
                            new_file.write('')
                            new_file.write('')

42
43
        remove(os.path.join(directory, file))
        move(abs_path, os.path.join(directory, file))
44