Logo ROOT  
Reference Guide
Loading...
Searching...
No Matches
print_roofit_pyz_doctrings.py
Go to the documentation of this file.
1# -------------------------------------------------------------------------------
2# Author: Jonas Rembser <jonas.rembser@cern.ch> CERN
3# -------------------------------------------------------------------------------
4
5################################################################################
6# Copyright (C) 1995-2020, Rene Brun and Fons Rademakers. #
7# All rights reserved. #
8# #
9# For the licensing terms see $ROOTSYS/LICENSE. #
10# For the list of contributors see $ROOTSYS/README/CREDITS. #
11################################################################################
12
13# Creates the doxygen documentation for the RooFit pythonizations, which includes:
14# - a PyROOT box for each pythonized class or member function
15# - a separate page for the RoofitPythonizations group where all the RooFit
16# pythonization documentation is aggregated
17
18import inspect
19
20
22 """Clean everything from the C++ signature that prohibits doxygen from automatically creating the correct link."""
23
24 # If the signature doesn't include the function parameters or they are
25 # empty, we are done.
26 if not "(" in sig or "()" in sig:
27 return sig
28
29 def strip_defaults_from_param_sig(param_sig):
30 # strip default parameter values
31 split_was_at_equal_sign = [False]
32 for c in param_sig:
33 if c == "=":
34 split_was_at_equal_sign.append(True)
35 elif c == ",":
36 split_was_at_equal_sign.append(False)
37 l = param_sig.replace("=", ",").split(",")
38 l = [l for l, was in zip(l, split_was_at_equal_sign) if not was]
39 return ",".join(l)
40
41 def strip_defaults(sig):
42 pbegin = sig.index("(") + 1
43 pend = sig.rindex(")")
44 param_sig = sig[pbegin:pend]
45 return sig[:pbegin] + strip_defaults_from_param_sig(param_sig) + sig[pend:]
46
47 def strip_output(sig):
48 beg = sig.index("(")
49 tmp = sig[:beg].replace("*", "").replace("&", "")
50 return tmp.strip().split(" ")[-1] + sig[beg:]
51
52 # replace new lines
53 sig = sig.replace("\n", " ")
54
55 # remove semicolons
56 sig = sig.replace(";", "")
57
58 # remove default parameters in the signature
59 sig = strip_defaults(sig)
60
61 # remove output parameter from signature
62 sig = strip_output(sig)
63
64 # remove double whitespaces
65 while " " in sig:
66 sig = sig.replace(" ", " ")
67
68 # return processed signature with whitespaces stripped from beginning and end
69 return sig.strip()
70
71
73
74 if klass.__doc__ is None:
75 return
76
77 print(r"\class " + klass.__cpp_name__)
78 print(r"\brief \parblock \endparblock")
79 print(r"\htmlonly")
80 print(r'<div class="pyrootbox">')
81 print(r"\endhtmlonly")
82 print(r"## PyROOT")
83
84 print(inspect.cleandoc(klass.__doc__))
85
86 print(r"\htmlonly")
87 print(r"</div>")
88 print(r"\endhtmlonly")
89 print(r"")
90
91
93
94 if func.__doc__ is None or not hasattr(func, "_cpp_signature"):
95 return
96
97 sigs = func._cpp_signature
98 if isinstance(sigs, str):
99 sigs = [sigs]
100
101 for sig in sigs:
102 print(r"\fn " + clean_cpp_signature(sig))
103 print(r"\brief \parblock \endparblock")
104 print(r"\htmlonly")
105 print(r'<div class="pyrootbox">')
106 print(r"\endhtmlonly")
107 print(r"## PyROOT")
108
109 print(inspect.cleandoc(func.__doc__))
110
111 print(r"\htmlonly")
112 print(r"</div>")
113 print(r"\endhtmlonly")
114 print(r"")
115
116
118 """Prints the doxygen code for the RooFit pythonization page."""
119 from ROOT._pythonization import _roofit
120
121 def member_funcs_have_doc(python_class):
122 funcs_have_doc = False
123 for func_name in _roofit.get_defined_attributes(python_klass):
124 if not getattr(python_class, func_name).__doc__ is None:
125 funcs_have_doc = True
126 return funcs_have_doc
127
128 # Fill separate RooFit pythonization page, starting with the introduction and table of contents...
129 print(r"\defgroup RoofitPythonizations RooFit Pythonizations")
130 print(r"\ingroup Roofitmain")
131 for python_klass in _roofit.python_classes:
132 if python_klass.__doc__ is None and not member_funcs_have_doc(python_klass):
133 continue
134 class_name = python_klass.__name__
135 print("- [" + class_name + "](\\ref _" + class_name.lower() + ")")
136
137 for func_name in _roofit.get_defined_attributes(python_klass):
138 func = getattr(python_klass, func_name)
139 if func.__doc__ is None:
140 continue
141 print(" - [" + func.__name__ + "](\\ref _" + (python_klass.__name__ + "_" + func.__name__).lower() + ")")
142
143 print("")
144
145 # ...and then iterating over all pythonized classes and functions
146 for python_klass in _roofit.python_classes:
147
148 if python_klass.__doc__ is None and not member_funcs_have_doc(python_klass):
149 continue
150
151 print(r"\anchor _" + python_klass.__name__.lower())
152 print(r"## " + python_klass.__name__)
153 print(r"\see " + python_klass.__name__)
154 if not python_klass.__doc__ is None:
155 print("")
156 print(inspect.cleandoc(python_klass.__doc__))
157 print("")
158
159 for func_name in _roofit.get_defined_attributes(python_klass):
160 func = getattr(python_klass, func_name)
161 if func.__doc__ is None:
162 continue
163 print(r"\anchor _" + (python_klass.__name__ + "_" + func.__name__).lower())
164 print(r"### " + python_klass.__name__ + "." + func.__name__)
165 print(inspect.cleandoc(func.__doc__))
166 print(r"")
167 if hasattr(func, "_cpp_signature"):
168 sigs = func._cpp_signature
169 if isinstance(sigs, str):
170 sigs = [sigs]
171 for sig in sigs:
172 print(r"\see " + clean_cpp_signature(sig))
173 print(r"")
174
175
177 """Print PyROOT blocks for the RooFit C++ documentation."""
178 from ROOT._pythonization import _roofit
179
180 for python_klass in _roofit.python_classes:
181
182 write_pyroot_block_for_class(python_klass)
183
184 func_names = _roofit.get_defined_attributes(python_klass)
185
186 for func_name in func_names:
187 func = getattr(python_klass, func_name)
189
190 for python_function in _roofit.python_roofit_functions:
191 write_pyroot_block_for_function(python_function)
192
193
194if __name__ == "__main__":
195
196 try:
197 print(r"/**")
199 print(r"")
201 print(r"*/")
202 except ImportError:
203 # roofit was probably not built
204 pass
print_roofit_pythonization_page()
Prints the doxygen code for the RooFit pythonization page.
clean_cpp_signature(sig)
Clean everything from the C++ signature that prohibits doxygen from automatically creating the correc...
print_pyroot_blocks_for_cpp_docs()
Print PyROOT blocks for the RooFit C++ documentation.