Coverage for /usr/lib/python3/dist-packages/h5py/__init__.py: 81%

32 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2025-06-14 15:25 +0200

1# avoid running mpi with serial (1 process) jobs 

2# by checking whether mpi is actually being used over multiple processes 

3# Probe number of processes with OMPI_COMM_WORLD_SIZE (openmpi) and MPI_LOCALNRANKS (mpich) 

4 

5from os import getenv as os_getenv 

6from sys import modules as sys_modules 

7from importlib import import_module 

8 

9_OPENMPI_MULTIPROC = os_getenv('OMPI_COMM_WORLD_SIZE') is not None 

10_MPICH_MULTIPROC = os_getenv('MPI_LOCALNRANKS') is not None 

11_MPI_USE_ALWAYS = os_getenv('H5PY_ALWAYS_USE_MPI') is not None 

12_MPI_USE_NEVER = os_getenv('H5PY_NEVER_USE_MPI') is not None 

13 

14_MPI_ACTIVE = (_OPENMPI_MULTIPROC or _MPICH_MULTIPROC) and not _MPI_USE_NEVER 

15 

16# H5PY_ALWAYS_USE_MPI takes precedence if H5PY_NEVER_USE_MPI is also set 

17if _MPI_ACTIVE or _MPI_USE_ALWAYS: 

18 try: 

19 from . import _debian_h5py_mpi as _h5py 

20 except: 

21 from . import _debian_h5py_serial as _h5py 

22else: 

23 try: 

24 from . import _debian_h5py_serial as _h5py 

25 except: 

26 from . import _debian_h5py_mpi as _h5py 

27 

28__version__ = _h5py.__version__ 

29 

30# make generic h5py module behaviour the same as specific builds 

31# by importing public and weak internal symbols (single _underscore) 

32api = [ k for k in _h5py.__dict__.keys() if not k.startswith('__') and not k.endswith('__') ] 

33this_module=sys_modules[__name__] 

34for key in api: 

35 # "imports" symbols (makes them accessible) 

36 setattr(this_module,key,getattr(_h5py,key)) 

37 # rename symbols as properties of toplevel h5py module 

38 sys_modules['h5py.{}'.format(key)] = getattr(_h5py,key) 

39del api 

40del this_module 

41 

42# tests are not loaded with h5py, but can be imported separately with 

43# "import h5py.tests" 

44tests = import_module('{}.tests'.format(_h5py.__name__)) 

45sys_modules['h5py.tests'] = tests 

46del tests 

47 

48# likewise for h5py_warnings 

49h5pyw = import_module('{}.h5py_warnings'.format(_h5py.__name__)) 

50sys_modules['h5py.h5py_warnings'] = h5pyw 

51del h5pyw 

52 

53del os_getenv, sys_modules, import_module