Skip to content

Commit 84e3dd5

Browse files
author
Jeff Whitaker
authored
Merge pull request Unidata#1348 from Unidata/nc_rc_set
expose nc_rc_set, nc_rc_get (via rc_set, rc_get module functions).
2 parents 82b11bf + 180584a commit 84e3dd5

10 files changed

Lines changed: 162 additions & 71 deletions

File tree

‎.github/workflows/cibuildwheel.yml‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ jobs:
6060
- os: macos-14
6161
arch: arm64
6262
CIBW_ENVIRONMENT: MACOSX_DEPLOYMENT_TARGET=14.0
63-
- os: macos-11
63+
- os: macos-12
6464
arch: x86_64
65-
CIBW_ENVIRONMENT: MACOSX_DEPLOYMENT_TARGET=11.0
65+
CIBW_ENVIRONMENT: MACOSX_DEPLOYMENT_TARGET=12.0
6666

6767
steps:
6868
- uses: actions/checkout@v4

‎Changelog‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
version 1.7.2 (tag v1.7.2rel)
1+
version 1.7.2 (not yet released)
22
===============================
33
* add static type hints (PR #1302)
4+
* Expose nc_rc_set, nc_rc_get (via rc_set, rc_get module functions). (PR #1348)
45

56
version 1.7.1 (tag v1.7.1rel)
67
===============================

‎docs/index.html‎

Lines changed: 72 additions & 54 deletions
Large diffs are not rendered by default.

‎include/netCDF4.pxi‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,7 @@ cdef extern from "netcdf-compat.h":
392392
int nc_set_alignment(int threshold, int alignment)
393393
int nc_get_alignment(int *threshold, int *alignment)
394394
int nc_rc_set(char* key, char* value) nogil
395+
const_char_ptr *nc_rc_get(char* key)
395396

396397
int nc_open_mem(const char *path, int mode, size_t size, void* memory, int *ncidp) nogil
397398
int nc_create_mem(const char *path, int mode, size_t initialize, int *ncidp) nogil

‎include/netcdf-compat.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ static inline int nc_get_alignment(int* thresholdp, int* alignmentp) {
6060
#else
6161
#define HAS_NCRCSET 0
6262
static inline int nc_rc_set(const char* key, const char* value) { return NC_EINVAL; }
63+
static inline const char *nc_rc_get(const char* key) { return NC_EINVAL; }
6364
#endif
6465

6566
#if NC_VERSION_GE(4, 4, 0)

‎src/netCDF4/__init__.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@
1010
__has_parallel4_support__, __has_pnetcdf_support__,
1111
__has_quantization_support__, __has_zstandard_support__,
1212
__has_bzip2_support__, __has_blosc_support__, __has_szip_support__,
13-
__has_set_alignment__, __has_parallel_support__, __has_ncfilter__)
13+
__has_set_alignment__, __has_parallel_support__, __has_ncfilter__, __has_nc_rc_set__)
1414
import os
1515
__all__ = [
1616
'Dataset', 'Variable', 'Dimension', 'Group', 'MFDataset', 'MFTime', 'CompoundType',
1717
'VLType', 'date2num', 'num2date', 'date2index', 'stringtochar', 'chartostring',
1818
'stringtoarr', 'getlibversion', 'EnumType', 'get_chunk_cache', 'set_chunk_cache',
19-
'set_alignment', 'get_alignment'
19+
'set_alignment', 'get_alignment', 'rc_get', 'rc_set',
2020
]
2121
__pdoc__ = {'utils': False}
2222
# if HDF5_PLUGIN_PATH not set, point to package path if plugins live there

‎src/netCDF4/__init__.pyi‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ __all__ = [
1414
'Dataset', 'Variable', 'Dimension', 'Group', 'MFDataset', 'MFTime', 'CompoundType',
1515
'VLType', 'date2num', 'num2date', 'date2index', 'stringtochar', 'chartostring',
1616
'stringtoarr', 'getlibversion', 'EnumType', 'get_chunk_cache', 'set_chunk_cache',
17-
'set_alignment', 'get_alignment'
17+
'set_alignment', 'get_alignment', 'rc_get', 'rc_set',
1818
]
1919
__pdoc__ = {'utils': False}
2020

@@ -87,6 +87,7 @@ __has_blosc_support__: BoolInt
8787
__has_szip_support__: BoolInt
8888
__has_set_alignment__: BoolInt
8989
__has_ncfilter__: BoolInt
90+
__has_nc_rc_set__: BoolInt
9091
is_native_little: bool
9192
is_native_big: bool
9293
default_encoding: Final = 'utf-8'
@@ -624,6 +625,8 @@ def chartostring(
624625
) -> npt.NDArray[np.str_] | npt.NDArray[np.bytes_]: ...
625626

626627
def getlibversion() -> str: ...
628+
def rc_get(key: str) -> str | None: ...
629+
def rc_set(key: str, value: str)-> None: ...
627630

628631
def set_alignment(threshold: int, alignment: int): ...
629632
def get_alignment() -> tuple[int, int]: ...

‎src/netCDF4/_netCDF4.pyi‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ from . import (
66
stringtoarr, getlibversion, EnumType, get_chunk_cache, set_chunk_cache,
77
set_alignment, get_alignment, default_fillvals, default_encoding,
88
NetCDF4MissingFeatureException, is_native_big, is_native_little, unicode_error,
9+
rc_get, rc_set,
910
__version__, __netcdf4libversion__, __hdf5libversion__, __has_rename_grp__,
1011
__has_nc_inq_path__, __has_nc_inq_format_extended__, __has_nc_open_mem__,
1112
__has_nc_create_mem__, __has_cdf5_format__, __has_parallel4_support__,
1213
__has_pnetcdf_support__, __has_parallel_support__,
1314
__has_quantization_support__, __has_zstandard_support__,
1415
__has_bzip2_support__, __has_blosc_support__, __has_szip_support__,
15-
__has_set_alignment__, __has_ncfilter__
16+
__has_set_alignment__, __has_ncfilter__, __has_nc_rc_set__,
1617
)
1718

1819

‎src/netCDF4/_netCDF4.pyx‎

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""Version 1.7.1
1+
"""Version 1.7.2
22
-------------
33
44
# Introduction
@@ -1272,7 +1272,7 @@ import sys
12721272
import functools
12731273
from typing import Union
12741274

1275-
__version__ = "1.7.1.post1"
1275+
__version__ = "1.7.2"
12761276

12771277
# Initialize numpy
12781278
import posixpath
@@ -1308,15 +1308,61 @@ __has_blosc_support__ = HAS_BLOSC_SUPPORT
13081308
__has_szip_support__ = HAS_SZIP_SUPPORT
13091309
__has_set_alignment__ = HAS_SET_ALIGNMENT
13101310
__has_ncfilter__ = HAS_NCFILTER
1311+
__has_nc_rc_set__ = HAS_NCRCSET
13111312

13121313

13131314
# set path to SSL certificates (issue #1246)
13141315
# available starting in version 4.9.1
1315-
if HAS_NCRCSET:
1316+
if __has_nc_rc_set__:
13161317
import certifi
13171318
if nc_rc_set("HTTP.SSL.CAINFO", _strencode(certifi.where())) != 0:
13181319
raise RuntimeError('error setting path to SSL certificates')
13191320

1321+
def rc_get(key):
1322+
"""
1323+
**```rc_get(key)```**
1324+
1325+
Returns the internal netcdf-c rc table value corresponding to key.
1326+
"""
1327+
cdef int ierr
1328+
cdef char *keyc
1329+
cdef char *valc
1330+
if __has_nc_rc_set__:
1331+
bytestr = _strencode(_tostr(key))
1332+
keyc = bytestr
1333+
valc = <char *>nc_rc_get(keyc)
1334+
if valc is NULL:
1335+
return None
1336+
else:
1337+
return valc.decode('utf-8')
1338+
else:
1339+
raise RuntimeError(
1340+
"This function requires netcdf-c 4.9.0+ to be used at compile time"
1341+
)
1342+
1343+
def rc_set(key, value):
1344+
"""
1345+
**```rc_set(key, value)```**
1346+
1347+
Sets the internal netcdf-c rc table value corresponding to key.
1348+
"""
1349+
cdef int ierr
1350+
cdef char *keyc
1351+
cdef char *valuec
1352+
if __has_nc_rc_set__:
1353+
key_bytestr = _strencode(_tostr(key))
1354+
keyc = key_bytestr
1355+
val_bytestr = _strencode(_tostr(value))
1356+
valuec = val_bytestr
1357+
with nogil:
1358+
ierr = nc_rc_set(keyc,valuec)
1359+
_ensure_nc_success(ierr)
1360+
else:
1361+
raise RuntimeError(
1362+
"This function requires netcdf-c 4.9.0+ to be used at compile time"
1363+
)
1364+
1365+
13201366

13211367
# check for required version of netcdf-4 and hdf5.
13221368
def _gethdf5libversion():
@@ -1330,7 +1376,7 @@ def _gethdf5libversion():
13301376

13311377
def getlibversion():
13321378
"""
1333-
**`getlibversion()`**
1379+
**```getlibversion()```**
13341380
13351381
returns a string describing the version of the netcdf library
13361382
used to build the module, and when it was built.
@@ -1339,7 +1385,7 @@ used to build the module, and when it was built.
13391385

13401386
def get_chunk_cache():
13411387
"""
1342-
**`get_chunk_cache()`**
1388+
**```get_chunk_cache()```**
13431389
13441390
return current netCDF chunk cache information in a tuple (size,nelems,preemption).
13451391
See netcdf C library documentation for `nc_get_chunk_cache` for
@@ -1355,7 +1401,7 @@ details. Values can be reset with `set_chunk_cache`."""
13551401

13561402
def set_chunk_cache(size=None,nelems=None,preemption=None):
13571403
"""
1358-
**`set_chunk_cache(self,size=None,nelems=None,preemption=None)`**
1404+
**```set_chunk_cache(size=None,nelems=None,preemption=None)```**
13591405
13601406
change netCDF4 chunk cache settings.
13611407
See netcdf C library documentation for `nc_set_chunk_cache` for
@@ -1383,7 +1429,7 @@ details."""
13831429

13841430

13851431
def get_alignment():
1386-
"""**`get_alignment()`**
1432+
"""**```get_alignment()```**
13871433
13881434
return current netCDF alignment within HDF5 files in a tuple
13891435
(threshold,alignment). See netcdf C library documentation for
@@ -1394,7 +1440,7 @@ def get_alignment():
13941440

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

14001446
cdef int ierr
@@ -1407,7 +1453,7 @@ def get_alignment():
14071453

14081454

14091455
def set_alignment(threshold, alignment):
1410-
"""**`set_alignment(threshold,alignment)`**
1456+
"""**```set_alignment(threshold,alignment)```**
14111457
14121458
Change the HDF5 file alignment.
14131459
See netcdf C library documentation for `nc_set_alignment` for
@@ -1417,7 +1463,7 @@ def set_alignment(threshold, alignment):
14171463

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

14231469
cdef int ierr

‎test/test_ncrc.py‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import unittest
2+
import netCDF4
3+
from netCDF4 import __has_nc_rc_set__
4+
5+
class NCRCTestCase(unittest.TestCase):
6+
def setUp(self):
7+
pass
8+
9+
def tearDown(self):
10+
pass
11+
12+
def runTest(self):
13+
"""test rc_get, rc_set functions"""
14+
if __has_nc_rc_set__:
15+
netCDF4.rc_set('foo','bar')
16+
assert netCDF4.rc_get('foo') == 'bar'
17+
assert netCDF4.rc_get('bar') == None
18+
19+
if __name__ == '__main__':
20+
unittest.main()

0 commit comments

Comments
 (0)