Spider tn #240
Workflow file for this run
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: Build, lint and test package | |
on: | |
push: | |
branches: | |
- 'main' | |
- 'beta' | |
- 'release' | |
pull_request: | |
workflow_dispatch: | |
env: | |
SRC_DIR: lambeq | |
TEST_DIR: tests | |
jobs: | |
lint: | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: [ "3.10", "3.11", "3.12" ] | |
outputs: | |
error-check: ${{ steps.error-check.conclusion }} | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install linter | |
run: python -m pip install flake8 flake8-broken-line flake8-bugbear flake8-copyright flake8-import-order flake8-quotes | |
- name: Check for errors | |
id: error-check | |
run: | |
# stop the build if there are Python syntax errors or undefined names | |
flake8 ${{ env.SRC_DIR }} --count --isolated --select=E9,F63,F7,F82 --show-source --statistics | |
- name: Lint with flake8 | |
run: | |
# max-doc-length should be 72 but the copyright notice is too wide for that, so we only error on >74 characters | |
flake8 ${{ env.SRC_DIR }} --max-doc-length=74 | |
- name: Check doc line lengths and complexity | |
run: | |
# exit-zero treats all errors as warnings | |
flake8 ${{ env.SRC_DIR }} --count --exit-zero --isolated --max-complexity=10 --max-doc-length=72 --select=C901,W505 --statistics | |
build_and_test: | |
needs: lint | |
if: ${{ always() && needs.lint.outputs.error-check == 'success' }} | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: [ "3.10", "3.11", "3.12" ] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install base package | |
run: pip install . | |
- name: Check package import works | |
run: python -c 'import lambeq' | |
- name: Install downgraded Qiskit (for compatibility reasons) | |
# This should be removed once the following PR is merged: | |
# https://github.com/PennyLaneAI/pennylane-qiskit/pull/493 | |
run: pip install 'qiskit<1' pytket-qiskit qiskit-ibm-runtime | |
- name: Install extra dependencies and tester | |
run: pip install .[extras] .[test] | |
- name: Locate bobcat pre-trained model cache | |
id: loc-bobcat-cache | |
run: echo "dir=$(python -c 'from lambeq.text2diagram.model_downloader import ModelDownloader; print(ModelDownloader("bert").model_dir)')" >> $GITHUB_OUTPUT | |
- name: Restore bobcat pre-trained model from cache | |
id: bobcat-cache | |
uses: actions/cache@v2 | |
with: | |
path: ${{ steps.loc-bobcat-cache.outputs.dir }} | |
key: bobcat-bert-v1 | |
- name: Test with pytest | |
run: > | |
coverage run --source=${{ env.SRC_DIR }} | |
--module pytest ${{ env.SRC_DIR }} ${{ env.TEST_DIR }} | |
--doctest-modules | |
--durations=50 | |
--ignore=${{ env.TEST_DIR }}/text2diagram/test_depccg_parser.py | |
- name: Coverage report | |
run: coverage report -m | |
type_check: | |
needs: lint | |
if: ${{ always() && needs.lint.outputs.error-check == 'success' }} | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
python-version: [ "3.10", "3.11", "3.12" ] | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Setup Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v4 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies with type hints | |
run: python -m pip install numpy pytket spacy torch types-PyYAML types-Pillow ipython | |
- name: Install type checker | |
run: python -m pip install mypy | |
- name: Type check with mypy | |
run: mypy ${{ env.SRC_DIR }} | |
- name: View strict type errors | |
continue-on-error: true # this is expected to fail but the job should still succeed | |
run: mypy --strict ${{ env.SRC_DIR }} |