Skip to content

Commit

Permalink
Use meson to build stripy (#109)
Browse files Browse the repository at this point in the history
* first attempt at a meson build

* added all fortran modules to meson.build

* update pyproject.toml with meson build-backend

* link fortranobject.c to build f sources

* missing tag - probably does nothing

* meson default is to install sources as a module (not submodule)

* make pyproject.toml a bit more verbose

* getting closer using subdir

* don't want f2py to generate module files since these are already generated in the .pyf headers

* no _ssrfpack_f2pywrappers.f

* build PYPI wheels using meson

* build with python 3.12

* update CI

* update manylinux build

* try getting libquadmath as a dependency

* try installing using a fortran environment on windows

* increment gcc to version 12

* ooops - typo

* try again...

* try another test using micromamba

* try now

* try now..

* remove micromamba - more trouble than its worth

* maybe gfortran v11 will fix windows?

* try intel compiler

* update windows fortran

* wheelhouse actions

* project requires meson instead of meson-python

* revert to mesonpy

* update wheelhouse platforms

* update wheelhouse to use fortran and mesa images

* meson build

* add python dependencies

* add python meson dependency

* try initialising pip install from cibuildwheel env

* update pip index-url

* try setting up a build machine with ninja

* move build env to another yaml

* move build env to a separate directory

* typo

* restrict to python 3.7 or greater

* run pytest

* run pytest in correct folder

* not working on windows...

* install ninja

* remove ninja installation on linux

* try restricting to 64-bit builds

* -lquadmath

* replace pkg_resources with importlib.resources

* do not build pypy wheels

* restrict env variable to windows

* install gcc on mac

* maybe these platform specific arguments are no good

* revert platform in meson.build

* revert -lquadmath in meson.build

* try reinstalling gcc on mac

* remove scipy dependency

* upload to PYPI on release

* just test on ubuntu with different python versions

---------

Co-authored-by: Ben Mather <[email protected]>
  • Loading branch information
brmather and Ben Mather authored Dec 5, 2023
1 parent 8daf676 commit 93d92df
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 312 deletions.
299 changes: 2 additions & 297 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CI
name: Run tests

on:
push:
Expand All @@ -11,7 +11,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v2
Expand All @@ -37,298 +37,3 @@ jobs:
run: |
pip install pytest
pytest -v
test_macos:
runs-on: macos-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v2
- uses: awvwgk/setup-fortran@main
id: setup-fortran
with:
compiler: gcc
version: 11

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
pip install numpy
pip install scipy
pip install Cython
# - name: Provide gfortran
# run: |
# ln -s /usr/local/bin/gfortran-10 /usr/local/bin/gfortran

- name: Install
run: |
pip install .
- name: Run tests
run: |
pip install pytest
pytest -v
test_windows:
runs-on: windows-latest
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
pip install numpy
pip install scipy
pip install Cython
- name: Install
run: |
pip install .
- name: Run tests
run: |
pip install pytest
pytest -v
conda_build_ubuntu:
name: Conda Build (Python ${{matrix.python-version}})
needs: [test_ubuntu]
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}

- name: Config Conda
shell: bash -l {0}
run: |
conda install --channel conda-forge conda-build anaconda-client conda-verify
conda config --add channels conda-forge
conda config --add channels underworldcode
conda config --set anaconda_upload no
- name: Config Conda For Upload
if: github.event_name == 'release'
shell: bash -l {0}
run: conda config --set anaconda_upload yes

- name: Upload new Packages
if: github.event_name == 'release'
shell: bash -l {0}
run: |
anaconda login --hostname github-actions-${{ matrix.os }}-$RANDOM --username ${{ secrets.ANACONDA_USERNAME }} --password ${{ secrets.ANACONDA_PASSWORD }}
conda-build --channel conda-forge --user geo-down-under conda
anaconda logout
conda_build_macos:
name: Conda Build (Python ${{matrix.python-version}})
needs: [test_macos]
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}

- name: Config Conda
shell: bash -l {0}
run: |
conda install --channel conda-forge conda-build anaconda-client conda-verify
conda config --add channels conda-forge
conda config --add channels underworldcode
conda config --set anaconda_upload no
- name: Config Conda For Upload
if: github.event_name == 'release'
shell: bash -l {0}
run: conda config --set anaconda_upload yes

- name: Upload new Packages
if: github.event_name == 'release'
shell: bash -l {0}
run: |
anaconda login --hostname github-actions-${{ matrix.os }}-$RANDOM --username ${{ secrets.ANACONDA_USERNAME }} --password ${{ secrets.ANACONDA_PASSWORD }}
conda-build --channel conda-forge --user geo-down-under conda
anaconda logout
conda_build_windows:
name: Conda Build (Python ${{matrix.python-version}} ${{ matrix.os }})
needs: [test_windows]
runs-on: windows-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]
steps:
- uses: actions/checkout@v2
- uses: conda-incubator/setup-miniconda@v2
with:
auto-update-conda: true
python-version: ${{ matrix.python-version }}

