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

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

54 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 This is the h5py package, a Python interface to the HDF5 

12 scientific data format. 

13""" 

14 

15from warnings import warn as _warn 

16import atexit 

17 

18 

19# --- Library setup ----------------------------------------------------------- 

20 

21# When importing from the root of the unpacked tarball or git checkout, 

22# Python sees the "h5py" source directory and tries to load it, which fails. 

23# We tried working around this by using "package_dir" but that breaks Cython. 

24try: 

25 from . import _errors 

26except ImportError: 

27 import os.path as _op 

28 if _op.exists(_op.join(_op.dirname(__file__), '..', 'setup.py')): 

29 raise ImportError("You cannot import h5py from inside the install directory.\nChange to another directory first.") 

30 else: 

31 raise 

32 

33from . import version 

34 

35if not version._hdf5_abi_compatible( 

36 version.hdf5_built_version_tuple, version.hdf5_version_tuple 

37): 

38 _warn(("h5py is running against HDF5 {0} when it was built against {1}, " 

39 "this may cause problems").format( 

40 '{0}.{1}.{2}'.format(*version.hdf5_version_tuple), 

41 '{0}.{1}.{2}'.format(*version.hdf5_built_version_tuple) 

42 )) 

43 

44 

45_errors.silence_errors() 

46 

47from ._conv import register_converters as _register_converters, \ 

48 unregister_converters as _unregister_converters 

49_register_converters() 

50atexit.register(_unregister_converters) 

51 

52from .h5z import _register_lzf 

53_register_lzf() 

54 

55 

56# --- Public API -------------------------------------------------------------- 

57 

58from . import h5a, h5d, h5ds, h5f, h5fd, h5g, h5r, h5s, h5t, h5p, h5z, h5pl 

59 

60from ._hl import filters 

61from ._hl.base import is_hdf5, HLObject, Empty 

62from ._hl.files import ( 

63 File, 

64 register_driver, 

65 unregister_driver, 

66 registered_drivers, 

67) 

68from ._hl.group import Group, SoftLink, ExternalLink, HardLink 

69from ._hl.dataset import Dataset 

70from ._hl.datatype import Datatype 

71from ._hl.attrs import AttributeManager 

72from ._hl.vds import VirtualSource, VirtualLayout 

73 

74from ._selector import MultiBlockSlice 

75from .h5 import get_config 

76from .h5r import Reference, RegionReference 

77from .h5t import (special_dtype, check_dtype, 

78 vlen_dtype, string_dtype, enum_dtype, ref_dtype, regionref_dtype, 

79 opaque_dtype, complex_compat_dtype, 

80 check_vlen_dtype, check_string_dtype, check_enum_dtype, check_ref_dtype, 

81 check_opaque_dtype, check_complex_dtype, 

82) 

83from .h5s import UNLIMITED 

84 

85from .version import version as __version__ 

86 

87 

88def run_tests(args=''): 

89 """Run tests with pytest and returns the exit status as an int. 

90 """ 

91 # Lazy-loading of tests package to avoid strong dependency on test 

92 # requirements, e.g. pytest 

93 from .tests import run_tests 

94 return run_tests(args) 

95 

96 

97def enable_ipython_completer(): 

98 """ Call this from an interactive IPython session to enable tab-completion 

99 of group and attribute names. 

100 """ 

101 import sys 

102 if 'IPython' in sys.modules: 

103 ip_running = False 

104 try: 

105 from IPython.core.interactiveshell import InteractiveShell 

106 ip_running = InteractiveShell.initialized() 

107 except ImportError: 

108 # support <ipython-0.11 

109 from IPython import ipapi as _ipapi 

110 ip_running = _ipapi.get() is not None 

111 except Exception: 

112 pass 

113 if ip_running: 

114 from . import ipy_completer 

115 return ipy_completer.load_ipython_extension() 

116 

117 raise RuntimeError('Completer must be enabled in active ipython session')