Skip to content

Commit

Permalink
expose nc_rc_set, nc_rc_get (via rc_set, rc_get module functions).
Browse files Browse the repository at this point in the history
  • Loading branch information
jswhit committed Jul 6, 2024
1 parent 553cf18 commit e2638ff
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cibuildwheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions include/netCDF4.pxi
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src/netCDF4/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
43 changes: 42 additions & 1 deletion src/netCDF4/_netCDF4.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -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 (<char *>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():
Expand Down

0 comments on commit e2638ff

Please sign in to comment.