diff --git a/.github/workflows/build-wheels.yml b/.github/workflows/build-wheels.yml index a1e49f4..8e50cac 100644 --- a/.github/workflows/build-wheels.yml +++ b/.github/workflows/build-wheels.yml @@ -12,15 +12,28 @@ jobs: runs-on: ${{ matrix.os }} strategy: matrix: - os: [ubuntu-20.04, macos-latest] + os: [windows-latest, ubuntu-latest, macos-latest] env: FC: gfortran-9 F90: gfortran-9 CC: gcc-9 + defaults: + run: + shell: bash steps: - uses: actions/checkout@v2 + # Only on the Windows runner + - name: Add Windows environment settings + if: startsWith(matrix.os, 'windows') + run: | + echo "C:\msys64\mingw64\bin" >> $GITHUB_PATH + echo "C:\msys64\usr\bin" >> $GITHUB_PATH + echo "FC=gfortran" >> $GITHUB_ENV + echo "F90=gfortran" >> $GITHUB_ENV + echo "CC=gcc" >> $GITHUB_ENV + - uses: actions/setup-python@v2 name: Install Python with: diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 623ce02..d4d09ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,18 +13,32 @@ jobs: build: runs-on: ${{ matrix.os }} + strategy: matrix: - os: [ubuntu-latest, macos-latest] + os: [windows-latest, ubuntu-latest, macos-latest] python-version: [3.7, 3.8, 3.9] env: FC: gfortran-9 F90: gfortran-9 CC: gcc-9 + defaults: + run: + shell: bash steps: - uses: actions/checkout@v2 + # Only on the Windows runner + - name: Add Windows environment settings + if: startsWith(matrix.os, 'windows') + run: | + echo "C:\msys64\mingw64\bin" >> $GITHUB_PATH + echo "C:\msys64\usr\bin" >> $GITHUB_PATH + echo "FC=gfortran" >> $GITHUB_ENV + echo "F90=gfortran" >> $GITHUB_ENV + echo "CC=gcc" >> $GITHUB_ENV + - name: Set up Python ${{ matrix.python-version }} uses: actions/setup-python@v2 with: @@ -39,7 +53,9 @@ jobs: python -m pip install --upgrade pip pip install flake8 pytest pip install -r requirements.txt - pip install . + + - name: Install pymsis + run: pip install -v . - name: Lint with flake8 run: | diff --git a/.github/workflows/download_mirror.py b/.github/workflows/download_mirror.py index a441d9d..cd07079 100644 --- a/.github/workflows/download_mirror.py +++ b/.github/workflows/download_mirror.py @@ -1,4 +1,5 @@ """This is only for CI downloading/testing.""" +import os import tarfile import urllib.request @@ -10,7 +11,7 @@ with urllib.request.urlopen(SOURCE_FILE) as stream: tf = tarfile.open(fileobj=stream, mode="r|gz") - tf.extractall(path='src/msis2/') + tf.extractall(path=os.path.join('src', 'msis2', '')) # MSIS-00 fortran file MSIS00_FILE = ("https://gist.githubusercontent.com/greglucas/" @@ -18,5 +19,5 @@ "raw/2c1f5d899d7b42392a6b19a041d2cc213589a5f1/" "NRLMSISE-00.FOR") with urllib.request.urlopen(MSIS00_FILE) as response: - with open('src/msis00/NRLMSISE-00.FOR', 'wb') as f: + with open(os.path.join('src', 'msis00', 'NRLMSISE-00.FOR'), 'wb') as f: f.write(response.read()) diff --git a/pymsis/__init__.py b/pymsis/__init__.py index d3ec452..9fbf788 100644 --- a/pymsis/__init__.py +++ b/pymsis/__init__.py @@ -1 +1,25 @@ -__version__ = "0.2.0" +import os +__version__ = "0.2.1" + +# If we are on Windows, Python 3.8+ then we need to add a DLL search path +# The libraries are located relative to this init file. +if os.name == 'nt': + pymsis_dir = None + pymsis_dir_libs = None + try: + # add folder to Windows DLL search paths + pymsis_dir = os.path.abspath(os.path.dirname(__file__)) + pymsis_dir_libs = os.path.join(pymsis_dir, '.libs') + try: + # This was added in Python 3.8, so we can default to this + # once we only support 3.8+ + os.add_dll_directory(pymsis_dir) + # Additionally, we need the .libs directory which has gfortran + os.add_dll_directory(pymsis_dir_libs) + except Exception: + pass + os.environ['PATH'] = (f"{pymsis_dir};{pymsis_dir_libs};" + f"{os.environ['PATH']}") + except Exception: + pass + del pymsis_dir, pymsis_dir_libs diff --git a/pymsis/msis.py b/pymsis/msis.py index e21bbd3..78d592f 100644 --- a/pymsis/msis.py +++ b/pymsis/msis.py @@ -215,4 +215,5 @@ def create_input(dates, lons, lats, alts, f107s, f107as, aps): f107s[indices[:, 0]], f107as[indices[:, 0]]], -1) # ap has 7 components, so we need to concatenate it onto the # arrays rather than stack - return shape, np.concatenate([arr, aps[indices[:, 0], :]], axis=1) + return shape, np.concatenate([arr, aps[indices[:, 0], :]], axis=1, + dtype=np.float32) diff --git a/pyproject.toml b/pyproject.toml index 6a1096a..083b425 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -2,7 +2,7 @@ requires = [ "setuptools>=42", "wheel", - "oldest-supported-numpy" + "numpy" ] build-backend = "setuptools.build_meta" diff --git a/setup.py b/setup.py index 674b191..085b86c 100644 --- a/setup.py +++ b/setup.py @@ -26,9 +26,11 @@ # If you want to get some additional speed from compile-time options you can # add extra compile-time flags. e.g., '-march=native', '-ffast-math' +# NOTE: -O1 seems to be required on Windows+Py39 CI systems, so we are setting +# that for everyone for now, but it should be investigated later. ext_msis2 = Extension(name='pymsis.msis2f', sources=msis2_sources, - extra_f90_compile_args=['-std=legacy']) + extra_f90_compile_args=['-std=legacy', '-O1']) msis00_sources = [os.path.join('src', 'msis00', 'msis00.F90'), os.path.join('src', 'msis00', 'NRLMSISE-00.FOR')] @@ -38,7 +40,7 @@ requirements = ['numpy'] -with open("README.rst", "r") as f: +with open("README.rst", "r", encoding='utf8', errors="ignore") as f: long_description = f.read() setup( diff --git a/src/msis2/msis2.F90 b/src/msis2/msis2.F90 index eb0f5f3..fc82854 100644 --- a/src/msis2/msis2.F90 +++ b/src/msis2/msis2.F90 @@ -39,5 +39,4 @@ subroutine pymsiscalc(day, utsec, lon, lat, z, sflux, sfluxavg, ap, output, n) sflux(i), ap(i, :), output(i, 11), output(i, 1:10)) enddo - return end subroutine pymsiscalc