Skip to content

Commit 68a3a6d

Browse files
committed
Add pyproject.toml and support Cython 3
1 parent de2212f commit 68a3a6d

File tree

8 files changed

+74
-48
lines changed

8 files changed

+74
-48
lines changed

.github/workflows/main.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ jobs:
88
runs-on: ${{ matrix.os }}
99
strategy:
1010
matrix:
11-
os: [ubuntu-latest, macOS-latest]
12-
python-version: ["3.7", "3.8", "3.9", "3.10"]
11+
os: [ubuntu-latest, macos-latest]
12+
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
1313
name: Python ${{ matrix.python-version }} example
1414

1515
steps:

Makefile

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
VERSION=$(shell python3 -c "import mpi4py_fft; print(mpi4py_fft.__version__)")
22

33
default:
4-
python setup.py build_ext -i
4+
python setup.py build build_ext -i
55

66
pip:
77
rm -f dist/*
@@ -15,6 +15,6 @@ tag:
1515
publish: tag pip
1616

1717
clean:
18-
git clean mpi4py_fft -fx
18+
git clean -dxf mpi4py_fft
1919
cd docs && make clean && cd ..
20-
@rm -rf *.egg-info/ build/ dist/ .eggs/
20+
@rm -rf *.egg-info/ build/ dist/ .eggs/

conf/meta.yaml

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ requirements:
1616
- {{ compiler('cxx') }}
1717
host:
1818
- python
19-
- cython <3.0
19+
- cython
2020
- numpy
2121
- pip
2222
- fftw
@@ -25,7 +25,7 @@ requirements:
2525
run:
2626
- python
2727
- mpi4py
28-
- mpich 4.0.2
28+
- mpich
2929
- {{ pin_compatible('numpy') }}
3030
- fftw
3131
- hdf5 * mpi_*

mpi4py_fft/fftw/fftw_xfftn.pxd

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cdef extern from "fftw3.h":
1+
cdef extern from "fftw3.h" nogil:
22

33
ctypedef struct fftw_complex_struct:
44
pass
@@ -12,15 +12,15 @@ cdef extern from "fftw3.h":
1212

1313
void fftw_destroy_plan(fftw_plan)
1414

15-
void fftw_execute_dft(fftw_plan, void *_in, void *_out) nogil
15+
void fftw_execute_dft(fftw_plan, void *_in, void *_out)
1616

17-
void fftw_execute_dft_c2r(fftw_plan, void *_in, void *_out) nogil
17+
void fftw_execute_dft_c2r(fftw_plan, void *_in, void *_out)
1818

19-
void fftw_execute_dft_r2c(fftw_plan, void *_in, void *_out) nogil
19+
void fftw_execute_dft_r2c(fftw_plan, void *_in, void *_out)
2020

21-
void fftw_execute_r2r(fftw_plan, void *_in, void *_out) nogil
21+
void fftw_execute_r2r(fftw_plan, void *_in, void *_out)
2222

23-
void fftw_execute(fftw_plan) nogil
23+
void fftw_execute(fftw_plan)
2424

2525
void fftw_init_threads()
2626

@@ -43,7 +43,7 @@ cdef extern from "fftw3.h":
4343
void fftw_print_plan(fftw_plan)
4444

4545

46-
cdef extern from "fftw_planxfftn.h":
46+
cdef extern from "fftw_planxfftn.h" nogil:
4747

4848
ctypedef double fftw_real
4949

mpi4py_fft/fftw/fftw_xfftn.pyx

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
cimport fftw_xfftn
21
#cython: language_level=3
2+
from . cimport fftw_xfftn
33
cimport numpy as np
44
from .utilities import *
55
import numpy as np
@@ -26,16 +26,16 @@ cpdef void cleanup():
2626
fftw_cleanup()
2727
fftw_cleanup_threads()
2828

29-
cdef void _fftw_execute_dft(void *plan, void *_in, void *_out) nogil:
29+
cdef void _fftw_execute_dft(void *plan, void *_in, void *_out) noexcept nogil:
3030
fftw_execute_dft(<fftw_plan>plan, <fftw_complex *>_in, <fftw_complex *>_out)
3131

32-
cdef void _fftw_execute_dft_r2c(void *plan, void *_in, void *_out) nogil:
32+
cdef void _fftw_execute_dft_r2c(void *plan, void *_in, void *_out) noexcept nogil:
3333
fftw_execute_dft_r2c(<fftw_plan>plan, <fftw_real *>_in, <fftw_complex *>_out)
3434

35-
cdef void _fftw_execute_dft_c2r(void *plan, void *_in, void *_out) nogil:
35+
cdef void _fftw_execute_dft_c2r(void *plan, void *_in, void *_out) noexcept nogil:
3636
fftw_execute_dft_c2r(<fftw_plan>plan, <fftw_complex *>_in, <fftw_real *>_out)
3737

38-
cdef void _fftw_execute_r2r(void *plan, void *_in, void *_out) nogil:
38+
cdef void _fftw_execute_r2r(void *plan, void *_in, void *_out) noexcept nogil:
3939
fftw_execute_r2r(<fftw_plan>plan, <fftw_real *>_in, <fftw_real *>_out)
4040

4141
cdef generic_function _get_execute_function(kind):

pyproject.toml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[build-system]
2+
requires = ["setuptools >= 42", "numpy", "cython >= 0.29.32"]
3+
build-backend = "setuptools.build_meta"

setup.py

+46-28
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
"""mpi4py-fft -- Parallel Fast Fourier Transforms (FFTs) using MPI for Python"""
23

34
import os
45
import sys
@@ -33,6 +34,8 @@ def get_prefix_dirs():
3334
append(dirs, sys.prefix)
3435
if 'CONDA_BUILD' not in os.environ:
3536
append(dirs, '/usr')
37+
append(dirs, '/usr/local')
38+
append(dirs, '/opt/homebrew')
3639
return dirs
3740

3841
def get_include_dirs():
@@ -101,10 +104,10 @@ def generate_extensions(fftwlibs, force=True):
101104
def remove_extensions(fftwlibs):
102105
"""Remove generated files"""
103106
for fname in (
104-
'utilities.c',
105-
'fftw_xfftn.c',
106-
'fftwf_xfftn.c',
107-
'fftwl_xfftn.c',
107+
'utilities.c',
108+
'fftw_xfftn.c',
109+
'fftwf_xfftn.c',
110+
'fftwl_xfftn.c',
108111
):
109112
dst = os.path.join(fftwdir, fname)
110113
try:
@@ -116,10 +119,10 @@ def remove_extensions(fftwlibs):
116119
continue
117120
p = 'fftw'+prec_map[d]+'_'
118121
for fname in (
119-
'fftw_planxfftn.h',
120-
'fftw_planxfftn.c',
121-
'fftw_xfftn.pyx',
122-
'fftw_xfftn.pxd',
122+
'fftw_planxfftn.h',
123+
'fftw_planxfftn.c',
124+
'fftw_xfftn.pyx',
125+
'fftw_xfftn.pxd',
123126
):
124127
dst = os.path.join(fftwdir, fname.replace('fftw_', p))
125128
try:
@@ -131,20 +134,31 @@ def get_extensions():
131134
"""Return list of extension modules"""
132135
include_dirs = get_include_dirs()
133136
library_dirs = get_library_dirs()
134-
ext = [Extension("mpi4py_fft.fftw.utilities",
135-
sources=[os.path.join(fftwdir, "utilities.pyx")],
136-
include_dirs=include_dirs)]
137+
ext = [
138+
Extension(
139+
"mpi4py_fft.fftw.utilities",
140+
sources=[os.path.join(fftwdir, "utilities.pyx")],
141+
define_macros=[('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')],
142+
include_dirs=include_dirs,
143+
),
144+
]
137145

138146
fftwlibs = get_fftw_libs()
139147
for d, libs in fftwlibs.items():
140-
p = 'fftw'+prec_map[d]+'_'
141-
ext.append(Extension("mpi4py_fft.fftw.{}xfftn".format(p),
142-
sources=[os.path.join(fftwdir, "{}xfftn.pyx".format(p)),
143-
os.path.join(fftwdir, "{}planxfftn.c".format(p))],
144-
#define_macros=[('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')],
145-
libraries=libs,
146-
include_dirs=include_dirs,
147-
library_dirs=library_dirs))
148+
p = 'fftw' + prec_map[d] + '_'
149+
ext.append(
150+
Extension(
151+
"mpi4py_fft.fftw.{}xfftn".format(p),
152+
sources=[
153+
os.path.join(fftwdir, "{}xfftn.pyx".format(p)),
154+
os.path.join(fftwdir, "{}planxfftn.c".format(p)),
155+
],
156+
define_macros=[('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')],
157+
libraries=libs,
158+
include_dirs=include_dirs,
159+
library_dirs=library_dirs,
160+
)
161+
)
148162
return ext
149163

150164

@@ -190,14 +204,19 @@ def version():
190204
if __name__ == '__main__':
191205
setup(name="mpi4py-fft",
192206
version=version(),
193-
description="mpi4py-fft -- Parallel Fast Fourier Transforms (FFTs) using MPI for Python",
207+
description=__doc__.strip(),
194208
long_description=long_description,
209+
long_description_content_type='text/x-rst',
195210
author="Lisandro Dalcin and Mikael Mortensen",
196-
url='https://github.com/mpi4py/mpi4py-fft',
197-
packages=["mpi4py_fft",
198-
"mpi4py_fft.fftw",
199-
"mpi4py_fft.io"],
200-
package_dir={"mpi4py_fft": "mpi4py_fft"},
211+
url="https://github.com/mpi4py/mpi4py-fft",
212+
packages=[
213+
"mpi4py_fft",
214+
"mpi4py_fft.fftw",
215+
"mpi4py_fft.io",
216+
],
217+
package_dir={
218+
"mpi4py_fft": "mpi4py_fft",
219+
},
201220
classifiers=[
202221
'Development Status :: 4 - Beta',
203222
'Environment :: Console',
@@ -209,10 +228,9 @@ def version():
209228
'License :: OSI Approved :: BSD License',
210229
'Topic :: Scientific/Engineering :: Mathematics',
211230
'Topic :: Software Development :: Libraries :: Python Modules',
212-
],
231+
],
232+
keywords=['Python', 'FFTW', 'FFT', 'DCT', 'DST', 'MPI'],
213233
distclass=Dist,
214234
ext_modules=get_extensions(),
215235
install_requires=["mpi4py", "numpy"],
216-
setup_requires=["setuptools>=18.0", "cython>=0.25"],
217-
keywords=['Python', 'FFTW', 'FFT', 'DCT', 'DST', 'MPI']
218236
)

tests/test_speed.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
from time import time
22
import numpy as np
3-
import pyfftw
43
import scipy.fftpack as sp
54
from mpi4py_fft import fftw
65
import pickle
76

7+
try:
8+
import pyfftw
9+
except ImportError:
10+
print('pyFFTW not available')
11+
raise SystemExit(0)
12+
813
try:
914
#fftw.import_wisdom('wisdom.dat')
1015
pyfftw.import_wisdom(pickle.load(open('pyfftw.wisdom', 'rb')))

0 commit comments

Comments
 (0)