Skip to content

Commit 2faedc0

Browse files
committed
cleaned up and fixed few issues and review comments
1 parent 66b874a commit 2faedc0

File tree

13 files changed

+206
-3712
lines changed

13 files changed

+206
-3712
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ nidcpowerunittest.xml
2929
nidigitalunittest.xml
3030
nifakeunittest.xml
3131
nimodinstunittest.xml
32+
nirfsgunittest.xml
3233
niscopeunittest.xml
3334
nitclkunittest.xml
3435
codegen.xml

build/helper/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
from build.helper.metadata_filters import filter_library_functions # noqa: F401
5252
from build.helper.metadata_filters import filter_parameters # noqa: F401
5353
from build.helper.metadata_filters import filter_public_functions # noqa: F401
54-
from build.helper.metadata_filters import filter_rep_cap_supported_attributes
54+
from build.helper.metadata_filters import filter_rep_cap_supported_attributes # noqa: F401
5555

5656
from build.helper.metadata_find import find_custom_type # noqa: F401
5757
from build.helper.metadata_find import find_session_handle_parameter # noqa: F401

build/helper/documentation_helper.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from .documentation_snippets import enum_note_text
55
from .documentation_snippets import func_note_text
66
from .documentation_snippets import rep_cap_attr_desc
7+
from .documentation_snippets import rep_cap_attr_desc_without_global
78
from .documentation_snippets import rep_cap_method_desc
89
from .helper import get_array_type_for_api_type
910
from .helper import get_numpy_type_for_api_type
@@ -116,7 +117,10 @@ def add_attribute_rep_cap_tip(attr, config):
116117

117118
multi_capability = get_attribute_repeated_caps_with_conjunction(attr)
118119
single_capability = attr['supported_rep_caps'][0]
119-
attr['documentation']['tip'] = rep_cap_attr_desc.format(config['module_name'], multi_capability, single_capability, attr['python_name'])
120+
if config['repeated_capability_object_type']['python'] != 'applicable-attributes-only':
121+
attr['documentation']['tip'] = rep_cap_attr_desc.format(config['module_name'], multi_capability, single_capability, attr['python_name'])
122+
else:
123+
attr['documentation']['tip'] = rep_cap_attr_desc_without_global.format(config['module_name'], multi_capability, single_capability, attr['python_name'])
120124

121125

122126
def get_documentation_for_node_rst(node, config, indent=0):

