8000 BUG: Handle `--f77flags` and `--f90flags` for `meson` by HaoZeke · Pull Request #26703 · numpy/numpy · GitHub
[go: up one dir, main page]

Skip to content

BUG: Handle --f77flags and --f90flags for meson #26703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 16, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
BUG: Use fortran args from f2py in meson
  • Loading branch information
HaoZeke committed Jun 16, 2024
commit 08a80a5d4be4fe94b7285906e1748950981dd699
31 changes: 30 additions & 1 deletion numpy/f2py/_backends/_meson.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def __init__(
include_dirs: list[Path],
object_files: list[Path],
linker_args: list[str],
c_args: list[str],
fortran_args: list[str],
build_type: str,
python_exe: str,
):
Expand All @@ -46,12 +46,18 @@ def __init__(
self.include_dirs = []
self.substitutions = {}
self.objects = object_files
# Convert args to '' wrapped variant for meson
self.fortran_args = [
f"'{x}'" if not (x.startswith("'") and x.endswith("'")) else x
for x in fortran_args
]
self.pipeline = [
self.initialize_template,
self.sources_substitution,
self.deps_substitution,
self.include_substitution,
self.libraries_substitution,
self.fortran_args_substitution,
]
self.build_type = build_type
self.python_exe = python_exe
Expand Down Expand Up @@ -109,6 +115,14 @@ def include_substitution(self) -> None:
[f"{self.indent}'''{inc}'''," for inc in self.include_dirs]
)

def fortran_args_substitution(self) -> None:
if self.fortran_args:
self.substitutions["fortran_args"] = (
f"{self.indent}fortran_args: [{', '.join([arg for arg in self.fortran_args])}],"
)
else:
self.substitutions["fortran_args"] = ""

def generate_meson_build(self):
for node in self.pipeline:
node()
Expand All @@ -126,6 +140,7 @@ def __init__(self, *args, **kwargs):
self.build_type = (
"debug" if any("debug" in flag for flag in self.fc_flags) else "release"
)
self.fc_flags = _get_flags(self.fc_flags)

def _move_exec_to_root(self, build_dir: Path):
walk_dir = Path(build_dir) / self.meson_build_dir
Expand Down Expand Up @@ -203,3 +218,17 @@ def _prepare_sources(mname, sources, bdir):
if not Path(source).suffix == ".pyf"
]
return extended_sources


def _get_flags(fc_flags):
flag_values = []
flag_pattern = re.compile(r"--f(77|90)flags=(.*)")

for flag in fc_flags:
match_result = flag_pattern.match(flag)
if match_result:
values = match_result.group(2).strip().split()
flag_values.extend(values)
# Hacky way to preserve order of flags
unique_flags = list(dict.fromkeys(flag_values))
return unique_flags
1 change: 1 addition & 0 deletions numpy/f2py/_backends/meson.build.template
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,5 @@ ${dep_list}
${lib_list}
${lib_dir_list}
],
${fortran_args}
install : true)
0