8000 DOC: Update meson and f2py for automated wrappers · numpy/numpy@a5bc4c1 · GitHub
[go: up one dir, main page]

Skip to content

Commit a5bc4c1

Browse files
committed
DOC: Update meson and f2py for automated wrappers
1 parent a311764 commit a5bc4c1

File tree

4 files changed

+75
-4
lines changed

4 files changed

+75
-4
lines changed

doc/source/f2py/buildtools/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
.. _f2py-bldsys:
2+
13
=======================
24
F2PY and Build Systems
35
=======================

doc/source/f2py/buildtools/meson.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,30 @@ possible. The easiest way to solve this is to let ``f2py`` deal with it:
8282
python -c 'import fib2'
8383
8484
85+
Automating wrapper generation
86+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
87+
88+
A major pain point in the workflow defined above, is the manual tracking of
89+
inputs. Although it would require more effort to figure out the actual outputs
90+
for reasons discussed in :ref:`f2py-bldsys`.
91+
92+
However, we can augment our workflow in a straightforward to take into account
93+
files for which the outputs are known when the build system is set up.
94+
95+
.. literalinclude:: ./../code/meson_upd.build
96+
:language: meson
97+
98+
This can be compiled and run as before.
99+
100+
.. code-block:: bash
101+
102+
rm -rf builddir
103+
meson setup builddir
104+
meson compile -C builddir
105+
cd builddir
106+
python -c "import numpy as np; import fibby; a = np.zeros(9); fibby.fib(a); print (a)"
107+
# [ 0. 1. 1. 2. 3. 5. 8. 13. 21.]
108+
85109
Salient points
86110
===============
87111

doc/source/f2py/code/meson.build

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ project('f2py_examples', 'c',
55
add_languages('fortran')
66

77
py_mod = import('python')
8-
py3 = py_mod.find_installation()
8+
py3 = py_mod.find_installation('python3')
99
py3_dep = py3.dependency()
10+
message(py3.path())
11+
message(py3.get_install_dir())
1012

1113
incdir_numpy = run_command(py3,
1214
['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'],
@@ -18,13 +20,19 @@ incdir_f2py = run_command(py3,
1820
check : true
1921
).stdout().strip()
2022

23+
fibby_source = custom_target('fibbymodule.c',
24+
input : ['fib1.f'],
25+
output : ['fibbymodule.c'],
26+
command : [ py3, '-m', 'numpy.f2py', '@INPUT@',
27+
'-m', 'fibby', '--lower' ]
28+
)
29+
2130
inc_np = include_directories(incdir_numpy, incdir_f2py)
2231

23-
py3.extension_module('fib2',
32+
py3.extension_module('fibby',
2433
'fib1.f',
25-
'fib2module.c',
34+
fibby_source,
2635
incdir_f2py+'/fortranobject.c',
2736
include_directories: inc_np,
2837
dependencies : py3_dep,
2938
install : true)
30-

doc/source/f2py/code/meson_upd.build

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
project('f2py_examples', 'c',
2+
version : '0.1',
3+
default_options : ['warning_level=2'])
4+
5+
add_languages('fortran')
6+
7+
py_mod = import('python')
8+
py3 = py_mod.find_installation('python3')
9+
py3_dep = py3.dependency()
10+
message(py3.path())
11+
message(py3.get_install_dir())
12+
13+
incdir_numpy = run_command(py3,
14+
['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'],
15+
check : true
16+
).stdout().strip()
17+
18+
incdir_f2py = run_command(py3,
19+
['-c', 'import os; os.chdir(".."); import numpy.f2py; print(numpy.f2py.get_include())'],
20+
check : true
21+
).stdout().strip()
22+
23+
fibby_source = custom_target('fibbymodule.c',
24+
input : ['fib1.f'],
25+
output : ['fibbymodule.c'],
26+
command : [ py3, '-m', 'numpy.f2py', '@INPUT@',
27+
'-m', 'fibby', '--lower' ])
28+
29+
inc_np = include_directories(incdir_numpy, incdir_f2py)
30+
31+
py3.extension_module('fibby',
32+
'fib1.f',
33+
fibby_source,
34+
incdir_f2py+'/fortranobject.c',
35+
include_directories: inc_np,
36+
dependencies : py3_dep,
37+
install : true)

0 commit comments

Comments
 (0)
0