Skip to content

Commit d85ba6b

Browse files
committed
BLD: use a generator for f2py
This removes all remaining invocations of `py3` in meson.build files. Not invoking the Python interpreter we're building for at all helps with cross-compilation, since that interpreter typically isn't able to run without the use of an emulator like QEMU.
1 parent 287f353 commit d85ba6b

27 files changed

+62
-110
lines changed

mypy.ini

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ ignore_missing_imports = True
119119
[mypy-scipy.optimize._slsqp]
120120
ignore_missing_imports = True
121121

122-
[mypy-scipy.interpolate.dfitpack]
122+
[mypy-scipy.interpolate._dfitpack]
123123
ignore_missing_imports = True
124124

125125
[mypy-scipy.interpolate.interpnd]

scipy/_build_utils/_generate_blas_wrapper.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
"""
23
Generate wrappers to dispatch BLAS/LAPACK calls to the properly prefixed/
34
suffixed symbols.

scipy/_build_utils/echo.py

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env python3
2+
"""
3+
A dummy script that only echos its input arguments.
4+
5+
This is useful in case a platform-independent way to run a no-op command
6+
on a target in a meson.build file is needed (e.g., to establish a
7+
dependency between targets).
8+
"""
9+
import logging
10+
import sys
11+
12+
logging.debug(f"Passed args to `scipy/_build_utils/echo.py`: {sys.argv[1:]}")

scipy/_build_utils/meson.build

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
if generate_blas_wrappers
2-
blas_wrapper_gen = files('_generate_blas_wrapper.py')
2+
blas_wrapper_gen = find_program('_generate_blas_wrapper.py')
33
blas_lapack_wrappers = custom_target('blas_lapack_wrappers',
44
output: ['blas_lapack_wrappers.c'],
5-
command: [py3, blas_wrapper_gen, '-o', '@OUTDIR@', accelerate_flag],
5+
command: [blas_wrapper_gen, '-o', '@OUTDIR@', accelerate_flag],
66
depend_files: [
77
'../linalg/cython_blas_signatures.txt',
88
'../linalg/cython_lapack_signatures.txt',

scipy/integrate/meson.build

+4-28
Original file line numberDiff line numberDiff line change
@@ -128,14 +128,8 @@ py3.extension_module('_odepack',
128128
subdir: 'scipy/integrate'
129129
)
130130

131-
vode_module = custom_target('vode_module',
132-
output: ['_vode-f2pywrappers.f', '_vodemodule.c'],
133-
input: 'vode.pyf',
134-
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
135-
)
136-
137131
py3.extension_module('_vode',
138-
vode_module,
132+
f2py_gen.process('vode.pyf'),
139133
link_with: [vode_lib],
140134
c_args: [Wno_unused_variable],
141135
link_args: version_link_args,
@@ -145,14 +139,8 @@ py3.extension_module('_vode',
145139
subdir: 'scipy/integrate'
146140
)
147141

148-
lsoda_module = custom_target('lsoda_module',
149-
output: ['_lsoda-f2pywrappers.f', '_lsodamodule.c'],
150-
input: 'lsoda.pyf',
151-
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
152-
)
153-
154142
py3.extension_module('_lsoda',
155-
lsoda_module,
143+
f2py_gen.process('lsoda.pyf'),
156144
link_with: [lsoda_lib, mach_lib],
157145
c_args: [Wno_unused_variable],
158146
dependencies: [lapack_dep, fortranobject_dep],
@@ -162,14 +150,8 @@ py3.extension_module('_lsoda',
162150
subdir: 'scipy/integrate'
163151
)
164152

165-
_dop_module = custom_target('_dop_module',
166-
output: ['_dop-f2pywrappers.f', '_dopmodule.c'],
167-
input: 'dop.pyf',
168-
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
169-
)
170-
171153
py3.extension_module('_dop',
172-
_dop_module,
154+
f2py_gen.process('dop.pyf'),
173155
link_with: [dop_lib],
174156
c_args: [Wno_unused_variable],
175157
dependencies: [fortranobject_dep],
@@ -186,14 +168,8 @@ py3.extension_module('_test_multivariate',
186168
subdir: 'scipy/integrate'
187169
)
188170

189-
_test_odeint_banded_module = custom_target('_test_odeint_banded_module',
190-
output: ['_test_odeint_bandedmodule.c', '_test_odeint_banded-f2pywrappers.f'],
191-
input: 'tests/banded5x5.pyf',
192-
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
193-
)
194-
195171
py3.extension_module('_test_odeint_banded',
196-
['tests/banded5x5.f', _test_odeint_banded_module],
172+
['tests/banded5x5.f', f2py_gen.process('tests/test_odeint_banded.pyf')],
197173
link_with: [lsoda_lib, mach_lib],
198174
fortran_args: _fflag_Wno_unused_dummy_argument,
199175
link_args: version_link_args,

scipy/interpolate/_fitpack2.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import numpy as np
2626

2727
from . import _fitpack_impl
28-
from . import dfitpack
28+
from . import _dfitpack as dfitpack
2929

3030

3131
dfitpack_int = dfitpack.types.intvar.dtype

scipy/interpolate/_fitpack_impl.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
# Try to replace _fitpack interface with
3434
# f2py-generated version
35-
from . import dfitpack
35+
from . import _dfitpack as dfitpack
3636

3737

3838
dfitpack_int = dfitpack.types.intvar.dtype

scipy/interpolate/_interpolate.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from scipy.special import comb
1313

1414
from . import _fitpack_py
15-
from . import dfitpack
15+
from . import _dfitpack as dfitpack
1616
from ._polyint import _Interpolator1D
1717
from . import _ppoly
1818
from .interpnd import _ndim_coords_from_arrays

scipy/interpolate/meson.build

+2-8
Original file line numberDiff line numberDiff line change
@@ -143,15 +143,9 @@ py3.extension_module('_fitpack',
143143
subdir: 'scipy/interpolate'
144144
)
145145

146-
dfitpack_module = custom_target('dfitpack_module',
147-
output: ['dfitpack-f2pywrappers.f', 'dfitpackmodule.c'],
148-
input: 'src/fitpack.pyf',
149-
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
150-
)
151-
152146
# TODO: Add flags for 64 bit ints
153-
py3.extension_module('dfitpack',
154-
dfitpack_module,
147+
py3.extension_module('_dfitpack',
148+
f2py_gen.process('src/dfitpack.pyf'),
155149
c_args: [Wno_unused_variable],
156150
link_args: version_link_args,
157151
dependencies: [lapack_dep, fortranobject_dep],

scipy/interpolate/src/fitpack.pyf renamed to scipy/interpolate/src/dfitpack.pyf

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
! This limit can be overridden with -fmax-stack-var-size, or -frecursive can
1010
! be used to force all local arrays to be allocated on the stack.
1111
!
12-
python module dfitpack ! in
12+
python module _dfitpack ! in
1313

1414
usercode '''
1515

scipy/interpolate/tests/test_bsplines.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
# XXX: move to the interpolate namespace
2525
from scipy.interpolate._ndbspline import make_ndbspl
2626

27-
from scipy.interpolate import dfitpack
27+
from scipy.interpolate import _dfitpack as dfitpack
2828
from scipy.interpolate import _bsplines as _b
2929

3030

scipy/interpolate/tests/test_fitpack.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
from scipy.interpolate._fitpack_py import (splrep, splev, bisplrep, bisplev,
1414
sproot, splprep, splint, spalde, splder, splantider, insert, dblint)
15-
from scipy.interpolate.dfitpack import regrid_smth
15+
from scipy.interpolate._dfitpack import regrid_smth
1616
from scipy.interpolate._fitpack2 import dfitpack_int
1717

1818

scipy/io/meson.build

+1-7
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
1-
_test_fortran_module = custom_target('_test_fortran_module',
2-
output: ['_test_fortranmodule.c'],
3-
input: '_test_fortran.pyf',
4-
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
5-
)
6-
71
py3.extension_module('_test_fortran',
82
[
9-
_test_fortran_module,
3+
f2py_gen.process('test_fortran.pyf'),
104
'_test_fortran.f'
115
],
126
c_args: [Wno_unused_variable],
File renamed without changes.

scipy/linalg/_generate_pyx.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
"""
23
Code generator script to make the Cython BLAS and LAPACK wrappers
34
from the files "cython_blas_signatures.txt" and

