Skip to content

Commit

Permalink
ECC-1630: Get API version as an integer
Browse files Browse the repository at this point in the history
  • Loading branch information
shahramn committed Jul 7, 2023
1 parent f9e519f commit 0eaf46c
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ Changelog for eccodes-python
1.6.0 (2023-07-dd)
--------------------

- ECC-1630: Get API version as an integer
- ECC-1601: GRIB: Support data values array decoded in single-precision
- ECC-1611: Add function to determine if a BUFR key is a coordinate descriptor

Expand Down
16 changes: 10 additions & 6 deletions gribapi/gribapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2283,11 +2283,12 @@ def grib_gts_header(flag):
lib.grib_gts_header_off(context)


def grib_get_api_version():
def grib_get_api_version(vformat=str):
"""
@brief Get the API version.
Returns the version of the API as a string in the format "major.minor.revision".
Returns the version of the API as a string in the format "major.minor.revision"
or as an integer (10000*major + 100*minor + revision)
"""

def div(v, d):
Expand All @@ -2297,11 +2298,14 @@ def div(v, d):
raise RuntimeError("Could not load the ecCodes library!")

v = lib.grib_get_api_version()
v, revision = div(v, 100)
v, minor = div(v, 100)
major = v

return "%d.%d.%d" % (major, minor, revision)
if vformat is str:
v, revision = div(v, 100)
v, minor = div(v, 100)
major = v
return "%d.%d.%d" % (major, minor, revision)
else:
return v


__version__ = grib_get_api_version()
Expand Down
11 changes: 11 additions & 0 deletions tests/test_eccodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,17 @@ def test_codes_set_samples_path():
eccodes.codes_set_samples_path(eccodes.codes_samples_path())


def test_api_version():
vs = eccodes.codes_get_api_version()
assert type(vs) == str
assert len(vs) > 0
assert vs == eccodes.codes_get_api_version(str)
vi = eccodes.codes_get_api_version(int)
assert type(vi) == int
assert vi > 20000
print(vi)


def test_version_info():
vinfo = eccodes.codes_get_version_info()
assert len(vinfo) == 2
Expand Down

0 comments on commit 0eaf46c

Please sign in to comment.