f2py on Windows including AppVeyor CI

Importing Fortran libraries from Python is easy and highly effective. We write modern Fortran code from scratch explicitly for the purpose of importing into Python. Here is an example .appveyor.yml script useful for CI with f2py.

- Visual Studio 2019
- ubuntu

stack: python 3

  PY_DIR: C:/Python38-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"]

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'])])

AppVeyor Windows/Linux CI templates for Python and Fortran