f2py on Windows including AppVeyor CI

Importing Fortran libraries from Python is accomplished via f2py. CIs such as AppVeyor work with f2py as in this example .appveyor.yml:

- Visual Studio
- ubuntu

stack: python 3

  PY_DIR: C:/Python310-x64
  MINGW_DIR: C:/msys64/mingw64/bin

clone_depth: 25

build: off

- cmd: set PATH=%PY_DIR%;%PY_DIR%\Scripts;%PATH%
- cmd: set PATH=%MINGW_DIR%;%PATH%
- ps: if ($isWindows) {echo "[build]`ncompiler=mingw32" | Out-File -Encoding ASCII ~/pydistutils.cfg}

install: pip install -e .[tests]

test_script: pytest

This pyproject.toml ensures Numpy is installed before attempting to build the Fortran extension module:

requires = ["setuptools", "numpy"]

NOTE: “setup.py” must import setuptools, even though it isn’t directly used here, to enable developer mode via pip install -e .

import setuptools  # noqa: F401
from numpy.distutils.core import setup, Extension

setup(ext_modules=[Extension(name='mymod', sources=['mylib.f90'])])

Related: AppVeyor CI templates for Python and Fortran