diff options
author | Rohit Goswami <rog32@hi.is> | 2021-11-15 21:07:38 +0000 |
---|---|---|
committer | Rohit Goswami <rog32@hi.is> | 2021-11-15 21:07:38 +0000 |
commit | a5bc4c124f884acb8aa4ee2d3c7db2e41aca738b (patch) | |
tree | d13f38b37c9e925d6bbb0521a4a815a6923adb8e | |
parent | a311764ec016510cce62304d25e781f97da7d3b4 (diff) | |
download | numpy-a5bc4c124f884acb8aa4ee2d3c7db2e41aca738b.tar.gz |
DOC: Update meson and f2py for automated wrappers
-rw-r--r-- | doc/source/f2py/buildtools/index.rst | 2 | ||||
-rw-r--r-- | doc/source/f2py/buildtools/meson.rst | 24 | ||||
-rw-r--r-- | doc/source/f2py/code/meson.build | 16 | ||||
-rw-r--r-- | doc/source/f2py/code/meson_upd.build | 37 |
4 files changed, 75 insertions, 4 deletions
diff --git a/doc/source/f2py/buildtools/index.rst b/doc/source/f2py/buildtools/index.rst index 75148fe22..959301ec5 100644 --- a/doc/source/f2py/buildtools/index.rst +++ b/doc/source/f2py/buildtools/index.rst @@ -1,3 +1,5 @@ +.. _f2py-bldsys: + ======================= F2PY and Build Systems ======================= diff --git a/doc/source/f2py/buildtools/meson.rst b/doc/source/f2py/buildtools/meson.rst index ad9fa65d7..d18715bbf 100644 --- a/doc/source/f2py/buildtools/meson.rst +++ b/doc/source/f2py/buildtools/meson.rst @@ -82,6 +82,30 @@ possible. The easiest way to solve this is to let ``f2py`` deal with it: python -c 'import fib2' +Automating wrapper generation +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +A major pain point in the workflow defined above, is the manual tracking of +inputs. Although it would require more effort to figure out the actual outputs +for reasons discussed in :ref:`f2py-bldsys`. + +However, we can augment our workflow in a straightforward to take into account +files for which the outputs are known when the build system is set up. + +.. literalinclude:: ./../code/meson_upd.build + :language: meson + +This can be compiled and run as before. + +.. code-block:: bash + + rm -rf builddir + meson setup builddir + meson compile -C builddir + cd builddir + python -c "import numpy as np; import fibby; a = np.zeros(9); fibby.fib(a); print (a)" + # [ 0. 1. 1. 2. 3. 5. 8. 13. 21.] + Salient points =============== diff --git a/doc/source/f2py/code/meson.build b/doc/source/f2py/code/meson.build index 425ee90f6..b756abf8f 100644 --- a/doc/source/f2py/code/meson.build +++ b/doc/source/f2py/code/meson.build @@ -5,8 +5,10 @@ project('f2py_examples', 'c', add_languages('fortran') py_mod = import('python') -py3 = py_mod.find_installation() +py3 = py_mod.find_installation('python3') py3_dep = py3.dependency() +message(py3.path()) +message(py3.get_install_dir()) incdir_numpy = run_command(py3, ['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'], @@ -18,13 +20,19 @@ incdir_f2py = run_command(py3, check : true ).stdout().strip() +fibby_source = custom_target('fibbymodule.c', + input : ['fib1.f'], + output : ['fibbymodule.c'], + command : [ py3, '-m', 'numpy.f2py', '@INPUT@', + '-m', 'fibby', '--lower' ] + ) + inc_np = include_directories(incdir_numpy, incdir_f2py) -py3.extension_module('fib2', +py3.extension_module('fibby', 'fib1.f', - 'fib2module.c', + fibby_source, incdir_f2py+'/fortranobject.c', include_directories: inc_np, dependencies : py3_dep, install : true) - diff --git a/doc/source/f2py/code/meson_upd.build b/doc/source/f2py/code/meson_upd.build new file mode 100644 index 000000000..97bd8d175 --- /dev/null +++ b/doc/source/f2py/code/meson_upd.build @@ -0,0 +1,37 @@ +project('f2py_examples', 'c', + version : '0.1', + default_options : ['warning_level=2']) + +add_languages('fortran') + +py_mod = import('python') +py3 = py_mod.find_installation('python3') +py3_dep = py3.dependency() +message(py3.path()) +message(py3.get_install_dir()) + +incdir_numpy = run_command(py3, + ['-c', 'import os; os.chdir(".."); import numpy; print(numpy.get_include())'], + check : true +).stdout().strip() + +incdir_f2py = run_command(py3, + ['-c', 'import os; os.chdir(".."); import numpy.f2py; print(numpy.f2py.get_include())'], + check : true +).stdout().strip() + +fibby_source = custom_target('fibbymodule.c', + input : ['fib1.f'], + output : ['fibbymodule.c'], + command : [ py3, '-m', 'numpy.f2py', '@INPUT@', + '-m', 'fibby', '--lower' ]) + +inc_np = include_directories(incdir_numpy, incdir_f2py) + +py3.extension_module('fibby', + 'fib1.f', + fibby_source, + incdir_f2py+'/fortranobject.c', + include_directories: inc_np, + dependencies : py3_dep, + install : true) |