Skip to content

Commit 78760ba

Browse files
jokvaprisae
authored andcommitted
Port build to meson+pyproject (#8)
To work with python >= 3.12, which will deprecated numpy.distutils, port the build to meson and pyproject. $ pip install build $ python -m build $ cd test && python -c "import fftlog; print(fftlog.__all__)" ['fhti', 'fftl', 'fht', 'fhtq'] The cd test is to avoid trying to import from $(pwd)/fftlog. This just changes the build, and does not hard constrain versions. Follow up work should be to figure out true minimum versions, maybe test with different compilers, and fix the type error in ifac and friends. The directory tree is flattened because fftlog/ doesn't form a cohesive module as-is. Due to the presence of the __init__.py the dir would be detected as a module and loaded by pytest and friends, shadowing the installed one and failing because it does not find the native extension. Finally, remove __init__.py from tests/ to not pretend it is a module anymore.
1 parent e636829 commit 78760ba

14 files changed

+100
-70
lines changed

.github/workflows/pytest.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ jobs:
5454
python -m pip install .[all]
5555
5656
- name: Flake8
57-
run: flake8 pyfftlog/ tests/
57+
run: flake8 src/ tests/
5858

5959
- name: Test with pytest
6060
run: pytest --cov=fftlog

meson.build

+56
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
project('fftlog', 'c')
2+
# fortran_std=legacy?
3+
add_languages('fortran')
4+
5+
if meson.get_compiler('fortran').get_id() == 'gcc'
6+
# Allow argument mismatch, otherwise (newer, probably >= 10) gfortran throws
7+
# Error: Type mismatch in argument ‘ifac’ at (1); passed REAL(8) to INTEGER(4)
8+
add_global_arguments('-fallow-argument-mismatch',
9+
language: ['fortran'])
10+
endif
11+
12+
py = import('python')
13+
py3 = py.find_installation()
14+
15+
f2py_name = '_fftlog'
16+
f2py_module_c = f'@[email protected]'
17+
f2py_wrapper_f = f'@[email protected]'
18+
f2py_dep = custom_target(
19+
'f2py wrappers',
20+
input: 'src/fftlog.pyf',
21+
output: [f2py_module_c, f2py_wrapper_f],
22+
command: [py3, '-m', 'numpy.f2py', '@INPUT@',
23+
'--build-dir', '@OUTDIR@', ],
24+
)
25+
26+
incdir_numpy = run_command(py3,
27+
['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'],
28+
check : true
29+
).stdout().strip()
30+
incdir_f2py = run_command(py3,
31+
['-c', 'import os; os.chdir(".."); import numpy.f2py; print(numpy.f2py.get_include())'],
32+
check : true
33+
).stdout().strip()
34+
inc_np = include_directories(incdir_numpy, incdir_f2py)
35+
36+
py3.extension_module('_fftlog',
37+
[f2py_dep,
38+
incdir_f2py / 'fortranobject.c',
39+
'src/cdgamma.f',
40+
'src/drfftb.f',
41+
'src/drfftf.f',
42+
'src/drffti.f',
43+
'src/fftlog.f',
44+
],
45+
link_language: 'fortran',
46+
include_directories: inc_np,
47+
install : true,
48+
subdir: 'fftlog',
49+
)
50+
51+
py3.install_sources([
52+
'src/__init__.py',
53+
],
54+
pure: false,
55+
subdir: 'fftlog',
56+
)

pyproject.toml

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
[build-system]
2+
build-backend = "mesonpy"
3+
requires = [
4+
"meson-python",
5+
"numpy",
6+
"wheel",
7+
"charset_normalizer",
8+
]
9+
10+
[project]
11+
name = "fftlog"
12+
description = "A python wrapper for FFTLog"
13+
readme = "README.rst"
14+
version = "0.2.1"
15+
authors = [
16+
{name = "The emsig community", email = "[email protected]"},
17+
]
18+
classifiers = [
19+
"Development Status :: 5 - Production/Stable",
20+
"License :: CC0 1.0 Universal (CC0 1.0) Public Domain Dedication",
21+
]
22+
dependencies = [
23+
"numpy",
24+
"scipy",
25+
]
26+
27+
[project.license]
28+
file = "LICENSE"
29+
30+
[project.optional-dependencies]
31+
tests = [
32+
"flake8",
33+
"pytest",
34+
"coveralls",
35+
"pytest_cov",
36+
"flake8-pyproject",
37+
]
38+
all = [
39+
"fftlog[tests]",
40+
]
41+
42+
[project.urls]
43+
Repository = "https://github.com/prisae/fftlog"

requirements-dev.txt

-8
This file was deleted.

requirements.txt

-1
This file was deleted.

setup.py

-60
This file was deleted.

fftlog/__init__.py src/__init__.py

File renamed without changes.

fftlog/src/cdgamma.f src/cdgamma.f

File renamed without changes.

fftlog/src/drfftb.f src/drfftb.f

File renamed without changes.

fftlog/src/drfftf.f src/drfftf.f

File renamed without changes.

fftlog/src/drffti.f src/drffti.f

File renamed without changes.

fftlog/src/fftlog.f src/fftlog.f

File renamed without changes.

fftlog/fftlog.pyf src/fftlog.pyf

File renamed without changes.

tests/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)