From 6a255faacb6ce200198699744c8ec7bf2d79374a Mon Sep 17 00:00:00 2001 From: Michael Davidsaver Date: Thu, 15 Aug 2024 19:09:59 -0700 Subject: [PATCH] numpy compat fixups --- .github/workflows/build.yml | 4 ++-- setup.py | 2 +- src/p4p.h | 6 ++---- src/pvxs_value.cpp | 4 ++-- 4 files changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index e268224..78cda5d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -94,8 +94,8 @@ jobs: os: ubuntu-latest pyver: cp39-cp39 piparch: manylinux2010_x86_64 - numpy: numpy==2.0.1 - cython: Cython==3.0.10 + numpy: numpy==1.19.3 + cython: Cython==0.29.23 - name: linux 3.10 amd64 os: ubuntu-latest diff --git a/setup.py b/setup.py index 167aeaa..869029e 100755 --- a/setup.py +++ b/setup.py @@ -100,7 +100,7 @@ def get_numpy_include_dirs(): 'ply', # for asLib ] -if numpy.lib.NumpyVersion(numpy.__version__) >= '2.0.0b1': +if hasattr(numpy.lib, "NumpyVersion") and numpy.lib.NumpyVersion(numpy.__version__) >= '2.0.0b1': install_requires += ['numpy >= 1.7', 'numpy < 3'] else: # assume ABI forward compatibility as indicated by diff --git a/src/p4p.h b/src/p4p.h index 330f1d4..e7cbd9a 100644 --- a/src/p4p.h +++ b/src/p4p.h @@ -41,10 +41,8 @@ #endif // avoid numpy deprecation warnings when building with cython >= 3.0 -#if CYTHON_HEX_VERSION>=0x03000000 -# define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION -# define NPY_TARGET_VERSION NPY_1_7_API_VERSION -#endif +#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION +#define NPY_TARGET_VERSION NPY_1_7_API_VERSION namespace p4p { diff --git a/src/pvxs_value.cpp b/src/pvxs_value.cpp index 4ab07a8..834ecc7 100644 --- a/src/pvxs_value.cpp +++ b/src/pvxs_value.cpp @@ -159,7 +159,7 @@ PyObject* asPy(const Value& v, bool unpackstruct, bool unpackrecurse, PyObject* PyRef pyarr(PyArray_New(&PyArray_Type, 1, &shape, ntype, nullptr, const_cast(varr.data()), // should not actually be modifiable - esize, NPY_CARRAY_RO, nullptr)); + esize, NPY_ARRAY_CARRAY_RO, nullptr)); #ifdef PyArray_SetBaseObject PyArray_SetBaseObject((PyArrayObject*)pyarr.obj, holder.release()); @@ -530,7 +530,7 @@ void storePy(Value& v, PyObject* py, bool forceCast) } PyRef arr(PyArray_FromAny(py, PyArray_DescrFromType(ntype), 0, 0, - NPY_CARRAY_RO|NPY_ARRAY_FORCECAST, nullptr)); + NPY_ARRAY_CARRAY_RO|NPY_ARRAY_FORCECAST, nullptr)); if(PyArray_NDIM((PyArrayObject*)arr.obj)!=1) throw std::logic_error("Only 1-d array can be assigned");