- name: Config Conda
shell: bash -l {0}
run: |
conda install --channel conda-forge conda-build anaconda-client conda-verify
conda config --add channels conda-forge
conda config --add channels underworldcode
conda config --set anaconda_upload no
- name: Config Conda For Upload
if: github.event_name == 'release'
shell: bash -l {0}
run: conda config --set anaconda_upload yes

- name: Upload new Packages
if: github.event_name == 'release'
shell: bash -l {0}
run: |
anaconda login --hostname github-actions-${{ matrix.os }}-$RANDOM --username ${{ secrets.ANACONDA_USERNAME }} --password ${{ secrets.ANACONDA_PASSWORD }}
conda-build --channel conda-forge --user geo-down-under conda
anaconda logout
pypi_windows:
runs-on: windows_latest
needs: test_windows
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v2

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
pip install numpy
pip install scipy
pip install Cython
- name: Provide gfortran
run: |
ln -s /usr/local/bin/gfortran-10 /usr/local/bin/gfortran
- name: Package for Pypi
run: |
python setup.py sdist bdist_wheel
- name: Upload to Pypi
run: |
python -m twine upload dist/* -r pypi --skip-existing
pypi_macos:
runs-on: macos-latest
needs: test_macos
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
strategy:
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10", "3.11"]

steps:
- uses: actions/checkout@v2
- uses: awvwgk/setup-fortran@main
id: setup-fortran
with:
compiler: gcc
version: 11

- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools wheel twine
pip install numpy
pip install scipy
pip install Cython
# - name: Provide gfortran
# run: |
# ln -s /usr/local/bin/gfortran-10 /usr/local/bin/gfortran

- name: Package for Pypi
run: |
python setup.py sdist bdist_wheel
- name: Upload to Pypi
run: |
python -m twine upload dist/* -r pypi --skip-existing
manylinux:
name: Build manylinux package
needs: test_ubuntu
runs-on: ubuntu-latest
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install setuptools twine wheel
pip install numpy
pip install scipy
pip install Cython
- name: Build manylinux Python wheels
uses: RalfG/[email protected]_x86_64
with:
python-versions: 'cp36-cp36m cp37-cp37m cp38-cp38 cp39-cp39 cp310-cp310 cp311-cp311'
pip-wheel-args: '--no-deps'
build-requirements: 'cython numpy'
- name: Publish wheels to PyPI
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_TOKEN }}
run: |
twine upload *-manylinux*.whl --skip-existing
77 changes: 77 additions & 0 deletions .github/workflows/pypi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
name: Build wheels

on: [push]

jobs:
build_wheels:
name: Build wheels on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]

steps:
- uses: actions/checkout@v3
- uses: actions/setup-python@v4
with:
python-version: 3.x

- name: Build wheels
uses: pypa/[email protected]
env:
# Disable building PyPy wheels on all platforms
CIBW_SKIP: 'pp*'
CIBW_ENVIRONMENT_WINDOWS: "CFLAGS='-lquadmath'"
CIBW_PROJECT_REQUIRES_PYTHON: ">=3.7"
CIBW_ARCHS: 'auto64'
CIBW_BEFORE_BUILD_WINDOWS: "choco install ninja"
CIBW_BEFORE_BUILD_MACOS: "brew install ninja gcc && brew reinstall gcc"
# CIBW_BEFORE_BUILD_LINUX: "apt-get install -y ninja-build"
CIBW_BEFORE_BUILD: "pip install numpy meson-python ninja setuptools build"
CIBW_TEST_REQUIRES: pytest
CIBW_TEST_COMMAND: "pytest {project}/stripy/tests"
# ...
# with:
# package-dir: .
# output-dir: wheelhouse
# config-file: "{package}/pyproject.toml"

- uses: actions/upload-artifact@v3
with:
path: ./wheelhouse/*.whl

build_sdist:
name: Build source distribution
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Build sdist
run: pipx run build --sdist

- uses: actions/upload-artifact@v3
with:
path: dist/*.tar.gz

upload_pypi:
needs: [build_wheels, build_sdist]
runs-on: ubuntu-latest
environment: pypi
permissions:
id-token: write
if: github.event_name == 'release' && github.event.action == 'published'
# or, alternatively, upload to PyPI on every tag starting with 'v' (remove on: release above to use this)
# if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v')
steps:
- uses: actions/download-artifact@v3
with:
# unpacks default artifact into dist/
# if `name: artifact` is omitted, the action will create extra parent dir
name: artifact
path: dist

- uses: pypa/gh-action-pypi-publish@release/v1
with:
user: __token__
password: ${{ secrets.PYPI_TOKEN }}
# To test: repository-url: https://test.pypi.org/legacy/
Loading

0 comments on commit 93d92df

Please sign in to comment.