Replace IPython notebook with examples #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Test and Publish | |
on: | |
push: | |
pull_request: | |
workflow_dispatch: | |
schedule: # Run tests once a week to detect regressions | |
- cron: '0 0 * * 1' | |
jobs: | |
# ------------------------------------------------------------ | |
# Run unit tests, linter, and other static checks. | |
# ------------------------------------------------------------ | |
test: | |
runs-on: ubuntu-latest | |
strategy: | |
fail-fast: false | |
matrix: | |
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12", "3.13", "pypy-3.10"] | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
cache: "pip" | |
allow-prereleases: true | |
- name: Install dependencies | |
run: | | |
pip install .[test] | |
- name: Run flake8 | |
run: | | |
# Ignore existing issues, but we should eventually fix these... | |
# E302 - Expected 2 blank lines, found N | |
# E305 - Expected 2 blank lines after class or function definition, found N | |
# E501 - Line too long (N > 79 characters) | |
# E741 - Do not use variables named 'I', 'O', or 'l' | |
# F401 - Module imported but unused | |
flake8 --extend-ignore=E302,E305,E501,E741 --per-file-ignores="__init__.py:F401" \ | |
platypus/ examples/ example.py | |
- name: Run tests | |
run: | | |
python -m pytest -rA -Werror | |
# ------------------------------------------------------------ | |
# Run all examples (targeting minimum Python version). | |
# ------------------------------------------------------------ | |
examples: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v4 | |
- name: Get minimum Python version | |
run: | | |
PYTHON_VERSION=$(cat pyproject.toml | grep "requires-python" | grep -Eo "[0-9]+\.[0-9]+") | |
echo "PYTHON_VERSION=${PYTHON_VERSION}" >> $GITHUB_ENV | |
- name: Set up Python ${{ env.PYTHON_VERSION }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
cache: "pip" | |
- name: Install dependencies | |
run: | | |
sudo apt update | |
sudo DEBIAN_FRONTEND=noninteractive apt-get -y install mpi mpich libmpich-dev libopenmpi-dev | |
pip install .[full] | |
- name: Run examples | |
run: | | |
find examples/ -name '*.py' -not -name '*mpi*' | \ | |
xargs -I {} sh -c "echo '{}:' && python '{}' && echo ''" | |
- name: Run MPI examples | |
run: | | |
lamboot | |
find examples/ -name '*.py' -name '*mpi*' | \ | |
xargs -I {} sh -c "echo '{}:' && mpirun -np 2 --oversubscribe python '{}' && echo ''" | |
lamhalt | |
# ------------------------------------------------------------ | |
# Build the distribution and publish (on release tag). | |
# ------------------------------------------------------------ | |
publish: | |
runs-on: ubuntu-latest | |
needs: [test, examples] | |
steps: | |
- name: Checkout source | |
uses: actions/checkout@v4 | |
- name: Get minimum Python version | |
run: | | |
PYTHON_VERSION=$(cat pyproject.toml | grep "requires-python" | grep -Eo "[0-9]+\.[0-9]+") | |
echo "PYTHON_VERSION=${PYTHON_VERSION}" >> $GITHUB_ENV | |
- name: Set up Python ${{ env.PYTHON_VERSION }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ env.PYTHON_VERSION }} | |
cache: "pip" | |
- name: Install build dependencies | |
run: | | |
pip install --upgrade pip | |
pip install --upgrade build wheel setuptools | |
- name: Build distributions | |
shell: bash -l {0} | |
run: python -m build | |
- name: Publish package | |
if: github.repository == 'Project-Platypus/Platypus' && github.event_name == 'push' && startsWith(github.ref, 'refs/tags') | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
password: ${{ secrets.PYPI_API_TOKEN }} |