File tree Expand file tree Collapse file tree 5 files changed +25
-0
lines changed
Expand file tree Collapse file tree 5 files changed +25
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,7 @@ Changelog for eccodes-python
552.43.0 (2025-mm-dd)
66--------------------
77
8+ - ECC-2108: Implement a way of switching off error output to 'stderr'
89- GitHub pull request #129: Update MemoryReader to read more than one field
910
1011
Original file line number Diff line number Diff line change 6161)
6262from gribapi import grib_clone as codes_clone
6363from gribapi import grib_context_delete as codes_context_delete
64+ from gribapi import grib_context_set_logging as codes_context_set_logging
6465from gribapi import grib_copy_namespace as codes_copy_namespace
6566from gribapi import grib_count_in_file as codes_count_in_file
6667from gribapi import grib_find_nearest as codes_grib_find_nearest
371372 "codes_skip_read_only" ,
372373 "codes_write" ,
373374 "codes_context_delete" ,
375+ "codes_context_set_logging" ,
374376 "CodesInternalError" ,
375377 "ConceptNoMatchError" ,
376378 "ConstantFieldError" ,
Original file line number Diff line number Diff line change @@ -139,6 +139,7 @@ void grib_multi_support_on(grib_context* c);
139139void grib_multi_support_off (grib_context * c );
140140void grib_multi_support_reset_file (grib_context * c , FILE * f );
141141long grib_get_api_version (void );
142+ void grib_context_set_logging_file (grib_context * c , FILE * f );
142143
143144char * grib_samples_path (const grib_context * c );
144145char * grib_definition_path (const grib_context * c );
Original file line number Diff line number Diff line change @@ -464,6 +464,12 @@ def grib_multi_support_reset_file(fileobj):
464464 lib .grib_multi_support_reset_file (context , fileobj )
465465
466466
467+ @require (fileobj = file )
468+ def grib_context_set_logging (fileobj ):
469+ context = lib .grib_context_get_default ()
470+ lib .grib_context_set_logging_file (context , fileobj )
471+
472+
467473@require (msgid = int )
468474def grib_release (msgid ):
469475 """
Original file line number Diff line number Diff line change 1515
1616import math
1717import os .path
18+ import sys
1819
1920import numpy as np
2021import pytest
@@ -115,6 +116,20 @@ def test_codes_get_native_type():
115116 eccodes .codes_get_native_type (0 , "aKey" ) # NULL handle
116117
117118
119+ def test_set_logging_file ():
120+ if eccodes .codes_get_api_version (int ) < 24300 :
121+ pytest .skip ("ecCodes version too old" )
122+
123+ nullDeviceFile = "/dev/null"
124+ with open (nullDeviceFile , "w" ) as fnull :
125+ eccodes .codes_context_set_logging (fnull )
126+ with pytest .raises (eccodes .FileNotFoundError ):
127+ eccodes .codes_grib_new_from_samples ("Silenced" )
128+ eccodes .codes_context_set_logging (sys .stderr )
129+ with pytest .raises (eccodes .FileNotFoundError ):
130+ eccodes .codes_grib_new_from_samples ("Restored" )
131+
132+
118133def test_new_from_file ():
119134 fpath = get_sample_fullpath ("GRIB2.tmpl" )
120135 if fpath is None :
You can’t perform that action at this time.
0 commit comments