Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/cibuildwheel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ jobs:
- os: macos-14
arch: arm64
CIBW_ENVIRONMENT: MACOSX_DEPLOYMENT_TARGET=14.0
- os: macos-11
- os: macos-12
arch: x86_64
CIBW_ENVIRONMENT: MACOSX_DEPLOYMENT_TARGET=11.0
CIBW_ENVIRONMENT: MACOSX_DEPLOYMENT_TARGET=12.0

steps:
- uses: actions/checkout@v4
Expand Down
2 changes: 1 addition & 1 deletion Changelog
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
version 1.7.2 (tag v1.7.2rel)
version 1.7.2 (not yet released)
===============================
* add static type hints (PR #1302)

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
1 change: 1 addition & 0 deletions include/netcdf-compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ static inline int nc_get_alignment(int* thresholdp, int* alignmentp) {
#else
#define HAS_NCRCSET 0
static inline int nc_rc_set(const char* key, const char* value) { return NC_EINVAL; }
static inline const char *nc_rc_get(const char* key) { return NC_EINVAL; }
#endif

#if NC_VERSION_GE(4, 4, 0)
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,13 +10,13 @@
__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_parallel_support__, __has_ncfilter__)
__has_set_alignment__, __has_parallel_support__, __has_ncfilter__, __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'
'set_alignment', 'get_alignment', 'nc_get', 'nc_set',
]
__pdoc__ = {'utils': False}
# if HDF5_PLUGIN_PATH not set, point to package path if plugins live there
Expand Down
5 changes: 4 additions & 1 deletion src/netCDF4/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ __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'
'set_alignment', 'get_alignment', 'nc_get', 'nc_set',
]
__pdoc__ = {'utils': False}

Expand Down Expand Up @@ -87,6 +87,7 @@ __has_blosc_support__: BoolInt
__has_szip_support__: BoolInt
__has_set_alignment__: BoolInt
__has_ncfilter__: BoolInt
__has_nc_rc_set__: BoolInt
is_native_little: bool
is_native_big: bool
default_encoding: Final = 'utf-8'
Expand Down Expand Up @@ -624,6 +625,8 @@ def chartostring(
) -> npt.NDArray[np.str_] | npt.NDArray[np.bytes_]: ...

def getlibversion() -> str: ...
def nc_get(key: str) -> str: ...
Comment thread
jswhit marked this conversation as resolved.
Outdated
def nc_set(key: str, val: str): ...
Comment thread
jswhit marked this conversation as resolved.
Outdated

def set_alignment(threshold: int, alignment: int): ...
def get_alignment() -> tuple[int, int]: ...
Expand Down
47 changes: 44 additions & 3 deletions 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 netcdf-c 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 netcdf-c 4.9.0+ to be used at compile time"
)



# check for required version of netcdf-4 and hdf5.
def _gethdf5libversion():
Expand Down Expand Up @@ -1394,7 +1435,7 @@ def get_alignment():

if not __has_set_alignment__:
raise RuntimeError(
"This function requires netcdf4 4.9.0+ to be used at compile time"
"This function requires netcdf-c 4.9.0+ to be used at compile time"
)

cdef int ierr
Expand All @@ -1417,7 +1458,7 @@ def set_alignment(threshold, alignment):

if not __has_set_alignment__:
raise RuntimeError(
"This function requires netcdf4 4.9.0+ to be used at compile time"
"This function requires netcdf-c 4.9.0+ to be used at compile time"
)

cdef int ierr
Expand Down
19 changes: 19 additions & 0 deletions test/test_ncrc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import unittest
import netCDF4
from netCDF4 import __has_nc_rc_set__

class NCRCTestCase(unittest.TestCase):
def setUp(self):
pass

def tearDown(self):
pass

def runTest(self):
"""test rc_get, rc_set functions"""
if __has_nc_rc_set__:
netCDF4.rc_set('foo','bar')
assert netCDF4.rc_get('foo') == 'bar'

if __name__ == '__main__':
unittest.main()