From 8e197546ba9df44d849d4ba1fce141bb48810aac Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Fri, 26 Jun 2015 16:47:44 -0600 Subject: [PATCH 1/2] Allow Python API to be used without h5py --- openmc/summary.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/openmc/summary.py b/openmc/summary.py index 61fb89a1e..f72562081 100644 --- a/openmc/summary.py +++ b/openmc/summary.py @@ -2,17 +2,22 @@ import numpy as np import openmc -try: - import h5py -except ImportError: - msg = 'Unable to import h5py which is needed by openmc.summary' - raise ImportError(msg) + +_h5_imported = False class Summary(object): def __init__(self, filename): + if not _h5_imported: + try: + import h5py + _h5_imported = True + except ImportError: + msg = 'Unable to import h5py which is needed by openmc.summary' + raise ImportError(msg) + openmc.reset_auto_ids() if not filename.endswith(('.h5', '.hdf5')): From dea66bb5f6448e8ecb6ea56f25496a0750b2373c Mon Sep 17 00:00:00 2001 From: Sterling Harper Date: Sun, 28 Jun 2015 14:05:18 -0600 Subject: [PATCH 2/2] Removed unnecessary import h5py import logic #403 --- openmc/summary.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/openmc/summary.py b/openmc/summary.py index f72562081..bb09e6969 100644 --- a/openmc/summary.py +++ b/openmc/summary.py @@ -3,20 +3,14 @@ import numpy as np import openmc -_h5_imported = False - - class Summary(object): def __init__(self, filename): - if not _h5_imported: - try: - import h5py - _h5_imported = True - except ImportError: - msg = 'Unable to import h5py which is needed by openmc.summary' - raise ImportError(msg) + # A user may not have h5py, but they can still use the rest of the + # Python API so we'll only try to import h5py if the user actually inits + # a Summary object. + import h5py openmc.reset_auto_ids()