Skip to content

Commit 1761376

Browse files
committed
Add pyproject.toml and support Cython 3
1 parent 291e327 commit 1761376

File tree

8 files changed

+72
-48
lines changed

8 files changed

+72
-48
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 7 additions & 7 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 3 additions & 0 deletions
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

Lines changed: 44 additions & 28 deletions
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
@@ -101,10 +102,10 @@ def generate_extensions(fftwlibs, force=True):
101102
def remove_extensions(fftwlibs):
102103
"""Remove generated files"""
103104
for fname in (
104-
'utilities.c',
105-
'fftw_xfftn.c',
106-
'fftwf_xfftn.c',
107-
'fftwl_xfftn.c',
105+
'utilities.c',
106+
'fftw_xfftn.c',
107+
'fftwf_xfftn.c',
108+
'fftwl_xfftn.c',
108109
):
109110
dst = os.path.join(fftwdir, fname)
110111
try:
@@ -116,10 +117,10 @@ def remove_extensions(fftwlibs):
116117
continue
117118
p = 'fftw'+prec_map[d]+'_'
118119
for fname in (
119-
'fftw_planxfftn.h',
120-
'fftw_planxfftn.c',
121-
'fftw_xfftn.pyx',
122-
'fftw_xfftn.pxd',
120+
'fftw_planxfftn.h',
121+
'fftw_planxfftn.c',
122+
'fftw_xfftn.pyx',
123+
'fftw_xfftn.pxd',
123124
):
124125
dst = os.path.join(fftwdir, fname.replace('fftw_', p))
125126
try:
@@ -131,20 +132,31 @@ def get_extensions():
131132
"""Return list of extension modules"""
132133
include_dirs = get_include_dirs()
133134
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)]
135+
ext = [
136+
Extension(
137+
"mpi4py_fft.fftw.utilities",
138+
sources=[os.path.join(fftwdir, "utilities.pyx")],
139+
define_macros=[('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')],
140+
include_dirs=include_dirs,
141+
),
142+
]
137143

138144
fftwlibs = get_fftw_libs()
139145
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))
146+
p = 'fftw' + prec_map[d] + '_'
147+
ext.append(
148+
Extension(
149+
"mpi4py_fft.fftw.{}xfftn".format(p),
150+
sources=[
151+
os.path.join(fftwdir, "{}xfftn.pyx".format(p)),
152+
os.path.join(fftwdir, "{}planxfftn.c".format(p)),
153+
],
154+
define_macros=[('NPY_NO_DEPRECATED_API', 'NPY_1_7_API_VERSION')],
155+
libraries=libs,
156+
include_dirs=include_dirs,
157+
library_dirs=library_dirs,
158+
)
159+
)
148160
return ext
149161

150162

@@ -190,14 +202,19 @@ def version():
190202
if __name__ == '__main__':
191203
setup(name="mpi4py-fft",
192204
version=version(),
193-
description="mpi4py-fft -- Parallel Fast Fourier Transforms (FFTs) using MPI for Python",
205+
description=__doc__.strip(),
194206
long_description=long_description,
207+
long_description_content_type='text/x-rst',
195208
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"},
209+
url="https://github.com/mpi4py/mpi4py-fft",
210+
packages=[
211+
"mpi4py_fft",
212+
"mpi4py_fft.fftw",
213+
"mpi4py_fft.io",
214+
],
215+
package_dir={
216+
"mpi4py_fft": "mpi4py_fft",
217+
},
201218
classifiers=[
202219
'Development Status :: 4 - Beta',
203220
'Environment :: Console',
@@ -209,10 +226,9 @@ def version():
209226
'License :: OSI Approved :: BSD License',
210227
'Topic :: Scientific/Engineering :: Mathematics',
211228
'Topic :: Software Development :: Libraries :: Python Modules',
212-
],
229+
],
230+
keywords=['Python', 'FFTW', 'FFT', 'DCT', 'DST', 'MPI'],
213231
distclass=Dist,
214232
ext_modules=get_extensions(),
215233
install_requires=["mpi4py", "numpy"],
216-
setup_requires=["setuptools>=18.0", "cython>=0.25"],
217-
keywords=['Python', 'FFTW', 'FFT', 'DCT', 'DST', 'MPI']
218234
)

tests/test_speed.py

Lines changed: 6 additions & 1 deletion
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)