forked from ni/nimi-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitialization_method.py.mako
More file actions
50 lines (44 loc) · 2.68 KB
/
initialization_method.py.mako
File metadata and controls
50 lines (44 loc) · 2.68 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
<%page args="f, config, method_template"/>\
<%
'''Renders a LibraryInterpreter initialization method, specifying the session should be closed on exit.'''
import build.helper as helper
grpc_supported = template_parameters['include_grpc_support']
parameters = f['parameters']
param_names_method = helper.get_params_snippet(f, helper.ParameterUsageOptions.INTERPRETER_METHOD_DECLARATION)
param_names_library = helper.get_params_snippet(f, helper.ParameterUsageOptions.LIBRARY_METHOD_CALL)
ivi_dance_parameters = helper.filter_ivi_dance_parameters(parameters)
ivi_dance_size_parameter = helper.find_size_parameter(ivi_dance_parameters, parameters)
len_parameters = helper.filter_len_parameters(parameters)
len_size_parameters = helper.find_size_parameter(len_parameters, parameters)
assert ivi_dance_size_parameter is None or len_size_parameters is None
full_func_name = f['interpreter_name'] + method_template['method_python_name_suffix']
c_func_name = config['c_function_prefix'] + f['name']
# If a method uses codegen_method=python-only, it should specify non-default method_templates
assert f['codegen_method'] != 'python-only', full_func_name + ' uses default_method method_template, but is python-only!'
%>\
def ${full_func_name}(${param_names_method}): # noqa: N802
% for p in helper.filter_parameters(parameters, helper.ParameterUsageOptions.LIBRARY_METHOD_CALL):
<% ivi_dance_step = helper.IviDanceStep.QUERY_SIZE if (p in ivi_dance_parameters or p == ivi_dance_size_parameter) else helper.IviDanceStep.NOT_APPLICABLE %>\
% for declaration in helper.get_ctype_variable_declaration_snippet(p, parameters, ivi_dance_step, config):
${declaration}
% endfor
% endfor
% if len(ivi_dance_parameters) > 0:
<% ivi_dance_step = helper.IviDanceStep.GET_DATA %>\
error_code = self._library.${c_func_name}(${param_names_library})
errors.handle_error(self, error_code, ignore_warnings=True, is_error_handling=${f['is_error_handling']})
% for declaration in helper.get_ctype_variable_declaration_snippet(ivi_dance_size_parameter, parameters, ivi_dance_step, config):
${declaration}
% endfor
% for param in ivi_dance_parameters:
% for declaration in helper.get_ctype_variable_declaration_snippet(param, parameters, ivi_dance_step, config):
${declaration}
% endfor
% endfor
% endif
error_code = self._library.${c_func_name}(${param_names_library})
errors.handle_error(self, error_code, ignore_warnings=False, is_error_handling=${f['is_error_handling']})
% if grpc_supported:
self._close_on_exit = True
% endif
${helper.get_library_interpreter_method_return_snippet(parameters, config)}