File tree Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Expand file tree Collapse file tree 3 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -10,6 +10,7 @@ Changelog for eccodes-python
10
10
1.6.0 (2023-07-dd)
11
11
--------------------
12
12
13
+ - ECC-1630: Get API version as an integer
13
14
- ECC-1601: GRIB: Support data values array decoded in single-precision
14
15
- ECC-1611: Add function to determine if a BUFR key is a coordinate descriptor
15
16
Original file line number Diff line number Diff line change @@ -2283,11 +2283,12 @@ def grib_gts_header(flag):
2283
2283
lib .grib_gts_header_off (context )
2284
2284
2285
2285
2286
- def grib_get_api_version ():
2286
+ def grib_get_api_version (vformat = str ):
2287
2287
"""
2288
2288
@brief Get the API version.
2289
2289
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)
2291
2292
"""
2292
2293
2293
2294
def div (v , d ):
@@ -2297,11 +2298,14 @@ def div(v, d):
2297
2298
raise RuntimeError ("Could not load the ecCodes library!" )
2298
2299
2299
2300
v = lib .grib_get_api_version ()
2300
- v , revision = div (v , 100 )
2301
- v , minor = div (v , 100 )
2302
- major = v
2303
2301
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
2305
2309
2306
2310
2307
2311
__version__ = grib_get_api_version ()
Original file line number Diff line number Diff line change @@ -56,6 +56,17 @@ def test_codes_set_samples_path():
56
56
eccodes .codes_set_samples_path (eccodes .codes_samples_path ())
57
57
58
58
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
+
59
70
def test_version_info ():
60
71
vinfo = eccodes .codes_get_version_info ()
61
72
assert len (vinfo ) == 2
You can’t perform that action at this time.
0 commit comments