Skip to content

Merge pull request #88 from muon-spectroscopy-computational-project/8… #939

Merge pull request #88 from muon-spectroscopy-computational-project/8…

Merge pull request #88 from muon-spectroscopy-computational-project/8… #939

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 tests
on:
# Triggers the workflow on push or pull request events but only for non-docs commits
push:
paths-ignore:
- "docs/**"
- .github/workflows/build-docs.yml
- CITATION.cff
- .github/workflows/citation-cff.yml
- .github/workflows/build.yml
pull_request:
paths-ignore:
- "docs/**"
- .github/workflows/build-docs.yml
- CITATION.cff
- .github/workflows/citation-cff.yml
- .github/workflows/build.yml
jobs:
lint:
name: Lint with flake8 and black
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install wheel
if [ -f requirements-lint.txt ]; then pip install -r requirements-lint.txt; else pip install .[dev]; fi
- name: Lint with flake8
run: flake8 . --count --show-source --statistics
- name: Check formatting with black
run: black --check .
test:
name: Test on Python ${{ matrix.python-version }} and ${{ matrix.os }}
needs: lint # don't run if linting failed
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.10"]
os: [ubuntu-latest, macOS-latest, windows-latest]
steps:
- uses: actions/checkout@v3
- 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
pip install wheel
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
shell: bash # Windows runners have Git Bash installed so this should work on all runners
- name: Install package
run: pip install .
- name: Test with pytest
run: pytest --pyargs muspinsim
test-openmp:
name: Test on Python ${{ matrix.python-version }} and ${{ matrix.os }} with OpenMP
needs: lint # don't run if linting failed
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
python-version: ["3.8", "3.10"]
# macOS-11 pinned here due to usage of $(brew --prefix llvm@15)
# macOS-12 will become macOS-latest in the near future but
# is currently still unstable
os: [ubuntu-latest, macOS-11, windows-latest]
steps:
- uses: actions/checkout@v3
- 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
pip install wheel
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
if [ -f requirements-dev.txt ]; then pip install -r requirements-dev.txt; fi
shell: bash # Windows runners have Git Bash installed so this should work on all runners
# Default compiler on macOS doesn't support OpenMP, so force the usage
# of homebrew's llvm see
# https://github.com/actions/runner-images/blob/main/images/macos/macos-11-Readme.md
# Even when installed, clang++ may not be able to find the OMP library when installed
# To resolve this, export the environment variables suggested by brew to $GITHUB_ENV
- name: Add optional environment variables
run: |
if [ "$RUNNER_OS" == 'macOS' ]; then
echo "CC=$(brew --prefix llvm@15)/bin/clang" >> "$GITHUB_ENV"
echo "CXX=$(brew --prefix llvm@15)/bin/clang++" >> "$GITHUB_ENV"
brew info libomp
echo "LDFLAGS=-L/usr/local/opt/libomp/lib" >> "$GITHUB_ENV"
echo "CPPFLAGS=-I/usr/local/opt/libomp/include" >> "$GITHUB_ENV"
fi
shell: bash
- name: Install package with -e
env:
MUSPINSIM_WITH_OPENMP: 1
if: matrix.python-version == '3.10' && matrix.os == 'ubuntu-latest'
run: pip install -e .
- name: Install package
env:
MUSPINSIM_WITH_OPENMP: 1
if: matrix.python-version != '3.10' || matrix.os != 'ubuntu-latest'
run: pip install .
- name: Test with pytest
run: pytest --cov --cov-report xml --pyargs muspinsim
- name: Upload to Codecov
if: matrix.python-version == '3.10' && matrix.os == 'ubuntu-latest'
uses: codecov/codecov-action@v3