Skip to content

Commit 0eaf46c

Browse files
committed
ECC-1630: Get API version as an integer
1 parent f9e519f commit 0eaf46c

File tree

3 files changed

+22
-6
lines changed

3 files changed

+22
-6
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ Changelog for eccodes-python
1010
1.6.0 (2023-07-dd)
1111
--------------------
1212

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

gribapi/gribapi.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2283,11 +2283,12 @@ def grib_gts_header(flag):
22832283
lib.grib_gts_header_off(context)
22842284

22852285

2286-
def grib_get_api_version():
2286+
def grib_get_api_version(vformat=str):
22872287
"""
22882288
@brief Get the API version.
22892289
2290-
Returns the version of the API as a string in the format "major.minor.revision".
2290+
Returns the version of the API as a string in the format "major.minor.revision"
2291+
or as an integer (10000*major + 100*minor + revision)
22912292
"""
22922293

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

22992300
v = lib.grib_get_api_version()
2300-
v, revision = div(v, 100)
2301-
v, minor = div(v, 100)
2302-
major = v
23032301

2304-
return "%d.%d.%d" % (major, minor, revision)
2302+
if vformat is str:
2303+
v, revision = div(v, 100)
2304+
v, minor = div(v, 100)
2305+
major = v
2306+
return "%d.%d.%d" % (major, minor, revision)
2307+
else:
2308+
return v
23052309

23062310

23072311
__version__ = grib_get_api_version()

tests/test_eccodes.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,17 @@ def test_codes_set_samples_path():
5656
eccodes.codes_set_samples_path(eccodes.codes_samples_path())
5757

5858

59+
def test_api_version():
60+
vs = eccodes.codes_get_api_version()
61+
assert type(vs) == str
62+
assert len(vs) > 0
63+
assert vs == eccodes.codes_get_api_version(str)
64+
vi = eccodes.codes_get_api_version(int)
65+
assert type(vi) == int
66+
assert vi > 20000
67+
print(vi)
68+
69+
5970
def test_version_info():
6071
vinfo = eccodes.codes_get_version_info()
6172
assert len(vinfo) == 2

0 commit comments

Comments
 (0)