build/helper/documentation_snippets.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
Example: :py:attr:`my_session.{3}`
2525
'''
2626

27+
rep_cap_attr_desc_without_global = '''
28+
This property can be set/get on specific {1} within your :py:class:`{0}.Session` instance.
29+
Use Python index notation on the repeated capabilities container {1} to specify a subset.
30+
31+
Example: :py:attr:`my_session.{2}[ ... ].{3}`
32+
'''
33+
2734
func_note_text = '''
2835
One or more of the referenced functions are not in the Python API for this driver.
2936
'''

build/helper/metadata_add_all.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
from .helper import get_python_type_for_api_type
1313
from .metadata_filters import filter_codegen_attributes
1414
from .metadata_filters import filter_codegen_functions
15-
from .metadata_filters import filter_rep_cap_supported_attributes
1615
from .metadata_find import find_custom_type
1716
from .metadata_find import find_size_parameter
1817
from .metadata_merge_dicts import merge_helper

build/helper/metadata_filters.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,11 +450,15 @@ def filter_codegen_enums(enums):
450450
'''Returns enum metadata only for those enums to be included in codegen'''
451451
return {k: v for k, v in enums.items() if v['codegen_method'] != 'no'}
452452

453+
453454
def filter_rep_cap_supported_attributes(attributes, rep_cap_name):
454455
'''Returns attribute metadata only for those attributes that support the specified repeated capability.
456+
455457
Args:
456458
attributes: Dictionary of attribute metadata.
459+
457460
rep_cap_name: The name of the repeated capability to filter by.
461+
458462
Returns:
459463
Dictionary of attributes that support the specified repeated capability.
460464
'''

build/templates/session.py.mako

Lines changed: 51 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ ${template_parameters['encoding_tag']}
33
<%
44
import build.helper as helper
55
import os
6+
from string import capwords
67
78
grpc_supported = template_parameters['include_grpc_support']
89
@@ -33,7 +34,9 @@ from functools import wraps
3334
% if attributes:
3435
import ${module_name}._attributes as _attributes
3536
% endif
37+
% if config['repeated_capability_object_type']['python'] != 'applicable-attributes-only':
3638
import ${module_name}._converters as _converters
39+
% endif
3740
import ${module_name}._library_interpreter as _library_interpreter
3841
import ${module_name}.enums as enums
3942
import ${module_name}.errors as errors
@@ -92,82 +95,71 @@ class _Lock(object):
9295
% endif
9396
% if len(config['repeated_capabilities']) > 0:
9497
% if config['repeated_capability_object_type']['python'] == 'applicable-attributes-only':
95-
% for rep_cap in config['repeated_capabilities']:
98+
class _RepeatedCapabilityAttributeOnlyBase(object):
99+
def __init__(self, session, prefix):
100+
object.__setattr__(self, '_session', session)
101+
object.__setattr__(self, '_prefix', prefix)
102+
object.__setattr__(self, '_repeated_capability', '')
103+
104+
def _get_attribute_vi_real64(self, attribute):
105+
value = self._session._interpreter.get_attribute_vi_real64(self._prefix + self._repeated_capability, attribute)
106+
return value
107+
108+
def _set_attribute_vi_real64(self, attribute, value):
109+
self._session._interpreter.set_attribute_vi_real64(self._prefix + self._repeated_capability, attribute, value)
110+
111+
def _get_attribute_vi_int32(self, attribute):
112+
value = self._session._interpreter.get_attribute_vi_int32(self._prefix + self._repeated_capability, attribute)
113+
return value
114+
115+
def _set_attribute_vi_int32(self, attribute, value):
116+
self._session._interpreter.set_attribute_vi_int32(self._prefix + self._repeated_capability, attribute, value)
96117

97-
class _RepeatedCapability${rep_cap['python_name'].capitalize()}(object):
98-
% for attribute in helper.sorted_attrs(helper.filter_rep_cap_supported_attributes(attributes, rep_cap['python_name'])):
118+
def _get_attribute_vi_string(self, attribute):
119+
value = self._session._interpreter.get_attribute_vi_string(self._prefix + self._repeated_capability, attribute)
120+
return value
121+
122+
def _set_attribute_vi_string(self, attribute, value):
123+
self._session._interpreter.set_attribute_vi_string(self._prefix + self._repeated_capability, attribute, value)
124+
125+
126+
% for rep_cap in config['repeated_capabilities']:
127+
class _RepeatedCapability${capwords(rep_cap['python_name'].replace('_', ' ')).replace(' ', '')}(_RepeatedCapabilityAttributeOnlyBase):
128+
% for attribute in helper.sorted_attrs(helper.filter_rep_cap_supported_attributes(attributes, rep_cap['python_name'])):
99129
<%
100130
helper.add_attribute_rep_cap_tip(attributes[attribute], config)
101131
%>\
102-
% if attributes[attribute]['enum']:
103-
% if helper.enum_uses_converter(enums[attributes[attribute]['enum']]):
132+
% if attributes[attribute]['enum']:
133+
% if helper.enum_uses_converter(enums[attributes[attribute]['enum']]):
104134
${attributes[attribute]['python_name']} = _attributes.AttributeEnumWithConverter(_attributes.AttributeEnum(_attributes.Attribute${attributes[attribute]['type']}, enums.${enums[attributes[attribute]['enum']]['python_name']}, ${attribute}), _converters.${enums[attributes[attribute]['enum']]['enum_to_converted_value_function_name']}, _converters.${enums[attributes[attribute]['enum']]['converted_value_to_enum_function_name']})
105-
% else:
135+
% else:
106136
${attributes[attribute]['python_name']} = _attributes.AttributeEnum(_attributes.Attribute${attributes[attribute]['type']}, enums.${enums[attributes[attribute]['enum']]['python_name']}, ${attribute})
107-
% endif
108-
% else:
137+
% endif
138+
% else:
109139
${attributes[attribute]['python_name']} = _attributes.${attributes[attribute]['attribute_class']}(${attribute})
110-
% endif
111-
% if 'documentation' in attributes[attribute] and len(helper.get_documentation_for_node_docstring(attributes[attribute], config, indent=4).strip()) > 0:
140+
% endif
141+
% if 'documentation' in attributes[attribute] and len(helper.get_documentation_for_node_docstring(attributes[attribute], config, indent=4).strip()) > 0:
112142
'''Type: ${attributes[attribute]['type_in_documentation']}
113143