scipy/linalg/meson.build

+5-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
__init__py = fs.copyfile('__init__.py')
44
_cy_array_utils_pxd = fs.copyfile('_cythonized_array_utils.pxd')
55

6+
_generate_pyx = find_program('_generate_pyx.py')
67
cython_linalg = custom_target('cython_linalg',
78
output: [
89
'cython_blas.pyx',
@@ -13,7 +14,7 @@ cython_linalg = custom_target('cython_linalg',
1314
'_lapack_subroutines.h'
1415
],
1516
input: '_generate_pyx.py',
16-
command: [py3, '@INPUT@', '-o', '@OUTDIR@', accelerate_flag],
17+
command: [_generate_pyx, '-o', '@OUTDIR@', accelerate_flag],
1718
depend_files: [
1819
'cython_blas_signatures.txt',
1920
'cython_lapack_signatures.txt',
@@ -30,10 +31,11 @@ cython_linalg = custom_target('cython_linalg',
3031
# warnings about multiple outputs. And using `depends: cython_linalg[2]` does
3132
# not work, because that generator depends does not accept CustomTargetIndex,
3233
# only CustomTarget. See https://github.com/mesonbuild/meson/issues/9837
34+
_echo = find_program('../_build_utils/echo.py')
3335
cython_blas_pxd = custom_target(
3436
output: '_dummy_cython_blas.pxd',
3537
input: cython_linalg[2],
36-
command: [py3, '-c', '"@INPUT@"'],
38+
command: [_echo, '@INPUT@'],
3739
)
3840

3941
# pyx -> c, pyx -> cpp generators, depending on __init__.py here.
@@ -109,13 +111,6 @@ py3.extension_module('_flapack',
109111

110112
# TODO: cblas/clapack are built *only* for ATLAS. Why? Is it still needed?
111113

112-
# _interpolative
113-
interpolative_module = custom_target('interpolative_module',
114-
output: '_interpolativemodule.c',
115-
input: 'interpolative.pyf',
116-
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
117-
)
118-
119114
# id_dist contains a copy of FFTPACK, which has type mismatch warnings
120115
# that are hard to fix. This code is terrible and noisy during the build,
121116
# silence it completely.
@@ -159,7 +154,7 @@ py3.extension_module('_interpolative',
159154
'src/id_dist/src/idzr_rid.f',
160155
'src/id_dist/src/idzr_rsvd.f',
161156
'src/id_dist/src/prini.f',
162-
interpolative_module,
157+
f2py_gen.process('interpolative.pyf'),
163158
],
164159
fortran_args: [fortran_ignore_warnings, _suppress_all_warnings],
165160
link_args: version_link_args,

scipy/meson.build

+11-1
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,15 @@ fortranobject_dep = declare_dependency(
144144
compile_args: _f2py_c_args,
145145
)
146146

147+
f2py = find_program('f2py')
148+
# Note: cannot handle .pyf.src or targets with #include's (due to no
149+
# `depend_files` - see feature request at meson#8295)
150+
f2py_gen = generator(generate_f2pymod,
151+
arguments : ['@INPUT@', '-o', '@BUILD_DIR@'],
152+
153+
)
154+
155+
147156
# TODO: 64-bit BLAS and LAPACK
148157
#
149158
# Note that this works as long as BLAS and LAPACK are detected properly via
@@ -252,14 +261,15 @@ endif
252261

253262
scipy_dir = py3.get_install_dir() / 'scipy'
254263

264+
version_utils = find_program('../tools/version_utils.py')
255265
generate_version = custom_target(
256266
'generate-version',
257267
install: true,
258268
build_always_stale: true,
259269
build_by_default: true,
260270
output: 'version.py',
261271
input: '../tools/version_utils.py',
262-
command: [py3, '@INPUT@', '--source-root', '@SOURCE_ROOT@'],
272+
command: [version_utils, '--source-root', '@SOURCE_ROOT@'],
263273
install_dir: scipy_dir,
264274
install_tag: 'python-runtime',
265275
)

scipy/optimize/meson.build

+4-28
Original file line numberDiff line numberDiff line change
@@ -92,18 +92,12 @@ py3.extension_module('_zeros',
9292
subdir: 'scipy/optimize'
9393
)
9494

95-
lbfgsb_module = custom_target('lbfgsb_module',
96-
output: ['_lbfgsb-f2pywrappers.f', '_lbfgsbmodule.c'],
97-
input: 'lbfgsb_src/lbfgsb.pyf',
98-
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
99-
)
100-
10195
py3.extension_module('_lbfgsb',
10296
[
10397
'lbfgsb_src/lbfgsb.f',
10498
'lbfgsb_src/linpack.f',
10599
'lbfgsb_src/timer.f',
106-
lbfgsb_module,
100+
f2py_gen.process('lbfgsb_src/lbfgsb.pyf'),
107101
],
108102
fortran_args: fortran_ignore_warnings,
109103
link_args: version_link_args,
@@ -126,14 +120,8 @@ py3.extension_module('_moduleTNC',
126120
subdir: 'scipy/optimize'
127121
)
128122

129-
cobyla_module = custom_target('cobyla_module',
130-
output: ['_cobylamodule.c'],
131-
input: 'cobyla/cobyla.pyf',
132-
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
133-
)
134-
135123
py3.extension_module('_cobyla',
136-
[cobyla_module, 'cobyla/cobyla2.f', 'cobyla/trstlp.f'],
124+
[f2py_gen.process('cobyla/cobyla.pyf'), 'cobyla/cobyla2.f', 'cobyla/trstlp.f'],
137125
c_args: [Wno_unused_variable],
138126
fortran_args: fortran_ignore_warnings,
139127
link_args: version_link_args,
@@ -143,14 +131,8 @@ py3.extension_module('_cobyla',
143131
subdir: 'scipy/optimize'
144132
)
145133

146-
minpack2_module = custom_target('minpack2_module',
147-
output: ['_minpack2module.c'],
148-
input: 'minpack2/minpack2.pyf',
149-
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
150-
)
151-
152134
py3.extension_module('_minpack2',
153-
[minpack2_module, 'minpack2/dcsrch.f', 'minpack2/dcstep.f'],
135+
[f2py_gen.process('minpack2/minpack2.pyf'), 'minpack2/dcsrch.f', 'minpack2/dcstep.f'],
154136
fortran_args: fortran_ignore_warnings,
155137
link_args: version_link_args,
156138
dependencies: [fortranobject_dep],
@@ -160,14 +142,8 @@ py3.extension_module('_minpack2',
160142
subdir: 'scipy/optimize'
161143
)
162144

163-
slsqp_module = custom_target('slsqp_module',
164-
output: ['_slsqpmodule.c'],
165-
input: 'slsqp/slsqp.pyf',
166-
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
167-
)
168-
169145
py3.extension_module('_slsqp',
170-
[slsqp_module, 'slsqp/slsqp_optmz.f'],
146+
[f2py_gen.process('slsqp/slsqp.pyf'), 'slsqp/slsqp_optmz.f'],
171147
fortran_args: fortran_ignore_warnings,
172148
link_args: version_link_args,
173149
dependencies: [fortranobject_dep],

scipy/sparse/_generate_sparsetools.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
"""
23
python generate_sparsetools.py
34

scipy/sparse/linalg/_propack/meson.build

+1-7
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,8 @@ foreach ele: elements
9797
gnu_symbol_visibility: 'hidden',
9898
)
9999

100-
propack_module = custom_target('propack_module' + ele[0],
101-
output: [ele[0] + '-f2pywrappers.f', ele[0] + 'module.c'],
102-
input: ele[2],
103-
command: [generate_f2pymod, '@INPUT@', '-o', '@OUTDIR@']
104-
)
105-
106100
propacklib = py3.extension_module(ele[0],
107-
propack_module,
101+
f2py_gen.process(ele[2]),
108102
link_with: propack_lib,
109103
c_args: ['-U_OPENMP', _cpp_Wno_cpp],
110104
fortran_args: _fflag_Wno_maybe_uninitialized,

scipy/sparse/sparsetools/meson.build

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
gen_sparsetools = find_program('../_generate_sparsetools.py')
12
_sparsetools_headers = custom_target('_sparsetools_headers',
23
output: [
34
'bsr_impl.h',
@@ -7,7 +8,7 @@ _sparsetools_headers = custom_target('_sparsetools_headers',
78
'sparsetools_impl.h',
89
],
910
input: '../_generate_sparsetools.py',
10-
command: [py3, '@INPUT@', '--no-force', '-o', '@OUTDIR@']
11+
command: [gen_sparsetools, '--no-force', '-o', '@OUTDIR@']
1112
)
1213

1314
py3.extension_module('_sparsetools',

scipy/special/_generate_pyx.py

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env python3
12
"""
23
python _generate_pyx.py
34

0 commit comments

Comments
 (0)