Skip to content

BUG: f2py --include-paths does not respect os.pathsep on Windows #31933

Description

@VectorPeak

Describe the issue:

f2py --include-paths is documented as a path-list option that should use the platform path separator (os.pathsep): : on POSIX and ; on Windows. However, the current parser always splits the option value on : in CombineIncludePaths.

That breaks normal Windows drive-letter paths because C:\... contains : as part of the path itself. This can affect both a single Windows include directory and native Windows path lists.

Affected code:

# numpy/f2py/f2py2e.py
if option_string in {"--include-paths", "--include_paths"}:
    include_paths_set.update(values.split(':'))
else:
    include_paths_set.add(values)

A single Windows path is split incorrectly:

--include-paths C:\fortran\include
=> ['C', '\\fortran\\include']

A Windows path list is also split incorrectly:

--include-paths C:\fortran\include;D:\vendor\include
=> ['C', '\\fortran\\include;D', '\\vendor\\include']

The expected behavior is to split --include-paths with os.pathsep, while leaving -I <path> as a single include-directory option.

Reproduce the code example:

import os

single_path = r"C:\fortran\include"
path_list = r"C:\fortran\include;D:\vendor\include"

print("os.name", os.name)
print("os.pathsep", repr(os.pathsep))

print("current single path split", single_path.split(':'))
print("expected single path split", single_path.split(os.pathsep))

print("current path-list split", path_list.split(':'))
print("expected path-list split", path_list.split(os.pathsep))

On Windows, this demonstrates the parser-level issue:

os.name nt
os.pathsep ';'
current single path split ['C', '\\fortran\\include']
expected single path split ['C:\\fortran\\include']
current path-list split ['C', '\\fortran\\include;D', '\\vendor\\include']
expected path-list split ['C:\\fortran\\include', 'D:\\vendor\\include']

Error message:

There is no direct Python traceback. The parsed include path list is wrong before F2PY passes it downstream.

The parsed include directories can then be consumed by:

f2py CLI
  -> f2py_parser()
  -> CombineIncludePaths.__call__()
  -> get_newer_options()
  -> include_paths / include_dirs

and then by either Fortran include-file lookup:

run_main(...)
  -> scaninputline(...)
  -> crackfortran.include_paths
  -> Fortran INCLUDE file lookup

or by the compile backend path:

run_compile(...)
  -> get_newer_options(...)
  -> build_backend(..., include_dirs, ...)
  -> MesonBackend
  -> meson.build include directories

Python and NumPy Versions:

This was checked against the current main branch source checkout:

NumPy source commit: f5f68cc3d25daf05402eed5aaa58459c56b3ac2b
Python used for the local parser demonstration: 3.14.5
Platform: Windows (`os.name == 'nt'`, `os.pathsep == ';'`)

Runtime Environment:

This is a CLI argument parsing issue in numpy/f2py/f2py2e.py, so it can be reproduced without importing a built NumPy package or running compiled code.

How does this issue affect you or how did you find it:

This affects F2PY users and build integrations that pass include directories through the documented --include-paths option on Windows. Even a single drive-letter path such as C:\fortran\include is split incorrectly by the current hard-coded : separator.

The workaround is to use repeated -I <path> options, which are handled as single paths and do not go through the path-list split. However, --include-paths is documented as the path-list option, so it should follow the platform os.pathsep semantics.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions