1
|
|
|
# Copyright 2014 Diamond Light Source Ltd. |
2
|
|
|
# |
3
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License"); |
4
|
|
|
# you may not use this file except in compliance with the License. |
5
|
|
|
# You may obtain a copy of the License at |
6
|
|
|
# |
7
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0 |
8
|
|
|
# |
9
|
|
|
# Unless required by applicable law or agreed to in writing, software |
10
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS, |
11
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12
|
|
|
# See the License for the specific language governing permissions and |
13
|
|
|
# limitations under the License. |
14
|
|
|
|
15
|
|
|
""" |
16
|
|
|
.. module:: create_autosummary |
17
|
|
|
:platform: Unix |
18
|
|
|
:synopsis: A module to automatically update a Sphinx API. |
19
|
|
|
|
20
|
|
|
.. moduleauthor:: Nicola Wadeson <[email protected]> |
21
|
|
|
|
22
|
|
|
""" |
23
|
|
|
import os |
24
|
|
|
|
25
|
|
|
|
26
|
|
|
def list_of_packages(base_path): |
27
|
|
|
pkg_list = [] |
28
|
|
|
for entry in os.listdir(base_path): |
29
|
|
|
entry_path = os.path.join(base_path, entry) |
30
|
|
|
if not os.path.isfile(entry_path): |
31
|
|
|
pkg_list.append(entry_path) |
32
|
|
|
return pkg_list |
33
|
|
|
|
34
|
|
|
|
35
|
|
|
def add_package_entry(f, root, dirs, files, output): |
36
|
|
|
pkg_path = root.split('Savu/')[1] |
37
|
|
|
module_name = pkg_path.replace('/', '.') |
38
|
|
|
f.write(module_name + |
39
|
|
|
'\n------------------------------------------------------------\n') |
40
|
|
|
f.write('\n.. toctree::\n') |
41
|
|
|
|
42
|
|
|
for fi in files: |
43
|
|
|
file_path = module_name + '.' + fi.split('.py')[0] |
44
|
|
|
f.write(' ' + output + '/' + file_path + '\n') |
45
|
|
|
f.write('\n\n') |
46
|
|
|
|
47
|
|
|
|
48
|
|
|
def add_indices_and_tables(f): |
49
|
|
|
f.write('Indices and tables\n') |
50
|
|
|
f.write('==================\n') |
51
|
|
|
f.write('* :ref:`genindex`\n') |
52
|
|
|
f.write('* :ref:`modindex`\n') |
53
|
|
|
f.write('* :ref:`search`\n') |
54
|
|
|
|
55
|
|
|
|
56
|
|
|
if __name__ == "__main__": |
57
|
|
|
import sys |
58
|
|
|
out_folder, rst_file, api_type = sys.argv[1:] |
59
|
|
|
|
60
|
|
|
# determine Savu base path |
61
|
|
|
savu_base_path = \ |
62
|
|
|
os.path.dirname(os.path.realpath(__file__)).split('doc')[0] |
63
|
|
|
|
64
|
|
|
# open the autosummary file |
65
|
|
|
f = open(savu_base_path + 'doc/source/reference/' + rst_file, 'w') |
66
|
|
|
|
67
|
|
|
if api_type == 'framework': |
68
|
|
|
f.write('Framework API \n===================\n') |
69
|
|
|
exclude_dir = ['__pycache__', 'test', 'plugins'] |
70
|
|
|
elif api_type == 'plugin': |
71
|
|
|
f.write('Plugin API \n===================\n') |
72
|
|
|
exclude_dir = ['__pycache__', 'test'] |
73
|
|
|
else: |
74
|
|
|
raise Exception('Unknown API type', api_type) |
75
|
|
|
|
76
|
|
|
# add header |
77
|
|
|
f.write('Information on specific functions, classes, and methods.\n \n') |
78
|
|
|
|
79
|
|
|
base_path = savu_base_path + 'savu' |
80
|
|
|
# create entries in the autosummary for each package |
81
|
|
|
|
82
|
|
|
exclude_file = ['__init__.py', 'win_readline.py'] |
83
|
|
|
|
84
|
|
|
for root, dirs, files in os.walk(base_path, topdown=True): |
85
|
|
|
dirs[:] = [d for d in dirs if d not in exclude_dir] |
86
|
|
|
files[:] = [fi for fi in files if fi.split('.')[-1] == 'py'] |
87
|
|
|
files[:] = [fi for fi in files if fi not in exclude_file] |
88
|
|
|
if '__' not in root: |
89
|
|
|
add_package_entry(f, root, dirs, files, out_folder) |
90
|
|
|
|
91
|
|
|
# add_indices_and_tables(f) |
92
|
|
|
|