Skip to content

BUG: Bad meson code generated by f2py with dotted library #26623

Description

@mathomp4

Describe the issue:

I'm having an issue trying to build a code using f2py with meson (aka Python 3.12). To wit, I have an f2py code that depends on a library libMAPL.base.so. When I try and use f2py with it, I get this error from Meson:

The Meson build system
Version: 1.4.1
Source dir: /tmp/tmpzxxmb51m
Build dir: /tmp/tmpzxxmb51m/bbdir
Build type: native build

meson.build:35:10: ERROR: Expecting lparen got assign.
MAPL.base = declare_dependency(link_args : ['-lMAPL.base'])
          ^

I believe the issue is that Meson thinks that MAPL.base is a method of the MAPL object or something? (I do not know Meson.)

You can reproduce this with the code below (saved as qsat_py.F90) running with:

f2py -m qsat_  -lMAPL.base --build-dir ./foo -c qsat_py.F90

Reproduce the code example:

subroutine qsat ( qs, T, p, nobs )
  use MAPL_SatVaporMod, only: MAPL_EQsat

  integer, intent(in) :: nobs
  real,    intent(in) :: p(nobs) ! pressure in Pa
  real,    intent(in) :: T(nobs) ! dry-bulb temperature in K
  real,    intent(out) :: qs(nobs) ! saturation specific humidity
  integer i

  do i = 1, nobs
     qs(i) = MAPL_EQsat(TL=t(i),PL=p(i),OverIce=.True.)
  end do
end subroutine qsat

subroutine qsatnoice ( qs, T, p, nobs )
  use MAPL_SatVaporMod, only: MAPL_EQsat

  integer, intent(in) :: nobs
  real,    intent(in) :: p(nobs) ! pressure in Pa
  real,    intent(in) :: T(nobs) ! dry-bulb temperature in K
  real,    intent(out) :: qs(nobs) ! saturation specific humidity
  integer i

  do i = 1, nobs
     qs(i) = MAPL_EQsat(TL=t(i),PL=p(i),OverIce=.False.)
  end do
end subroutine qsatnoice

Error message:

The Meson build system
Version: 1.4.1
Source dir: /tmp/tmpzxxmb51m
Build dir: /tmp/tmpzxxmb51m/bbdir
Build type: native build

meson.build:35:10: ERROR: Expecting lparen got assign.
MAPL.base = declare_dependency(link_args : ['-lMAPL.base'])
          ^

A full log can be found at /tmp/tmpzxxmb51m/bbdir/meson-logs/meson-log.txt
Traceback (most recent call last):
  File "/usr/local/other/GEOSpyD/24.4.0-0_py3.12/2024-05-31/bin/f2py", line 10, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/other/GEOSpyD/24.4.0-0_py3.12/2024-05-31/lib/python3.12/site-packages/numpy/f2py/f2py2e.py", line 766, in main
    run_compile()
  File "/usr/local/other/GEOSpyD/24.4.0-0_py3.12/2024-05-31/lib/python3.12/site-packages/numpy/f2py/f2py2e.py", line 738, in run_compile
    builder.compile()
  File "/usr/local/other/GEOSpyD/24.4.0-0_py3.12/2024-05-31/lib/python3.12/site-packages/numpy/f2py/_backends/_meson.py", line 178, in compile
    self.run_meson(self.build_dir)
  File "/usr/local/other/GEOSpyD/24.4.0-0_py3.12/2024-05-31/lib/python3.12/site-packages/numpy/f2py/_backends/_meson.py", line 171, in run_meson
    self._run_subprocess_command(setup_command, build_dir)
  File "/usr/local/other/GEOSpyD/24.4.0-0_py3.12/2024-05-31/lib/python3.12/site-packages/numpy/f2py/_backends/_meson.py", line 167, in _run_subprocess_command
    subprocess.run(command, cwd=cwd, check=True)
  File "/usr/local/other/GEOSpyD/24.4.0-0_py3.12/2024-05-31/lib/python3.12/subprocess.py", line 571, in run
    raise CalledProcessError(retcode, process.args,
subprocess.CalledProcessError: Command '['meson', 'setup', 'bbdir']' returned non-zero exit status 1.

Python and NumPy Versions:

1.26.4
3.12.2 | packaged by conda-forge | (main, Feb 16 2024, 20:50:58) [GCC 12.3.0]

Runtime Environment:

[{'numpy_version': '1.26.4',
'python': '3.12.2 | packaged by conda-forge | (main, Feb 16 2024, 20:50:58) '
'[GCC 12.3.0]',
'uname': uname_result(system='Linux', node='discover33', release='5.14.21-150400.24.81-default', version='#1 SMP PREEMPT_DYNAMIC Tue Aug 8 14:10:43 UTC 2023 (90a74a8)', machine='x86_64')},
{'simd_extensions': {'baseline': ['SSE', 'SSE2', 'SSE3'],
'found': ['SSSE3',
'SSE41',
'POPCNT',
'SSE42',
'AVX',
'F16C',
'FMA3',
'AVX2'],
'not_found': ['AVX512F',
'AVX512CD',
'AVX512_KNL',
'AVX512_KNM',
'AVX512_SKX',
'AVX512_CLX',
'AVX512_CNL',
'AVX512_ICL',
'AVX512_SPR']}},
{'filepath': '/gpfsm/dulocal15/sles15/other/GEOSpyD/24.4.0-0_py3.12/2024-05-31/lib/libmkl_rt.so.2',
'internal_api': 'mkl',
'num_threads': 1,
'prefix': 'libmkl_rt',
'threading_layer': 'intel',
'user_api': 'blas',
'version': '2023.2-Product'},
{'filepath': '/gpfsm/dulocal15/sles15/other/GEOSpyD/24.4.0-0_py3.12/2024-05-31/lib/libomp.so',
'internal_api': 'openmp',
'num_threads': 1,
'prefix': 'libomp',
'user_api': 'openmp',
'version': None}]

Context for the issue:

We cannot move to Python 3.12 unless we can work around this. Is there someway to have f2py "mangle" the variables it constructs in meson?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions