Source code for brainaccess.core.version

import ctypes
from brainaccess.core import _dll


[docs] class Version(ctypes.Structure): """A version number: major, minor and patch. Returned by :func:`brainaccess.core.get_version` and as the hardware and firmware versions in :class:`~brainaccess.core.device_info.DeviceInfo`. Printing it gives ``major.minor.patch``. Attributes ---------- major : int Major version; changes when the interface changes incompatibly. minor : int Minor version; changes when functionality is added. patch : int Patch version; changes for bug fixes. """ _fields_ = [ ("major", ctypes.c_uint8), ("minor", ctypes.c_uint8), ("patch", ctypes.c_uint8), ] def __init__(self, major, minor, patch):
[docs] self.major = major
[docs] self.minor = minor
[docs] self.patch = patch
def __repr__(self): return "{0}.{1}.{2}".format(self.major, self.minor, self.patch)
_dll.ba_is_version_compatible.argtypes = [ ctypes.POINTER(Version), ctypes.POINTER(Version), ] _dll.ba_is_version_compatible.restype = ctypes.c_bool
[docs] def is_version_compatible(expected: Version, actual: Version) -> bool: """Check whether two versions are compatible. Versions are compatible if their major and minor numbers are the same; the patch number is ignored. Parameters ---------- expected : Version The required version. actual : Version The version to check. Returns ------- bool ``True`` if the versions are compatible. """ return _dll.ba_is_version_compatible( ctypes.pointer(expected), ctypes.pointer(actual) )