__init__.py 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. This is the h5py package, a Python interface to the HDF5
  11. scientific data format.
  12. """
  13. from warnings import warn as _warn
  14. import atexit
  15. # --- Library setup -----------------------------------------------------------
  16. # When importing from the root of the unpacked tarball or git checkout,
  17. # Python sees the "h5py" source directory and tries to load it, which fails.
  18. # We tried working around this by using "package_dir" but that breaks Cython.
  19. try:
  20. from . import _errors
  21. except ImportError:
  22. import os.path as _op
  23. if _op.exists(_op.join(_op.dirname(__file__), '..', 'setup.py')):
  24. raise ImportError("You cannot import h5py from inside the install directory.\nChange to another directory first.")
  25. else:
  26. raise
  27. from . import version
  28. if version.hdf5_version_tuple != version.hdf5_built_version_tuple:
  29. _warn(("h5py is running against HDF5 {0} when it was built against {1}, "
  30. "this may cause problems").format(
  31. '{0}.{1}.{2}'.format(*version.hdf5_version_tuple),
  32. '{0}.{1}.{2}'.format(*version.hdf5_built_version_tuple)
  33. ))
  34. _errors.silence_errors()
  35. from ._conv import register_converters as _register_converters, \
  36. unregister_converters as _unregister_converters
  37. _register_converters()
  38. atexit.register(_unregister_converters)
  39. from .h5z import _register_lzf
  40. _register_lzf()
  41. # --- Public API --------------------------------------------------------------
  42. from . import h5a, h5d, h5ds, h5f, h5fd, h5g, h5r, h5s, h5t, h5p, h5z, h5pl
  43. from ._hl import filters
  44. from ._hl.base import is_hdf5, HLObject, Empty
  45. from ._hl.files import (
  46. File,
  47. register_driver,
  48. unregister_driver,
  49. registered_drivers,
  50. )
  51. from ._hl.group import Group, SoftLink, ExternalLink, HardLink
  52. from ._hl.dataset import Dataset
  53. from ._hl.datatype import Datatype
  54. from ._hl.attrs import AttributeManager
  55. from ._selector import MultiBlockSlice
  56. from .h5 import get_config
  57. from .h5r import Reference, RegionReference
  58. from .h5t import (special_dtype, check_dtype,
  59. vlen_dtype, string_dtype, enum_dtype, ref_dtype, regionref_dtype,
  60. opaque_dtype,
  61. check_vlen_dtype, check_string_dtype, check_enum_dtype, check_ref_dtype,
  62. check_opaque_dtype,
  63. )
  64. from .h5s import UNLIMITED
  65. from .version import version as __version__
  66. if version.hdf5_version_tuple[:3] >= get_config().vds_min_hdf5_version:
  67. from ._hl.vds import VirtualSource, VirtualLayout
  68. def run_tests(args=''):
  69. """Run tests with pytest and returns the exit status as an int.
  70. """
  71. # Lazy-loading of tests package to avoid strong dependency on test
  72. # requirements, e.g. pytest
  73. from .tests import run_tests
  74. return run_tests(args)
  75. def enable_ipython_completer():
  76. """ Call this from an interactive IPython session to enable tab-completion
  77. of group and attribute names.
  78. """
  79. import sys
  80. if 'IPython' in sys.modules:
  81. ip_running = False
  82. try:
  83. from IPython.core.interactiveshell import InteractiveShell
  84. ip_running = InteractiveShell.initialized()
  85. except ImportError:
  86. # support <ipython-0.11
  87. from IPython import ipapi as _ipapi
  88. ip_running = _ipapi.get() is not None
  89. except Exception:
  90. pass
  91. if ip_running:
  92. from . import ipy_completer
  93. return ipy_completer.load_ipython_extension()
  94. raise RuntimeError('Completer must be enabled in active ipython session')