-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathgen_inputs.py
executable file
·85 lines (70 loc) · 2.41 KB
/
gen_inputs.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
85
#!/usr/bin/env python3
# IODATA is an input and output module for quantum chemistry.
# Copyright (C) 2011-2019 The IODATA Development Team
#
# This file is part of IODATA.
#
# IODATA is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 3
# of the License, or (at your option) any later version.
#
# IODATA is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, see <http://www.gnu.org/licenses/>
# --
# pylint: disable=unused-argument,redefined-builtin
"""Generate formats.rst."""
from gen_formats import _format_words, _print_section
from iodata.api import INPUT_MODULES
__all__ = []
HEADER = """
.. _input_formats:
Supported Input Formats
#######################
"""
TEMPLATE = """
Default Template
----------------
.. code-block:: python
'''\\
{code_block_lines}
'''
"""
def main():
"""Write inputs.rst to stdout."""
print(HEADER)
for modname, module in sorted(INPUT_MODULES.items()):
if not hasattr(module, "write_input"):
continue
lines = module.__doc__.split("\n")
# add labels for cross-referencing format (e.g. in formats table)
print(f".. _input_{modname}:")
print()
_print_section("{} (``{}``)".format(lines[0][:-1], modname), "=")
print()
for line in lines[2:]:
print(line)
_print_section(":py:func:`iodata.formats.{}.write_input`".format(modname), "-")
fn = getattr(module, "write_input", None)
print("- Requires", _format_words(fn.required))
if fn.optional:
print("- May use", _format_words(fn.optional))
if fn.kwdocs:
print("- Keyword arguments", _format_words(fn.kwdocs))
if fn.notes:
print()
print(fn.notes)
print()
template = getattr(module, "default_template", None)
if template:
code_block_lines = [" " + l for l in template.split("\n")]
print(TEMPLATE.format(code_block_lines="\n".join(code_block_lines)))
print()
print()
if __name__ == "__main__":
main()