From e2638fffeda67a4a7ec5a2057a180256342f600f Mon Sep 17 00:00:00 2001 From: jswhit Date: Sat, 6 Jul 2024 11:57:13 -0600 Subject: [PATCH] expose nc_rc_set, nc_rc_get (via rc_set, rc_get module functions). --- .github/workflows/cibuildwheel.yml | 2 +- include/netCDF4.pxi | 1 + src/netCDF4/__init__.py | 4 +-- src/netCDF4/_netCDF4.pyx | 43 +++++++++++++++++++++++++++++- 4 files changed, 46 insertions(+), 4 deletions(-) diff --git a/.github/workflows/cibuildwheel.yml b/.github/workflows/cibuildwheel.yml index e7d515be7..da4c1365c 100644 --- a/.github/workflows/cibuildwheel.yml +++ b/.github/workflows/cibuildwheel.yml @@ -60,7 +60,7 @@ jobs: - os: macos-14 arch: arm64 CIBW_ENVIRONMENT: MACOSX_DEPLOYMENT_TARGET=14.0 - - os: macos-11 + - os: macos-13 arch: x86_64 CIBW_ENVIRONMENT: MACOSX_DEPLOYMENT_TARGET=11.0 diff --git a/include/netCDF4.pxi b/include/netCDF4.pxi index 9404171db..f748bf82c 100644 --- a/include/netCDF4.pxi +++ b/include/netCDF4.pxi @@ -392,6 +392,7 @@ cdef extern from "netcdf-compat.h": int nc_set_alignment(int threshold, int alignment) int nc_get_alignment(int *threshold, int *alignment) int nc_rc_set(char* key, char* value) nogil + const_char_ptr *nc_rc_get(char* key) int nc_open_mem(const char *path, int mode, size_t size, void* memory, int *ncidp) nogil int nc_create_mem(const char *path, int mode, size_t initialize, int *ncidp) nogil diff --git a/src/netCDF4/__init__.py b/src/netCDF4/__init__.py index ac93047a2..e63ad3fc6 100644 --- a/src/netCDF4/__init__.py +++ b/src/netCDF4/__init__.py @@ -10,10 +10,10 @@ __has_parallel4_support__, __has_pnetcdf_support__, __has_quantization_support__, __has_zstandard_support__, __has_bzip2_support__, __has_blosc_support__, __has_szip_support__, - __has_set_alignment__) + __has_set_alignment__, __has_nc_rc_set__) import os __all__ =\ -['Dataset','Variable','Dimension','Group','MFDataset','MFTime','CompoundType','VLType','date2num','num2date','date2index','stringtochar','chartostring','stringtoarr','getlibversion','EnumType','get_chunk_cache','set_chunk_cache','set_alignment','get_alignment'] +['Dataset','Variable','Dimension','Group','MFDataset','MFTime','CompoundType','VLType','date2num','num2date','date2index','stringtochar','chartostring','stringtoarr','getlibversion','EnumType','get_chunk_cache','set_chunk_cache','set_alignment','get_alignment','nc_get','nc_set'] __pdoc__ = { 'utils': False, } diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index 49f62ee5c..269ea733e 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -1308,15 +1308,56 @@ __has_blosc_support__ = HAS_BLOSC_SUPPORT __has_szip_support__ = HAS_SZIP_SUPPORT __has_set_alignment__ = HAS_SET_ALIGNMENT __has_ncfilter__ = HAS_NCFILTER +__has_nc_rc_set__ = HAS_NCRCSET # set path to SSL certificates (issue #1246) # available starting in version 4.9.1 -if HAS_NCRCSET: +if __has_nc_rc_set__: import certifi if nc_rc_set("HTTP.SSL.CAINFO", _strencode(certifi.where())) != 0: raise RuntimeError('error setting path to SSL certificates') +def rc_get(key): + """ +**`rc_key(key)`** + +Returns the internal netcdf-c rc table value corresponding to key. + """ + cdef int ierr + cdef char *keyc + if __has_nc_rc_set__: + bytestr = _strencode(_tostr(key)) + keyc = bytestr + return (nc_rc_get(keyc)).decode('utf-8') + else: + raise RuntimeError( + "This function requires netcdf4 4.9.0+ to be used at compile time" + ) + +def rc_set(key, value): + """ +**`rc_set(key, value)`** + +Sets the internal netcdf-c rc table value corresponding to key. + """ + cdef int ierr + cdef char *keyc + cdef char *valuec + if __has_nc_rc_set__: + key_bytestr = _strencode(_tostr(key)) + keyc = key_bytestr + val_bytestr = _strencode(_tostr(value)) + valuec = val_bytestr + with nogil: + ierr = nc_rc_set(keyc,valuec) + _ensure_nc_success(ierr) + else: + raise RuntimeError( + "This function requires netcdf4 4.9.0+ to be used at compile time" + ) + + # check for required version of netcdf-4 and hdf5. def _gethdf5libversion():