-
Notifications
You must be signed in to change notification settings - Fork 102
Expand file tree
/
Copy pathdocumentation_snippets.py
More file actions
257 lines (217 loc) · 8.57 KB
/
documentation_snippets.py
File metadata and controls
257 lines (217 loc) · 8.57 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
# Different documentation snippets we add to the generated documentation
import typing
rep_cap_method_desc: str = '''
This method requires repeated capabilities. If called directly on the
{0}.Session object, then the method will use all repeated capabilities in the session.
You can specify a subset of repeated capabilities using the Python index notation on an
{0}.Session repeated capabilities container, and calling this method on the result.
'''
rep_cap_attr_desc: str = '''
This property can use repeated capabilities. If set or get directly on the
{0}.Session object, then the set/get will use all repeated capabilities in the session.
You can specify a subset of repeated capabilities using the Python index notation on an
{0}.Session repeated capabilities container, and calling set/get value on the result.
'''
func_note_text: str = '''
One or more of the referenced functions are not in the Python API for this driver.
'''
attr_note_text: str = '''
One or more of the referenced attributes are not in the Python API for this driver.
'''
enum_note_text: str = '''
One or more of the referenced values are not in the Python API for this driver. Enums that only define values, or represent True/False, have been removed.
'''
session_return_text = '''
A session object representing the device.
'''
options_table_header: typing.Sequence[str] = ['Attribute', 'Default']
options_table_body: typing.Sequence[typing.Sequence[str]] = [
['range_check', 'True'],
['query_instrument_status', 'False'],
['cache', 'True'],
['simulate', 'False'],
['record_value_coersions', 'False'],
['driver_setup', '{}'],
]
options_text: str = '''
Specifies the initial value of certain attributes for the session. The
syntax for **options** is a dictionary of attributes with an assigned
value. For example:
{ 'simulate': False }
You do not have to specify a value for all the attributes. If you do not
specify a value for an attribute, the default value is used.
Advanced Example:
{ 'simulate': True, 'driver_setup': { 'Model': '<model number>', 'BoardType': '<type>' } }
'''
default_close_function_doc: str = '''
Closes the driver session and cleans up. After calling this the Session object
is no longer valid and cannot be used.
'''
close_function_note: str = '''
This function is not needed when using the session context manager
'''
default_initiate_function_doc: str = '''
Calls initiate
'''
initiate_function_note: str = '''
This function will return a Python context manager that will initiate on entering and abort on exit.
'''
def close_function_def_for_doc(functions, config):
# This is very specific to session based APIs. We look for a 'close' function in
# the metadata which is to become a code-generated "private" method of Session
# for which we provide a public wrapper. Copy its documentation so we apply it to
# the said public wrapper.
if 'close_function' not in config or config['close_function'] is None:
# There is no close function so we don't need to worry about documentation (nitclk only)
return None
close_name = config['close_function']
if close_name in functions:
import copy
function_def = copy.deepcopy(functions[close_name])
if 'documentation' not in function_def:
function_def['documentation'] = {}
if 'description' not in function_def['documentation']:
function_def['documentation']['description'] = default_close_function_doc
if 'note' not in function_def['documentation']:
function_def['documentation']['note'] = []
if type(function_def['documentation']['note']) is not list:
function_def['documentation']['note'] = [function_def['documentation']['note']]
function_def['documentation']['note'].append(close_function_note)
function_def['python_name'] = 'close'
else:
assert False, "No '{}' function defined".format(close_name)
return function_def
def initiate_function_def_for_doc(functions, config):
# This is very specific to session based APIs. We look for a 'initiate' function in
# the metadata which is to become a code-generated "private" method of Session
# for which we then use in a context manager. Copy its documentation so we apply it to
# the said context manager.
session_context_manager_initiate = None
if 'initiate_function' in config['context_manager_name']:
session_context_manager_initiate = config['context_manager_name']['initiate_function']
if session_context_manager_initiate is None:
# Don't have an initiate
return None
if session_context_manager_initiate in functions:
import copy
function_def = copy.deepcopy(functions[session_context_manager_initiate])
if 'documentation' not in function_def:
function_def['documentation'] = {}
if 'description' not in function_def['documentation']:
function_def['documentation']['description'] = default_initiate_function_doc
if 'note' not in function_def['documentation']:
function_def['documentation']['note'] = []
if type(function_def['documentation']['note']) is not list:
function_def['documentation']['note'] = [function_def['documentation']['note']]
function_def['documentation']['note'].append(initiate_function_note)
function_def['python_name'] = 'initiate'
else:
assert False, "No '{}' function defined".format(session_context_manager_initiate)
return function_def
def test_close_function_def_for_doc_note_not_list():
'''Testing for lack of syntax error - not actual documentation'''
functions = {
'close': {
'documentation': {
'description': 'test',
'note': 'test',
},
},
}
config = {
'close_function': 'close'
}
close_doc = close_function_def_for_doc(functions, config)
assert type(close_doc) is dict
return
def test_close_function_def_for_doc_note_list():
'''Testing for lack of syntax error - not actual documentation'''
functions = {
'close': {
'documentation': {
'description': 'test',
'note': ['test'],
},
},
}
config = {
'close_function': 'close'
}
close_doc = close_function_def_for_doc(functions, config)
assert type(close_doc) is dict
return
def test_close_function_def_for_doc_no_note():
'''Testing for lack of syntax error - not actual documentation'''
functions = {
'close': {
'documentation': {
'description': 'test',
},
},
}
config = {
'close_function': 'close'
}
close_doc = close_function_def_for_doc(functions, config)
assert type(close_doc) is dict
def test_initiate_function_def_for_doc_note_not_list():
'''Testing for lack of syntax error - not actual documentation'''
functions = {
'Initiate': {
'documentation': {
'description': 'test',
'note': 'test',
},
'python_name': '_initiate',
},
}
config = {
'context_manager_name': {
'task': 'acquisition',
'initiate_function': 'Initiate',
'abort_function': 'Abort',
},
}
initiate_doc = initiate_function_def_for_doc(functions, config)
assert type(initiate_doc) is dict
return
def test_initiate_function_def_for_doc_note_list():
'''Testing for lack of syntax error - not actual documentation'''
functions = {
'Initiate': {
'documentation': {
'description': 'test',
'note': ['test'],
},
'python_name': '_initiate',
},
}
config = {
'context_manager_name': {
'task': 'acquisition',
'initiate_function': 'Initiate',
'abort_function': 'Abort',
},
}
initiate_doc = initiate_function_def_for_doc(functions, config)
assert type(initiate_doc) is dict
return
def test_initiate_function_def_for_doc_no_note():
'''Testing for lack of syntax error - not actual documentation'''
functions = {
'Initiate': {
'documentation': {
'description': 'test',
},
'python_name': '_initiate',
},
}
config = {
'context_manager_name': {
'task': 'acquisition',
'initiate_function': 'Initiate',
'abort_function': 'Abort',
},
}
initiate_doc = initiate_function_def_for_doc(functions, config)
assert type(initiate_doc) is dict