Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/h5py/version.py: 14%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

36 statements  

1# This file is part of h5py, a Python interface to the HDF5 library. 

2# 

3# http://www.h5py.org 

4# 

5# Copyright 2008-2013 Andrew Collette and contributors 

6# 

7# License: Standard 3-clause BSD; see "license.txt" for full license terms 

8# and contributor agreement. 

9 

10""" 

11 Versioning module for h5py. 

12""" 

13from typing import Literal, NamedTuple 

14from . import h5 as _h5 

15import sys 

16import numpy 

17 

18# All should be integers, except pre, as validating versions is more than is 

19# needed for our use case 

20class _H5PY_VERSION_CLS(NamedTuple): 

21 major: int 

22 minor: int 

23 bugfix: int 

24 pre: Literal["a", "b", "rc"] | None = None 

25 post: int | None = None 

26 dev: int | None = None 

27 

28 def __str__(self) -> str: 

29 s = f"{self.major}.{self.minor}.{self.bugfix}" 

30 if self.pre is not None: 

31 s += self.pre 

32 if self.post is not None: 

33 s += f".post{self.post}" 

34 if version_tuple.dev is not None: 

35 s += f".dev{self.dev}" 

36 return s 

37 

38hdf5_built_version_tuple = _h5.HDF5_VERSION_COMPILED_AGAINST 

39 

40# keep in sync with project.version (pyproject.toml) 

41version_tuple = _H5PY_VERSION_CLS(major=3, minor=17, bugfix=0, dev=0) 

42version = str(version_tuple) 

43 

44hdf5_version_tuple = _h5.get_libversion() 

45hdf5_version = "%d.%d.%d" % hdf5_version_tuple 

46 

47 

48def _hdf5_abi_compatible(built_version, running_version): 

49 """Can h5py built against ``built_version`` safely use ``running_version``? 

50 

51 From 2.0.0 onwards HDF5 guarantees ABI backwards compatibility within a 

52 major version: an application linked against X.Y.Z runs without 

53 recompilation against any later X.A.B. See 

54 https://github.com/HDFGroup/hdf5/wiki/HDF5-Version-Numbers-and-Branch-Strategy 

55 

56 HDF5 1.x predates that promise -- its minor number played the role the 

57 major number plays now, and the ABI was known to change even between 

58 maintenance releases (e.g. H5Oget_info* in 1.10.4) -- so there we only 

59 accept an exact match, as h5py always has. 

60 """ 

61 if running_version == built_version: 

62 return True 

63 

64 if built_version[0] < 2: 

65 return False 

66 

67 # The majors must match, and an older library of the same major version may 

68 # be missing symbols and features h5py was built against, so only accept 

69 # newer ones. 

70 return (running_version[0] == built_version[0]) and (running_version > built_version) 

71 

72api_version_tuple = (1,8) 

73api_version = "%d.%d" % api_version_tuple 

74 

75info = """\ 

76Summary of the h5py configuration 

77--------------------------------- 

78 

79h5py %(h5py)s 

80HDF5 %(hdf5)s 

81Python %(python)s 

82sys.platform %(platform)s 

83sys.maxsize %(maxsize)s 

84numpy %(numpy)s 

85cython (built with) %(cython_version)s 

86numpy (built against) %(numpy_build_version)s 

87HDF5 (built against) %(hdf5_build_version)s 

88""" % { 

89 'h5py': version, 

90 'hdf5': hdf5_version, 

91 'python': sys.version, 

92 'platform': sys.platform, 

93 'maxsize': sys.maxsize, 

94 'numpy': numpy.__version__, 

95 'cython_version': _h5.CYTHON_VERSION_COMPILED_WITH, 

96 'numpy_build_version': _h5.NUMPY_VERSION_COMPILED_AGAINST, 

97 'hdf5_build_version': "%d.%d.%d" % hdf5_built_version_tuple, 

98}