Skip to content

BUG: avoid invalid Meson identifiers for f2py libraries#31963

Merged
HaoZeke merged 4 commits into
numpy:mainfrom
VectorPeak:fix-f2py-meson-lib-identifiers
Jul 12, 2026
Merged

BUG: avoid invalid Meson identifiers for f2py libraries#31963
HaoZeke merged 4 commits into
numpy:mainfrom
VectorPeak:fix-f2py-meson-lib-identifiers

Conversation

@VectorPeak

@VectorPeak VectorPeak commented Jul 11, 2026

Copy link
Copy Markdown
Contributor

PR summary

Fixes #31964.

Fixes invalid Meson variable names generated by the f2py Meson backend for -l libraries whose names are valid linker library names but are not valid Meson identifiers.

#26634 handled dotted library names by replacing . with _, but other inputs can still break or become ambiguous when the raw library name is used as the Meson variable name. For example, a library such as scalapack-openmpi can lead to an invalid assignment target in the generated meson.build.

This PR separates the internal Meson variable name from the user-provided linker library name. The generated dependency variable now uses a private indexed identifier, while the linker argument still preserves the original value, e.g. -lscalapack-openmpi remains -lscalapack-openmpi.

The regression test parses the generated meson.build and asserts that the generated dependency declarations preserve the original -l<name> linker arguments, while the unsafe original library names are not used directly as Meson assignment targets. It covers dotted, hyphenated, realistic hyphenated, underscore/collision, and digit-leading library names:

  • foo.bar
  • scalapack-openmpi
  • foo-bar
  • foo_bar
  • 1foo

Validation performed locally:

  • git diff --check
  • spin lint
  • A direct MesonTemplate parser check using mesonbuild.mparser.Parser(...).parse(), which completed with parse-ok and verified that generated dependency declarations preserve the original -l... arguments.

I also attempted the focused pytest command below, but this unbuilt local source checkout stops during NumPy test configuration before selected tests run because the generated numpy.version module is unavailable:

D:\ZXY\Dev\Miniforge3\envs\prw-numpy-py312\python.exe -m pytest numpy/f2py/tests/test_regression.py -q -k "meson_library_names or gh26623"

First time committer introduction

N/A.

AI Disclosure

Codex was used to investigate the failing f2py/Meson code path, draft the small code and regression-test change, run focused local validation, and draft this PR description. The diff and submission were reviewed by a human before opening the PR.

@HaoZeke HaoZeke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for this @VectorPeak.
#26634 only handled dots so scalapack-openmpi wouldn't work.
Separating the meson id from the -l makes sense.

I'd like a regression test to demonstrate the linker still gets -l and then this should be done :)

Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
@VectorPeak
VectorPeak force-pushed the fix-f2py-meson-lib-identifiers branch from b15b0c6 to 17c9b1c Compare July 12, 2026 17:01
Co-authored-by: chatgpt-codex-connector[bot] <199175422+chatgpt-codex-connector[bot]@users.noreply.github.com>
@VectorPeak

Copy link
Copy Markdown
Contributor Author

Thanks @HaoZeke, I updated the regression test to check the generated Meson dependency declarations.

It now includes scalapack-openmpi, parses the generated meson.build, and verifies the original -l<name> link args are preserved while unsafe names are not emitted directly as Meson assignment targets.

@VectorPeak
VectorPeak requested a review from HaoZeke July 12, 2026 17:24

@HaoZeke HaoZeke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @VectorPeak, LGTM, in it goes

@HaoZeke
HaoZeke merged commit 71d523a into numpy:main Jul 12, 2026
87 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

F2PY Meson backend generates invalid identifiers for some -l library names

3 participants