Skip to content

Commit

Permalink
BUG: Fix NumPy and Cython deprecation and initialization warnings
Browse files Browse the repository at this point in the history
Fix NumPy and Cython deprecation and initialization warnings.

Fixes:
```
dipy/core/interpolation.c:45594:3: warning: 'tp_print' is deprecated
[-Wdeprecated-declarations]
   0, /*tp_print*/
   ^
/Users/runner/hostedtoolcache/Python/3.8.3/x64/include/python3.8/cpython/object.h:260:5:
note: 'tp_print' has been explicitly marked deprecated here
    Py_DEPRECATED(3.8) int (*tp_print)(PyObject *, FILE *, int);
    ^
/Users/runner/hostedtoolcache/Python/3.8.3/x64/include/python3.8/pyport.h:515:54:
note: expanded from macro 'Py_DEPRECATED'
```

and
```
/Users/runner/work/1/s/venv/lib/python3.8/site-packages/numpy/core/include/numpy/npy_1_7_deprecated_api.h:17:2:
warning: "Using deprecated NumPy API, disable it with "          "#define
NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION" [-W#warnings]
 ^
```

raised for example in:
https://dev.azure.com/dipy/46625eaf-7255-4a2c-9e92-befcdbdca2a8/_apis/build/builds/492/logs/85

The `tp_print` deprecation warning only when using Python 3.8 on macOS. Related
Cython references:
cython/cython#3201
cython/cython#3474
  • Loading branch information
jhlegarreta committed Jul 23, 2020
1 parent d395d87 commit de359f5
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@
from os.path import join as pjoin, dirname, exists
from glob import glob


def is_platform_mac():
return sys.platform == "darwin"


def is_platform_windows():
return sys.platform == "win32" or sys.platform == "cygwin"

# BEFORE importing distutils, remove MANIFEST. distutils doesn't properly
# update it when the contents of directories change.
if exists('MANIFEST'):
Expand All @@ -30,6 +38,7 @@
# removing MANIFEST
from distutils.core import setup
from distutils.extension import Extension
from distutils.version import LooseVersion

from cythexts import cyproc_exts, get_pyx_sdist
from setup_helpers import (install_scripts_bat, add_flag_checking,
Expand Down Expand Up @@ -61,6 +70,28 @@
# Define extensions
EXTS = []

if is_platform_windows():
extra_compile_args = []
else:
extra_compile_args = ["-Werror"]

# In numpy>=1.16.0, silence build warnings about deprecated API usage. We
# cannot do anything about these warnings because they stem from Cython+NumPy
# version mismatches.
macros = [("NPY_NO_DEPRECATED_API", "0")]
if "-Werror" in extra_compile_args:
try:
import numpy as np
except ImportError:
pass
else:
if np.__version__ < LooseVersion("1.16.0"):
extra_compile_args.remove("-Werror")

# Silence Cython `tp_print` deprecation warnings
if sys.version_info[:2] == (3, 8):
extra_compile_args.append("-Wno-error=missing-field-initializers")

# We use some defs from npymath, but we don't want to link against npymath lib
ext_kwargs = {'include_dirs': ['src']} # We add np.get_include() later

Expand Down Expand Up @@ -105,6 +136,8 @@
pyx_src = pjoin(*modulename.split('.')) + '.pyx'
EXTS.append(Extension(modulename, [pyx_src] + other_sources,
language=language,
extra_compile_args=extra_compile_args,
macros=macros,
**deepcopy(ext_kwargs))) # deepcopy lists

# Do our own build and install time dependency checking. setup.py gets called
Expand Down

0 comments on commit de359f5

Please sign in to comment.