114144
${helper.get_documentation_for_node_docstring(attributes[attribute], config, indent=4)}
115145
'''
116-
% endif
117-
% endfor
118-
def __init__(self, session, repeated_capability_list):
119-
object.__setattr__(self, '_session', session)
120-
object.__setattr__(self, '_repeated_capability_list', repeated_capability_list)
121-
object.__setattr__(self, '_prefix', '${rep_cap["prefix"]}')
122-
object.__setattr__(self, '_current_repeated_capability_list', repeated_capability_list if len(repeated_capability_list) > 0 else [''])
123-
object.__setattr__(self, '_separator', '')
146+
% endif
147+
% endfor
148+
def __init__(self, session):
149+
super(_RepeatedCapability${capwords(rep_cap['python_name'].replace('_', ' ')).replace(' ', '')}, self).__init__(session, '${rep_cap["prefix"]}')
124150

125151
def __setattr__(self, key, value):
126152
if key not in dir(self):
127153
raise AttributeError("'{0}' object has no attribute '{1}'".format(type(self).__name__, key))
128154
object.__setattr__(self, key, value)
129155

130156
def __getitem__(self, repeated_capability):
131-
'''Set/get properties or call methods with a repeated capability (i.e. channels)'''
132-
rep_caps_list = _converters.convert_repeated_capabilities(repeated_capability, self._prefix)
133-
complete_rep_cap_list = [
134-
current_rep_cap + self._separator + rep_cap
135-
for current_rep_cap in self._current_repeated_capability_list
136-
for rep_cap in rep_caps_list
137-
]
138-
object.__setattr__(self, '_current_repeated_capability_list', complete_rep_cap_list)
139-
self._current_repeated_capability_list = complete_rep_cap_list
140-
157+
super(_RepeatedCapability${capwords(rep_cap['python_name'].replace('_', ' ')).replace(' ', '')}, self).__setattr__('_repeated_capability', repeated_capability)
141158
return self
142159

143-
def _get_attribute_vi_real64(self, attribute):
144-
repeated_capability = ','.join(self._current_repeated_capability_list)
145-
value = self._session._interpreter.get_attribute_vi_real64(repeated_capability, attribute)
146-
return value
147-
148-
def _set_attribute_vi_real64(self, attribute, value):
149-
repeated_capability = ','.join(self._current_repeated_capability_list)
150-
self._session._interpreter.set_attribute_vi_real64(repeated_capability, attribute, value)
151-
152-
def _get_attribute_vi_int32(self, attribute):
153-
repeated_capability = ','.join(self._current_repeated_capability_list)
154-
value = self._session._interpreter.get_attribute_vi_int32(repeated_capability, attribute)
155-
return value
156160

157-
def _set_attribute_vi_int32(self, attribute, value):
158-
repeated_capability = ','.join(self._current_repeated_capability_list)
159-
self._session._interpreter.set_attribute_vi_int32(repeated_capability, attribute, value)
160-
161-
def _get_attribute_vi_string(self, attribute):
162-
repeated_capability = ','.join(self._current_repeated_capability_list)
163-
value = self._session._interpreter.get_attribute_vi_string(repeated_capability, attribute)
164-
return value
165-
166-
def _set_attribute_vi_string(self, attribute, value):
167-
repeated_capability = ','.join(self._current_repeated_capability_list)
168-
self._session._interpreter.set_attribute_vi_string(repeated_capability, attribute, value)
169-
% endfor
170-
% else:
161+
% endfor
162+
% else:
171163
class _RepeatedCapabilities(object):
172164
def __init__(self, session, prefix, current_repeated_capability_list):
173165
self._session = session
@@ -205,7 +197,7 @@ class _NoChannel(object):
205197
self._session._repeated_capability = self._repeated_capability_cache
206198

207199

208-
% endif
200+
% endif
209201
% endif
210202
class _SessionBase(object):
211203
'''Base class for all ${config['driver_name']} sessions.'''
@@ -214,12 +206,8 @@ class _SessionBase(object):
214206
_is_frozen = False
215207

216208
% for attribute in helper.sorted_attrs(helper.filter_codegen_attributes(attributes)):
209+
% if not ('supported_rep_caps' in attributes[attribute] and len(attributes[attribute]['supported_rep_caps']) > 0 and config['repeated_capability_object_type']['python'] == 'applicable-attributes-only'):
217210
<%
218-
# Skip attributes with repeated capability expansion set to "applicable-attributes-only"
219-
if 'repeated_capability_type' in attributes[attribute]:
220-
rep_cap_type = attributes[attribute]['repeated_capability_type']
221-
if any(rep_cap.get('python_name') == rep_cap_type and config['repeated_capability_object_type'] == 'applicable-attributes-only' for rep_cap in config['repeated_capabilities']):
222-
continue
223211
helper.add_attribute_rep_cap_tip(attributes[attribute], config)
224212
%>\
225213
%if attributes[attribute]['enum']:
@@ -237,6 +225,7 @@ helper.add_attribute_rep_cap_tip(attributes[attribute], config)
237225
${helper.get_documentation_for_node_docstring(attributes[attribute], config, indent=4)}
238226
'''
239227
% endif
228+
% endif
240229
% endfor
241230
<%
242231
init_function = config['functions']['_init_function']
@@ -263,7 +252,7 @@ constructor_params = helper.filter_parameters(init_function['parameters'], helpe
263252
# Instantiate any repeated capability objects
264253
% for rep_cap in config['repeated_capabilities']:
265254
% if config['repeated_capability_object_type']['python'] == 'applicable-attributes-only':
266-
self.${rep_cap['python_name']} = _RepeatedCapability${rep_cap['python_name'].capitalize()}(self, repeated_capability_list)
255+
self.${rep_cap['python_name']} = _RepeatedCapability${capwords(rep_cap['python_name'].replace('_', ' ')).replace(' ', '')}(self)
267256
% else:
268257
self.${rep_cap['python_name']} = _RepeatedCapabilities(self, '${rep_cap["prefix"]}', repeated_capability_list)
269258
% endif

build/unit_tests/test_metadata_add_all.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -979,6 +979,9 @@ def _compare_dicts(actual, expected):
979979
},
980980
],
981981
'enum_whitelist_suffix': ['_POINT_FIVE'],
982+
'repeated_capability_object_type': {
983+
'python': 'session'
984+
},
982985
'repeated_capabilities': [
983986
{'python_name': 'channels', 'prefix': '', },
984987
],

0 commit comments

Comments
 (0)