Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Soft deps in setup #123

Merged
merged 9 commits into from
Jun 15, 2018
1 change: 1 addition & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ branch = True
omit =
setup.py
iris_grib/tests/*
.eggs/*


[report]
Expand Down
40 changes: 40 additions & 0 deletions iris_grib/_iris_mercator_support.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# (C) British Crown Copyright 2018, Met Office
#
# This file is part of iris-grib.
#
# iris-grib is free software: you can redistribute it and/or modify it under
# the terms of the GNU Lesser General Public License as published by the
# Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# iris-grib is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with iris-grib. If not, see <http://www.gnu.org/licenses/>.
"""
Temporary module to check for the extended Mercator class in Iris,
which iris-grib requires for its Mercator support.

"""
from __future__ import (absolute_import, division, print_function)
from six.moves import (filter, input, map, range, zip) # noqa
import six

import distutils.version

import iris


def confirm_extended_mercator_supported():
# Check that Iris version is at least 2.1, required for 'standard_parallel'
# support in the Mercator coord-system.
# This is a temporary fix allowing us to state Iris>=2.0 as a dependency,
# required for this release because Iris 2.1 is not yet available.
iris_version = distutils.version.LooseVersion(iris.__version__)
min_mercator_version = '2.1.0'
if iris_version < min_mercator_version:
msg = 'Support for Mercator projections requires Iris version >= {}'
raise ValueError(msg.format(min_mercator_version))
4 changes: 4 additions & 0 deletions iris_grib/_load_convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
ReferenceTarget
from iris.util import _is_circular

from ._iris_mercator_support import confirm_extended_mercator_supported
from ._grib1_load_rules import grib1_convert
from .message import GribMessage

Expand Down Expand Up @@ -746,6 +747,9 @@ def grid_definition_template_10(section, metadata):
# intersects the Earth
standard_parallel = section['LaD'] * _GRID_ACCURACY_IN_DEGREES

# Check and raise a more intelligible error, if the Iris version is too old
# to support the Mercator 'standard_parallel' keyword.
confirm_extended_mercator_supported()
cs = icoord_systems.Mercator(standard_parallel=standard_parallel,
ellipsoid=geog_cs)

Expand Down
4 changes: 4 additions & 0 deletions iris_grib/_save_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
TransverseMercator, LambertConformal)
import iris.exceptions

from ._iris_mercator_support import confirm_extended_mercator_supported
from . import grib_phenom_translation as gptx
from ._load_convert import (_STATISTIC_TYPE_NAMES, _TIME_RANGE_UNITS)
from iris.util import is_regular, regular_step
Expand Down Expand Up @@ -503,6 +504,9 @@ def grid_definition_template_10(cube, grib):
gribapi.grib_set(grib, "longitudeOfLastGridPoint",
int(np.round(last_x / _DEFAULT_DEGREES_UNITS)))

# Check and raise a more intelligible error, if the Iris version is too old
# to support the Mercator 'standard_parallel' property.
confirm_extended_mercator_supported()
# Encode the latitude at which the projection intersects the Earth.
gribapi.grib_set(grib, 'LaD',
cs.standard_parallel / _DEFAULT_DEGREES_UNITS)
Expand Down
10 changes: 6 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,12 @@ def file_walk_relative(top, remove=''):
'Programming Language :: Python :: 3.4',
'Programming Language :: Python :: 3.5',
],
install_requires = [
# 'iris>=1.9,<2',
# Also: the ECMWF GRIB API
],
# NOTE: This Iris version requirement is a purely temporary measure :
# Iris>=2.1 is needed for Mercator support, but this is not yet available,
# so 'iris_grib._confirm_iris_mercator_support' performs a runtime version
# check instead + raises an error if required.
# TODO: update Iris version and remove runtime checking, in future release.
install_requires = ['scitools-iris>=2.0.*', 'eccodes'],
extras_require = {
'test:python_version=="2.7"': ['mock'],
},
Expand Down