Skip to content

Python package

Python package #247

Workflow file for this run

# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Python package
on: [push, pull_request]
jobs:
Test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ["3.7", "3.8", "3.9", "3.10"]
qt5: [true, false]
gdal: [true, false]
seisunix: [true, false]
exclude:
- os: windows-latest
python-version: "3.7"
- os: macos-latest
qt5: true
- os: macos-latest
seisunix: true
- os: macos-latest
gdal: true
- os: windows-latest
qt5: true
- os: windows-latest
seisunix: true
- os: windows-latest
gdal: true
steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
# testing
python -m pip install flake8 pytest
python -m pip install coverage
python -m pip install mock
# production
python -m pip install wheel
python -m pip install -r requirements.txt
- name: Install optional dependency qt5
if: ${{ matrix.qt5 }}
run: |
sudo apt install -y xvfb x11-utils libxkbcommon-x11-0 libxcb-icccm4 libxcb-image0 libxcb-keysyms1 libxcb-randr0 libxcb-render-util0 libxcb-xinerama0 pyqt5-dev-tools
python -m pip install pyqt5
python -c 'import PyQt5'
- name: Install optional dependency SeisUnix
if: ${{ matrix.seisunix }}
run: bash install_su.sh
- name: Install optional dependency GDAL
if: ${{ matrix.gdal }}
run: |
sudo apt-get install -y libcurl4-gnutls-dev
sudo apt-get install libgdal-dev=3.4.1+dfsg-1build4
export CPLUS_INCLUDE_PATH=/usr/include/gdal
export C_INCLUDE_PATH=/usr/include/gdal
python -m pip install gdal==3.4.1
- name: Install ImpDAR
run: python -m pip install .
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Run tests GUI
if: ${{ matrix.qt5 }}
run: |
xvfb-run `which coverage` run --source impdar --omit=impdar/tests/*,impdar/lib/analysis/* -m pytest
- name: Run tests no GUI
if: ${{ !matrix.qt5 }}
run: |
coverage run --source impdar --omit=impdar/tests/*,impdar/lib/analysis/* -m pytest
- name: Produce xml coverage
run: coverage xml
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
fail_ci_if_error: false # I see no reason to fail over this.
Windows-Build:
needs: Test
runs-on: windows-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10"]
steps:
- uses: actions/checkout@master
- name: Download Build Tools for Visual Studio 2019
run: Invoke-WebRequest -Uri https://aka.ms/vs/16/release/vs_buildtools.exe -OutFile vs_buildtools.exe
- name: Run vs_buildtools.exe install
run: ./vs_buildtools.exe --quiet --wait --norestart --nocache --add Microsoft.VisualStudio.Component.VC.Tools.x86.x64 --add Microsoft.VisualStudio.Component.VC.v141.x86.x64 --add Microsoft.VisualStudio.Component.VC.140 --includeRecommended
- name: Set up Python ${{ matrix.python-version }} x64
uses: actions/setup-python@v1
with:
python-version: ${{ matrix.python-version }}
architecture: x64
- name: Install Python package dependencies
run: pip install cython wheel
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
- name: Build binary wheel
run: python setup.py bdist_wheel
- uses: actions/upload-artifact@v3
with:
name: build-windows-${{ matrix.python-version }}
path: dist
Mac-Build:
runs-on: macos-latest
needs: Test
strategy:
fail-fast: false
matrix:
python-version: ["3.7", "3.8", "3.9", "3.10"]
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
steps:
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- name: Symlink gcc
run: |
ln -s /usr/local/bin/gfortran-9 /usr/local/bin/gfortran
ln -s /usr/local/bin/gcc-9 /usr/local/bin/gcc
continue-on-error: true
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
run: |
python -m pip install --upgrade pip wheel cython
python -m pip install -r requirements.txt
- name: Build binary wheel
run: python setup.py bdist_wheel
- uses: actions/upload-artifact@v3
with:
name: build-macos-${{ matrix.python-version }}
path: dist
# This one is only run when actually needed
Linux-Build:
runs-on: ubuntu-latest
needs: Test
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_API_TOKEN }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Build and deploy manylinux wheels
uses: ./
- uses: actions/upload-artifact@v3
with:
name: build-linux
path: dist
# deploy source distribution
Source-Build:
runs-on: ubuntu-latest
needs: Test
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
- name: create source distribution
run: python setup.py sdist
- uses: actions/upload-artifact@v3
with:
name: build-source
path: dist
Upload-PyPi:
runs-on: ubuntu-latest
needs: [Source-Build, Mac-Build, Windows-Build, Linux-Build]
steps:
- uses: actions/checkout@v4
- uses: actions/download-artifact@v3
- name: Collect packages
run: |
if [ ! -d dist ]; then mkdir dist; fi
for d in build*; do mv -f $d/* dist/; done
- name: Publish distribution 📦 to Test PyPI
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.TEST_PYPI_API_TOKEN }}
repository_url: https://test.pypi.org/legacy/
skip_existing: true
- name: Publish distribution 📦 to PyPI
if: startsWith(github.ref, 'refs/tags')
uses: pypa/gh-action-pypi-publish@master
with:
password: ${{ secrets.PYPI_API_TOKEN }}