f2py on Windows including AppVeyor CI

Related: AppVeyor Windows/Linux CI templates for Python and Fortran


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.

image:
- Visual Studio 2017
- ubuntu1804

stack: python 3

environment:
  PY_DIR: C:\Python37-x64
  MINGW_DIR: C:\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin

clone_depth: 25

build: off

init:
- 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 -r a -v

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

[build-system]
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'])])