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.

Note: the pyproject.toml below is also required.

- Visual Studio 2017
- ubuntu1804

stack: python 3

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

clone_depth: 3

build: off

- cmd: set PATH=%PY_DIR%;%PY_DIR%\Scripts;%PATH%
- cmd: set PATH=%MINGW_DIR%;%PATH%

- pip install -e .[tests]

test_script: pytest -rsv

Why do we first pip install? To ensure Numpy is installed before building with pyproject.toml:

requires = ["setuptools", "wheel", "numpy"]

setup.py must include:

from pathlib import Path
import os

if os.name == 'nt':
    sfn = Path(__file__).parent / 'setup.cfg'
    stxt = sfn.read_text()
    if '[build_ext]' not in stxt:
        with sfn.open('a') as f:
            f.write("[build_ext]\ncompiler = mingw32")

this says that if the system is Windows, specify MinGW compiler without requiring root.