Skip to content

Commit

Permalink
Add nitclk template changes (#1026)
Browse files Browse the repository at this point in the history
* Add initial metadata

* Create nitclk.mak

* Remove numpy restriction

Bug fixed

* Upgrade pip

* Remove specific version of flake8

'\' in comments now need to be escaped

* Add basepython section

* Try using pypy3.5

* Go back to pypy3 and remove basepython block

* Don't need to run build_test for all builds - only 3.6

* Remove warning from coverage

* Undo previous change

* Try disabling faulthandler

* Remove --no-faulthandler

* pypy needs an older version of pytest

See pytest-dev/pytest#5807

* Use platform_python_implementation since implementation_name is not defined on Python2

* Try to get back to the initial coverage

* Do the same thing for build_test

* Remove redundant pip

* Add codecov file to try to control limits for passing

* Enable nitclk build

* There are some files we will need to skip for now

* Add generated nitclk files

* Update generated files

* Can't skip README.rst

* Update templates

* Add new cases for buffers with a converter

* Need to handle ' []' to normalize everything

* Get the session handle name from config instead of hardcoding 'vi'

* Temp commit

* Fix syntax error

* Test new cases

* Force change

* Update generated files

* Update generated files

* Add different target for pr (project) and commit (patch)

* threshold should be number

* Renumber scaler cases to be in order used in the code

* Update generated files

* Renumber buffer cases to match order used in code

* Move and rename test to match case (C020)

* Update generated files

* Be consistent with spaces before #

* Change comments based on review

* Change logic per PR review

* Add comment per PR review

* Don't contitionally add code - every driver gets all attribute types and converters

* Move nifake test converter after nitclk converter

* Update generated files

* Update comment based on review

* Change to session_number based on review

* Update generated files

* Lower target for now

* Drop target until tests added later

* Force a rebuild
  • Loading branch information
texasaggie97-zz authored and marcoskirsch committed Sep 18, 2019
1 parent 4e05b9a commit 8da41e7
Show file tree
Hide file tree
Showing 33 changed files with 545 additions and 46 deletions.
4 changes: 2 additions & 2 deletions .codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ coverage:
status:
project:
default:
target: 90%
target: 85%
threshhold: 5
patch:
default:
target: 70%
target: 35%
threshhold: 5

33 changes: 30 additions & 3 deletions build/templates/__init__.py.mako
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
${template_parameters['encoding_tag']}
# This file was generated
<%
import build.helper as helper
enums = template_parameters['metadata'].enums
functions = helper.filter_codegen_functions(template_parameters['metadata'].functions)
config = template_parameters['metadata'].config
module_name = config['module_name']
registry_name = config['driver_registry'] if 'driver_registry' in config else config['driver_name']
Expand All @@ -10,11 +13,35 @@ registry_name = config['driver_registry'] if 'driver_registry' in config else co
__version__ = '${config['module_version']}'

% if len(enums) > 0:
from ${module_name}.enums import * # noqa: F403,F401,H303
from ${module_name}.enums import * # noqa: F403,F401,H303
% endif
from ${module_name}.errors import DriverWarning # noqa: F401
from ${module_name}.errors import Error # noqa: F401
from ${module_name}.errors import DriverWarning # noqa: F401
from ${module_name}.errors import Error # noqa: F401
<%
# nitclk is different. It does not have a Session class that we open a session on
# Instead it is a bunch of stateless function calls. So if we are NOT building for
# nitclk, we import the Session class. If it is nitclk then we will
# import each function and the SessionReference class
%>\
% if config['module_name'] == 'nitclk':
from ${module_name}.session import SessionReference # noqa: F401

# Function imports
<%
# There two types of functions in `nitclk`:
#
# 1. Functions that take a single SessionReference (get/set attribute)
# 2. Functions that take in a list of SessionReference
#
# The second type are the public functions that clients will call, so we need to import them explicitly into
# the `nitclk` namespace. We are using the `render_in_session_base` metadata in order to distinguish them
%>\
% for func_name in sorted([functions[k]['python_name'] for k in functions if not functions[k]['render_in_session_base']]):
from ${module_name}.session import ${func_name} # noqa: F401
% endfor
% else:
from ${module_name}.session import Session # noqa: F401
% endif
<%
# Blank lines are to make each import separate so that they do not need to be sorted
# Otherwise flake8 test fails
Expand Down
13 changes: 13 additions & 0 deletions build/templates/_attributes.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ ${template_parameters['encoding_tag']}
# This file was generated
<%
module_name = template_parameters['metadata'].config['module_name']
config = template_parameters['metadata'].config
%>\
import ${module_name}._converters as _converters

Expand Down Expand Up @@ -112,4 +113,16 @@ class AttributeEnum(object):
return self._underlying_attribute.__set__(session, value.value)


# nitclk specific attribute type
class AttributeViInt32SessionReference(Attribute):

def __get__(self, session, session_type):
# Import here to avoid a circular dependency when initial import happens
from ${module_name}.session import SessionReference
return SessionReference(session._get_attribute_vi_int32(self._attribute_id))

def __set__(self, session, value):
session._set_attribute_vi_int32(self._attribute_id, _converters.convert_to_nitclk_session_number(value))



40 changes: 33 additions & 7 deletions build/templates/_converters.py.mako
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,6 @@ def convert_month_to_timedelta(months):
return datetime.timedelta(days=(30.4167 * months))


% if config['module_name'] == 'nifake':
# nifake specific converter(s) - used only for testing
def convert_double_each_element(numbers):
return [x * 2 for x in numbers]


% endif
# This converter is not called from the normal codegen path for function. Instead it is
# call from init and is a special case. Also, it just returns a string rather than a ctype object
def convert_init_with_options_dictionary(values, encoding):
Expand Down Expand Up @@ -222,6 +215,39 @@ def convert_init_with_options_dictionary(values, encoding):
return init_with_options_string


# nitclk specific converters
def convert_to_nitclk_session_number(item):
'''Convert from supported objects to NI-TClk Session Num

Supported objects are:
- class with .tclk object of type nitclk.SessionReference
- nitclk.SessionReference
- NI-TClk Session Num
'''
try:
return item.tclk.get_session_number()
except KeyError:
pass

try:
return item.get_session_number()
except KeyError:
pass

# If we haven't gotten a SessionReference, we assume the item is the actual nitclk session num and return it
return item


def convert_to_nitclk_session_number_list(item_list):
'''Converts a list of items to nitclk session nums'''
return [convert_to_nitclk_session_number(i) for i in item_list]


# nifake specific converter(s) - used only for testing
def convert_double_each_element(numbers):
return [x * 2 for x in numbers]


# Let's run some tests
def test_convert_init_with_options_dictionary():
assert convert_init_with_options_dictionary('', 'ascii') == ''
Expand Down
6 changes: 3 additions & 3 deletions generated/nidcpower/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

__version__ = '1.1.3.dev0'

from nidcpower.enums import * # noqa: F403,F401,H303
from nidcpower.errors import DriverWarning # noqa: F401
from nidcpower.errors import Error # noqa: F401
from nidcpower.enums import * # noqa: F403,F401,H303
from nidcpower.errors import DriverWarning # noqa: F401
from nidcpower.errors import Error # noqa: F401
from nidcpower.session import Session # noqa: F401


Expand Down
12 changes: 12 additions & 0 deletions generated/nidcpower/_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,16 @@ def __set__(self, session, value):
return self._underlying_attribute.__set__(session, value.value)


# nitclk specific attribute type
class AttributeViInt32SessionReference(Attribute):

def __get__(self, session, session_type):
# Import here to avoid a circular dependency when initial import happens
from nidcpower.session import SessionReference
return SessionReference(session._get_attribute_vi_int32(self._attribute_id))

def __set__(self, session, value):
session._set_attribute_vi_int32(self._attribute_id, _converters.convert_to_nitclk_session_number(value))



33 changes: 33 additions & 0 deletions generated/nidcpower/_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,39 @@ def convert_init_with_options_dictionary(values, encoding):
return init_with_options_string


# nitclk specific converters
def convert_to_nitclk_session_number(item):
'''Convert from supported objects to NI-TClk Session Num
Supported objects are:
- class with .tclk object of type nitclk.SessionReference
- nitclk.SessionReference
- NI-TClk Session Num
'''
try:
return item.tclk.get_session_number()
except KeyError:
pass

try:
return item.get_session_number()
except KeyError:
pass

# If we haven't gotten a SessionReference, we assume the item is the actual nitclk session num and return it
return item


def convert_to_nitclk_session_number_list(item_list):
'''Converts a list of items to nitclk session nums'''
return [convert_to_nitclk_session_number(i) for i in item_list]


# nifake specific converter(s) - used only for testing
def convert_double_each_element(numbers):
return [x * 2 for x in numbers]


# Let's run some tests
def test_convert_init_with_options_dictionary():
assert convert_init_with_options_dictionary('', 'ascii') == ''
Expand Down
6 changes: 3 additions & 3 deletions generated/nidigital/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

__version__ = '0.1.1.dev0'

from nidigital.enums import * # noqa: F403,F401,H303
from nidigital.errors import DriverWarning # noqa: F401
from nidigital.errors import Error # noqa: F401
from nidigital.enums import * # noqa: F403,F401,H303
from nidigital.errors import DriverWarning # noqa: F401
from nidigital.errors import Error # noqa: F401
from nidigital.session import Session # noqa: F401


Expand Down
12 changes: 12 additions & 0 deletions generated/nidigital/_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,16 @@ def __set__(self, session, value):
return self._underlying_attribute.__set__(session, value.value)


# nitclk specific attribute type
class AttributeViInt32SessionReference(Attribute):

def __get__(self, session, session_type):
# Import here to avoid a circular dependency when initial import happens
from nidigital.session import SessionReference
return SessionReference(session._get_attribute_vi_int32(self._attribute_id))

def __set__(self, session, value):
session._set_attribute_vi_int32(self._attribute_id, _converters.convert_to_nitclk_session_number(value))



33 changes: 33 additions & 0 deletions generated/nidigital/_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,39 @@ def convert_init_with_options_dictionary(values, encoding):
return init_with_options_string


# nitclk specific converters
def convert_to_nitclk_session_number(item):
'''Convert from supported objects to NI-TClk Session Num
Supported objects are:
- class with .tclk object of type nitclk.SessionReference
- nitclk.SessionReference
- NI-TClk Session Num
'''
try:
return item.tclk.get_session_number()
except KeyError:
pass

try:
return item.get_session_number()
except KeyError:
pass

# If we haven't gotten a SessionReference, we assume the item is the actual nitclk session num and return it
return item


def convert_to_nitclk_session_number_list(item_list):
'''Converts a list of items to nitclk session nums'''
return [convert_to_nitclk_session_number(i) for i in item_list]


# nifake specific converter(s) - used only for testing
def convert_double_each_element(numbers):
return [x * 2 for x in numbers]


# Let's run some tests
def test_convert_init_with_options_dictionary():
assert convert_init_with_options_dictionary('', 'ascii') == ''
Expand Down
6 changes: 3 additions & 3 deletions generated/nidmm/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

__version__ = '1.1.3.dev0'

from nidmm.enums import * # noqa: F403,F401,H303
from nidmm.errors import DriverWarning # noqa: F401
from nidmm.errors import Error # noqa: F401
from nidmm.enums import * # noqa: F403,F401,H303
from nidmm.errors import DriverWarning # noqa: F401
from nidmm.errors import Error # noqa: F401
from nidmm.session import Session # noqa: F401


Expand Down
12 changes: 12 additions & 0 deletions generated/nidmm/_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,16 @@ def __set__(self, session, value):
return self._underlying_attribute.__set__(session, value.value)


# nitclk specific attribute type
class AttributeViInt32SessionReference(Attribute):

def __get__(self, session, session_type):
# Import here to avoid a circular dependency when initial import happens
from nidmm.session import SessionReference
return SessionReference(session._get_attribute_vi_int32(self._attribute_id))

def __set__(self, session, value):
session._set_attribute_vi_int32(self._attribute_id, _converters.convert_to_nitclk_session_number(value))



33 changes: 33 additions & 0 deletions generated/nidmm/_converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,39 @@ def convert_init_with_options_dictionary(values, encoding):
return init_with_options_string


# nitclk specific converters
def convert_to_nitclk_session_number(item):
'''Convert from supported objects to NI-TClk Session Num
Supported objects are:
- class with .tclk object of type nitclk.SessionReference
- nitclk.SessionReference
- NI-TClk Session Num
'''
try:
return item.tclk.get_session_number()
except KeyError:
pass

try:
return item.get_session_number()
except KeyError:
pass

# If we haven't gotten a SessionReference, we assume the item is the actual nitclk session num and return it
return item


def convert_to_nitclk_session_number_list(item_list):
'''Converts a list of items to nitclk session nums'''
return [convert_to_nitclk_session_number(i) for i in item_list]


# nifake specific converter(s) - used only for testing
def convert_double_each_element(numbers):
return [x * 2 for x in numbers]


# Let's run some tests
def test_convert_init_with_options_dictionary():
assert convert_init_with_options_dictionary('', 'ascii') == ''
Expand Down
6 changes: 3 additions & 3 deletions generated/nifake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

__version__ = '1.1.3.dev0'

from nifake.enums import * # noqa: F403,F401,H303
from nifake.errors import DriverWarning # noqa: F401
from nifake.errors import Error # noqa: F401
from nifake.enums import * # noqa: F403,F401,H303
from nifake.errors import DriverWarning # noqa: F401
from nifake.errors import Error # noqa: F401
from nifake.session import Session # noqa: F401

from nifake.custom_struct import CustomStruct # noqa: F401
Expand Down
12 changes: 12 additions & 0 deletions generated/nifake/_attributes.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,4 +109,16 @@ def __set__(self, session, value):
return self._underlying_attribute.__set__(session, value.value)


# nitclk specific attribute type
class AttributeViInt32SessionReference(Attribute):

def __get__(self, session, session_type):
# Import here to avoid a circular dependency when initial import happens
from nifake.session import SessionReference
return SessionReference(session._get_attribute_vi_int32(self._attribute_id))

def __set__(self, session, value):
session._set_attribute_vi_int32(self._attribute_id, _converters.convert_to_nitclk_session_number(value))



0 comments on commit 8da41e7

Please sign in to comment.