diff --git a/.github/workflows/cibuildwheel.yml b/.github/workflows/cibuildwheel.yml index e7d515be7..b6415474f 100644 --- a/.github/workflows/cibuildwheel.yml +++ b/.github/workflows/cibuildwheel.yml @@ -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 diff --git a/Changelog b/Changelog index 1b1157406..f1e82e2b3 100644 --- a/Changelog +++ b/Changelog @@ -1,6 +1,7 @@ - version 1.7.2 (tag v1.7.2rel) + version 1.7.2 (not yet released) =============================== * add static type hints (PR #1302) + * Expose nc_rc_set, nc_rc_get (via rc_set, rc_get module functions). (PR #1348) version 1.7.1 (tag v1.7.1rel) =============================== diff --git a/docs/index.html b/docs/index.html index 6971ceb5b..730c955d7 100644 --- a/docs/index.html +++ b/docs/index.html @@ -2,19 +2,22 @@ - - + + netCDF4 API documentation - - - - - - + + + + + + - - + +
@@ -23,7 +26,7 @@

Package netCDF4

-

Version 1.7.0

+

Version 1.7.2

Introduction

netcdf4-python is a Python interface to the netCDF C library.

netCDF version 4 has many features @@ -118,8 +121,8 @@

Creating/Opening/Closing a netCDF If the file is open for write access (mode='w', 'r+' or 'a'), you may write any type of data including new dimensions, groups, variables and attributes. -netCDF files come in five flavors (NETCDF3_CLASSIC, -NETCDF3_64BIT_OFFSET, NETCDF3_64BIT_DATA, NETCDF4_CLASSIC<code>, and </code>NETCDF4). +netCDF files come in five flavors (NETCDF3_CLASSIC, +NETCDF3_64BIT_OFFSET, NETCDF3_64BIT_DATA, NETCDF4_CLASSIC, and NETCDF4). NETCDF3_CLASSIC was the original netcdf binary format, and was limited to file sizes less than 2 Gb. NETCDF3_64BIT_OFFSET was introduced in version 3.6.0 of the library, and extended the original binary format @@ -1261,7 +1264,7 @@

Functions

def get_alignment()
-

get_alignment()

+

get_alignment()

return current netCDF alignment within HDF5 files in a tuple (threshold,alignment). See netcdf C library documentation for nc_get_alignment for details. Values can be reset with @@ -1272,7 +1275,7 @@

Functions

def get_chunk_cache()
-

get_chunk_cache()

+

get_chunk_cache()

return current netCDF chunk cache information in a tuple (size,nelems,preemption). See netcdf C library documentation for nc_get_chunk_cache for details. Values can be reset with set_chunk_cache().

@@ -1281,7 +1284,7 @@

Functions

def getlibversion()
-

getlibversion()

+

getlibversion()

returns a string describing the version of the netcdf library used to build the module, and when it was built.

@@ -1340,11 +1343,25 @@

Functions

do not contain a time-zone offset, even if the specified units contains one.

+
+def rc_get(key) +
+
+

rc_get(key)

+

Returns the internal netcdf-c rc table value corresponding to key.

+
+
+def rc_set(key, value) +
+
+

rc_set(key, value)

+

Sets the internal netcdf-c rc table value corresponding to key.

+
def set_alignment(threshold, alignment)
-

set_alignment()(threshold,alignment)

+

set_alignment(threshold,alignment)

Change the HDF5 file alignment. See netcdf C library documentation for nc_set_alignment for details.

@@ -1354,7 +1371,7 @@

Functions

def set_chunk_cache(size=None, nelems=None, preemption=None)
-

set_chunk_cache(self,size=None,nelems=None,preemption=None)

+

set_chunk_cache(size=None,nelems=None,preemption=None)

change netCDF4 chunk cache settings. See netcdf C library documentation for nc_set_chunk_cache for details.

@@ -1415,12 +1432,12 @@

Classes

the user.

__init__(group, datatype, datatype_name)

CompoundType constructor.

-

group: Group instance to associate with the compound datatype.

-

datatype: A numpy dtype object describing a structured (a.k.a record) +

grp: Group instance to associate with the compound datatype.

+

dt: A numpy dtype object describing a structured (a.k.a record) array. Can be composed of homogeneous numeric or character data types, or other structured array data types.

-

datatype_name: a Python string containing a description of the +

dtype_name: a Python string containing a description of the compound data type.

Note 1: When creating nested compound data types, the inner compound data types must already be associated with CompoundType @@ -1433,15 +1450,15 @@

Instance variables

var dtype
-

Return an attribute of instance, which is of type owner.

+
var dtype_view
-

Return an attribute of instance, which is of type owner.

+
var name
-

Return an attribute of instance, which is of type owner.

+
@@ -1623,39 +1640,39 @@

Instance variables

var auto_complex
-

Return an attribute of instance, which is of type owner.

+
var cmptypes
-

Return an attribute of instance, which is of type owner.

+
var data_model
-

Return an attribute of instance, which is of type owner.

+
var dimensions
-

Return an attribute of instance, which is of type owner.

+
var disk_format
-

Return an attribute of instance, which is of type owner.

+
var enumtypes
-

Return an attribute of instance, which is of type owner.

+
var file_format
-

Return an attribute of instance, which is of type owner.

+
var groups
-

Return an attribute of instance, which is of type owner.

+
var keepweakref
-

Return an attribute of instance, which is of type owner.

+
var name
@@ -1663,19 +1680,19 @@

Instance variables

var parent
-

Return an attribute of instance, which is of type owner.

+
var path
-

Return an attribute of instance, which is of type owner.

+
var variables
-

Return an attribute of instance, which is of type owner.

+
var vltypes
-

Return an attribute of instance, which is of type owner.

+

Methods

@@ -2264,15 +2281,15 @@

Instance variables

var dtype
-

Return an attribute of instance, which is of type owner.

+
var enum_dict
-

Return an attribute of instance, which is of type owner.

+
var name
-

Return an attribute of instance, which is of type owner.

+
@@ -2476,11 +2493,11 @@

Instance variables

var dtype
-

Return an attribute of instance, which is of type owner.

+
var name
-

Return an attribute of instance, which is of type owner.

+
@@ -2668,15 +2685,15 @@

Instance variables

var always_mask
-

Return an attribute of instance, which is of type owner.

+
var auto_complex
-

Return an attribute of instance, which is of type owner.

+
var chartostring
-

Return an attribute of instance, which is of type owner.

+
var datatype
@@ -2691,11 +2708,11 @@

Instance variables

var dtype
-

Return an attribute of instance, which is of type owner.

+
var mask
-

Return an attribute of instance, which is of type owner.

+
var name
@@ -2703,11 +2720,11 @@

Instance variables

var ndim
-

Return an attribute of instance, which is of type owner.

+
var scale
-

Return an attribute of instance, which is of type owner.

+
var shape
@@ -3049,10 +3066,9 @@

Methods

- \ No newline at end of file + 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/include/netcdf-compat.h b/include/netcdf-compat.h index 89e7b20fe..d1144d979 100644 --- a/include/netcdf-compat.h +++ b/include/netcdf-compat.h @@ -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) diff --git a/src/netCDF4/__init__.py b/src/netCDF4/__init__.py index 25f6fad2e..e7e94d2cf 100644 --- a/src/netCDF4/__init__.py +++ b/src/netCDF4/__init__.py @@ -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', 'rc_get', 'rc_set', ] __pdoc__ = {'utils': False} # if HDF5_PLUGIN_PATH not set, point to package path if plugins live there diff --git a/src/netCDF4/__init__.pyi b/src/netCDF4/__init__.pyi index 413336f0e..1a709dd35 100644 --- a/src/netCDF4/__init__.pyi +++ b/src/netCDF4/__init__.pyi @@ -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', 'rc_get', 'rc_set', ] __pdoc__ = {'utils': False} @@ -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' @@ -624,6 +625,8 @@ def chartostring( ) -> npt.NDArray[np.str_] | npt.NDArray[np.bytes_]: ... def getlibversion() -> str: ... +def rc_get(key: str) -> str | None: ... +def rc_set(key: str, value: str)-> None: ... def set_alignment(threshold: int, alignment: int): ... def get_alignment() -> tuple[int, int]: ... diff --git a/src/netCDF4/_netCDF4.pyi b/src/netCDF4/_netCDF4.pyi index 536d4f63b..304e50e69 100644 --- a/src/netCDF4/_netCDF4.pyi +++ b/src/netCDF4/_netCDF4.pyi @@ -6,13 +6,14 @@ from . import ( stringtoarr, getlibversion, EnumType, get_chunk_cache, set_chunk_cache, set_alignment, get_alignment, default_fillvals, default_encoding, NetCDF4MissingFeatureException, is_native_big, is_native_little, unicode_error, + rc_get, rc_set, __version__, __netcdf4libversion__, __hdf5libversion__, __has_rename_grp__, __has_nc_inq_path__, __has_nc_inq_format_extended__, __has_nc_open_mem__, __has_nc_create_mem__, __has_cdf5_format__, __has_parallel4_support__, __has_pnetcdf_support__, __has_parallel_support__, __has_quantization_support__, __has_zstandard_support__, __has_bzip2_support__, __has_blosc_support__, __has_szip_support__, - __has_set_alignment__, __has_ncfilter__ + __has_set_alignment__, __has_ncfilter__, __has_nc_rc_set__, ) diff --git a/src/netCDF4/_netCDF4.pyx b/src/netCDF4/_netCDF4.pyx index 2d9a16628..b912cdfb6 100644 --- a/src/netCDF4/_netCDF4.pyx +++ b/src/netCDF4/_netCDF4.pyx @@ -1,4 +1,4 @@ -"""Version 1.7.1 +"""Version 1.7.2 ------------- # Introduction @@ -1272,7 +1272,7 @@ import sys import functools from typing import Union -__version__ = "1.7.1.post1" +__version__ = "1.7.2" # Initialize numpy import posixpath @@ -1308,15 +1308,61 @@ __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_get(key)```** + +Returns the internal netcdf-c rc table value corresponding to key. + """ + cdef int ierr + cdef char *keyc + cdef char *valc + if __has_nc_rc_set__: + bytestr = _strencode(_tostr(key)) + keyc = bytestr + valc = nc_rc_get(keyc) + if valc is NULL: + return None + else: + return valc.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(): @@ -1330,7 +1376,7 @@ def _gethdf5libversion(): def getlibversion(): """ -**`getlibversion()`** +**```getlibversion()```** returns a string describing the version of the netcdf library used to build the module, and when it was built. @@ -1339,7 +1385,7 @@ used to build the module, and when it was built. def get_chunk_cache(): """ -**`get_chunk_cache()`** +**```get_chunk_cache()```** return current netCDF chunk cache information in a tuple (size,nelems,preemption). See netcdf C library documentation for `nc_get_chunk_cache` for @@ -1355,7 +1401,7 @@ details. Values can be reset with `set_chunk_cache`.""" def set_chunk_cache(size=None,nelems=None,preemption=None): """ -**`set_chunk_cache(self,size=None,nelems=None,preemption=None)`** +**```set_chunk_cache(size=None,nelems=None,preemption=None)```** change netCDF4 chunk cache settings. See netcdf C library documentation for `nc_set_chunk_cache` for @@ -1383,7 +1429,7 @@ details.""" def get_alignment(): - """**`get_alignment()`** + """**```get_alignment()```** return current netCDF alignment within HDF5 files in a tuple (threshold,alignment). See netcdf C library documentation for @@ -1394,7 +1440,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 @@ -1407,7 +1453,7 @@ def get_alignment(): def set_alignment(threshold, alignment): - """**`set_alignment(threshold,alignment)`** + """**```set_alignment(threshold,alignment)```** Change the HDF5 file alignment. See netcdf C library documentation for `nc_set_alignment` for @@ -1417,7 +1463,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 diff --git a/test/test_ncrc.py b/test/test_ncrc.py new file mode 100644 index 000000000..02cd168c4 --- /dev/null +++ b/test/test_ncrc.py @@ -0,0 +1,20 @@ +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' + assert netCDF4.rc_get('bar') == None + +if __name__ == '__main__': + unittest.main()