From 1547c0d0226de8bd779d3574b9b970c740450b70 Mon Sep 17 00:00:00 2001 From: Baudouin Raoult Date: Wed, 11 Mar 2020 08:10:52 +0000 Subject: [PATCH] Add support for pyeccodes (experimental) --- cfgrib/__init__.py | 2 +- cfgrib/messages.py | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/cfgrib/__init__.py b/cfgrib/__init__.py index c769b436..23ab2d3d 100644 --- a/cfgrib/__init__.py +++ b/cfgrib/__init__.py @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -__version__ = '0.9.7.7.dev0' +__version__ = '0.9.8.0.dev0' # cfgrib core API depends on the ECMWF ecCodes C-library only from .cfmessage import CfMessage diff --git a/cfgrib/messages.py b/cfgrib/messages.py index 5a4abf62..aab9c28d 100644 --- a/cfgrib/messages.py +++ b/cfgrib/messages.py @@ -29,11 +29,14 @@ import attr import numpy as np -# select between using the external ecCodes bindings or the internal implementation -if os.environ.get('CFGRIB_USE_EXTERNAL_ECCODES_BINDINGS'): - import eccodes -else: - from . import bindings as eccodes +try: + # select between using the external ecCodes bindings or the internal implementation + if int(os.environ.get('CFGRIB_USE_EXTERNAL_ECCODES_BINDINGS', '0')): + import eccodes + else: + from . import bindings as eccodes +except RuntimeError: + import pyeccodes.compat as eccodes eccodes_version = eccodes.codes_get_api_version()