Add type annotations to code base #1245
Workflow file for this run
This file contains hidden or 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: "CI & CD" | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - "main" | |
| pull_request: | |
| release: | |
| types: | |
| - published | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} | |
| cancel-in-progress: true | |
| env: | |
| CIBW_BUILD: cp312-* cp313-* cp314-* | |
| CIBW_TEST_EXTRAS: test | |
| CIBW_TEST_COMMAND: > | |
| pytest {project} | |
| --durations=50 | |
| --ignore={project}//tests//sequence//align//test_statistics.py | |
| --ignore={project}//tests//application | |
| --ignore={project}//tests//interface | |
| --ignore={project}//tests//database | |
| --ignore={project}//tests//test_doctest.py | |
| --ignore={project}//tests//test_modname.py | |
| CIBW_DEPENDENCY_VERSIONS: "pinned" | |
| # Configuration for the architecture-agnostic jobs | |
| PY_VERSION: "3.12" # Keep in sync with minimum supported version in pyproject.toml | |
| jobs: | |
| lint: | |
| name: Check code style | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: prefix-dev/setup-pixi@v0.9.6 | |
| with: | |
| environments: lint | |
| cache: true | |
| cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }} | |
| - name: Check code style and type annotations | |
| run: pixi run lint | |
| build-internal: | |
| name: Build CCD and wheel for reusing it in several CI jobs | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v4 | |
| with: | |
| # Make sure to fetch the latest tag, | |
| # so 'switcher.py' works correctly in 'docs' job | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PY_VERSION }} | |
| - name: Get current CCD for hashing | |
| run: wget https://files.wwpdb.org/pub/pdb/data/monomers/components.cif.gz | |
| - name: Cache CCD | |
| uses: actions/cache@v4 | |
| id: cache-ccd | |
| with: | |
| path: ./src/biotite/structure/info/components.bcif | |
| key: cache-${{ hashFiles('src/biotite/setup_ccd.py') }}-${{ hashFiles('components.cif.gz') }} | |
| - name: Remove CCD used for hashing | |
| run: rm components.cif.gz | |
| - name: Build internal CCD | |
| if: steps.cache-ccd.outputs.cache-hit != 'true' | |
| run: | | |
| pip install -e . | |
| python -m biotite.setup_ccd | |
| - name: Install build backend | |
| run: pip install build | |
| - name: Build distribution | |
| run: python -m build --wheel | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: internal-build | |
| path: ./dist/*.whl | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: ccd | |
| path: ./src/biotite/structure/info/components.bcif | |
| generate-wheels-matrix: | |
| name: "Generate wheels matrix" | |
| runs-on: "ubuntu-latest" | |
| outputs: | |
| include: ${{ steps.set-matrix.outputs.include }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Install cibuildwheel | |
| # MAKE SURE THIS STAYS IN SYNC WITH THE LOWER GHA cibuildwheel | |
| run: pipx install cibuildwheel==3.3.0 | |
| - id: set-matrix | |
| run: | | |
| MATRIX=$( | |
| { | |
| cibuildwheel --print-build-identifiers --platform linux --archs x86_64 \ | |
| | jq -nRc '{"dist": inputs, "os": "ubuntu-latest"}' \ | |
| && cibuildwheel --print-build-identifiers --platform linux --archs aarch64 \ | |
| | jq -nRc '{"dist": inputs, "os": "ubuntu-24.04-arm"}' \ | |
| && cibuildwheel --print-build-identifiers --platform macos \ | |
| | jq -nRc '{"dist": inputs, "os": "macos-latest"}' \ | |
| && cibuildwheel --print-build-identifiers --platform windows \ | |
| | jq -nRc '{"dist": inputs, "os": "windows-latest"}' | |
| } | jq -sc | |
| ) | |
| echo "include=$MATRIX" | tee -a $GITHUB_OUTPUT | |
| env: | |
| CIBW_ARCHS_LINUX: "x86_64 aarch64" | |
| CIBW_ARCHS_MACOS: "arm64" | |
| CIBW_ARCHS_WINDOWS: "x86 AMD64" | |
| # Skip musllinux because it takes too long to compile on GHA | |
| # since it is emulated. (6+ hours) | |
| # *note* most of the build time is actually numpy for musllinux | |
| CIBW_SKIP: "*musllinux* *-manylinux_i686 *-musllinux_i686 *-win32 pp*" | |
| test-and-build: | |
| name: "Build & Test" | |
| needs: | |
| - generate-wheels-matrix | |
| - build-internal | |
| strategy: | |
| matrix: | |
| include: ${{ fromJson(needs.generate-wheels-matrix.outputs.include) }} | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Add internal CCD to Biotite | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: ccd | |
| path: src/biotite/structure/info | |
| # QEMU enables building/testing for non-native architectures (ie arm64) | |
| # at the cost of speed | |
| - name: Set up QEMU | |
| if: runner.os == 'Linux' | |
| uses: docker/setup-qemu-action@v3 | |
| with: | |
| platforms: all | |
| - name: Build & (optionally) test wheels | |
| # MAKE SURE THIS STAYS IN SYNC WITH THE UPPER pipx call to cibuildwheel | |
| uses: pypa/cibuildwheel@v3.3.0 | |
| with: | |
| only: ${{ matrix.dist }} | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: release-${{ matrix.dist }} | |
| path: ./wheelhouse/*.whl | |
| sdist: | |
| name: Build source distribution | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build-internal | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - name: Add internal CCD to Biotite | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: ccd | |
| path: src/biotite/structure/info | |
| - name: Build source distribution | |
| run: pipx run build --sdist | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: release-sdist | |
| path: dist//*.tar.gz | |
| test-interfaces: | |
| name: Test interfaces to databases and applications | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build-internal | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: internal-build | |
| path: dist | |
| - uses: prefix-dev/setup-pixi@v0.9.6 | |
| with: | |
| environments: default | |
| cache: true | |
| cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }} | |
| - name: Install pre-built wheel into the pixi environment | |
| # `--no-deps` because conda already provides all runtime dependencies | |
| run: pixi run python -m pip install --no-deps ./dist/*.whl | |
| - name: Run tests | |
| # Running NCBI BLAST and SRA takes too long | |
| # The tests on the NCBI Entrez database are not reliable enough | |
| run: > | |
| pixi run pytest | |
| --durations=50 | |
| --ignore="tests//application//test_blast.py" | |
| --ignore="tests//application//test_sra.py" | |
| --ignore="tests//database//test_entrez.py" | |
| tests//test_doctest.py | |
| tests//test_typing.py | |
| tests//test_modname.py | |
| tests//database | |
| tests//application | |
| tests//interface | |
| test-muscle5: | |
| name: Test interface to Muscle 5 | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build-internal | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: internal-build | |
| path: dist | |
| - uses: prefix-dev/setup-pixi@v0.9.6 | |
| with: | |
| environments: muscle5 | |
| cache: true | |
| cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }} | |
| - name: Install pre-built wheel into the pixi environment | |
| run: pixi run -e muscle5 python -m pip install --no-deps ./dist/*.whl | |
| - name: Test Muscle 5 interface | |
| run: pixi run -e muscle5 pytest --durations=50 tests//application//test_msa.py | |
| docs: | |
| name: Build documentation | |
| runs-on: ubuntu-latest | |
| needs: | |
| - build-internal | |
| env: | |
| NCBI_API_KEY: ${{ secrets.NCBI_API_KEY }} | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: internal-build | |
| path: dist | |
| - uses: prefix-dev/setup-pixi@v0.9.6 | |
| with: | |
| environments: doc | |
| cache: true | |
| cache-write: ${{ github.event_name == 'push' && github.ref_name == 'main' }} | |
| - name: Restore cached partially build docs from a failed previous build | |
| id: cache-docs-restore | |
| uses: actions/cache/restore@v4 | |
| with: | |
| key: docs-${{ github.sha }} | |
| path: | | |
| doc/examples/backreferences | |
| doc/examples/gallery | |
| build/doc | |
| build/jupyter_execute | |
| - name: Install pre-built wheel into the pixi environment | |
| run: pixi run -e doc python -m pip install --no-deps ./dist/*.whl | |
| - name: Build base documentation | |
| run: pixi run doc | |
| - name: Build tutorial and gallery | |
| if: > | |
| ( | |
| github.event_name == 'release' && | |
| github.event.action == 'published' | |
| ) | |
| || github.event_name == 'workflow_dispatch' | |
| run: pixi run doc-full | |
| - name: Cache partially built docs from failed build | |
| id: cache-docs-save | |
| if: failure() | |
| uses: actions/cache/save@v4 | |
| with: | |
| key: ${{ steps.cache-docs-restore.outputs.cache-primary-key }} | |
| path: | | |
| doc/examples/backreferences | |
| doc/examples/gallery | |
| build/doc | |
| build/jupyter_execute | |
| - name: Zip documentation | |
| run: | | |
| cd build | |
| zip -r ../dist/doc.zip doc | |
| cd .. | |
| - uses: actions/upload-artifact@v4 | |
| with: | |
| name: documentation | |
| path: dist/doc.zip | |
| benchmark: | |
| name: Run benchmarks | |
| runs-on: ubuntu-latest | |
| if: github.event_name != 'release' | |
| needs: | |
| - build-internal | |
| steps: | |
| - uses: actions/checkout@v4 | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: internal-build | |
| path: dist | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: ${{ env.PY_VERSION }} | |
| - name: Install dependencies | |
| run: pip install dist//*.whl pytest pytest-codspeed | |
| - name: Run benchmarks | |
| uses: CodSpeedHQ/action@v3 | |
| with: | |
| run: pytest --codspeed benchmarks | |
| upload-package: | |
| name: Upload package to GitHub Releases & PyPI | |
| permissions: | |
| contents: write | |
| id-token: write | |
| needs: | |
| - lint | |
| - test-and-build | |
| - sdist | |
| - test-interfaces | |
| - test-muscle5 | |
| - docs | |
| runs-on: ubuntu-latest | |
| environment: | |
| name: publish | |
| url: https://pypi.org/p/biotite | |
| steps: | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| pattern: release-* | |
| merge-multiple: true | |
| path: dist | |
| - name: List distributions to be uploaded | |
| run: ls dist | |
| - name: Upload to GitHub Releases | |
| uses: softprops/action-gh-release@v2.0.5 | |
| if: github.event_name == 'release' && github.event.action == 'published' | |
| with: | |
| files: dist//* | |
| - name: Upload to PyPI | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| if: github.event_name == 'release' && github.event.action == 'published' | |
| upload-ccd: | |
| name: Upload CCD to GitHub Releases | |
| permissions: | |
| contents: write | |
| needs: | |
| - build-internal | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: ccd | |
| path: dist | |
| - name: Upload to GitHub Releases | |
| uses: softprops/action-gh-release@v2.0.5 | |
| if: github.event_name == 'release' && github.event.action == 'published' | |
| with: | |
| files: dist//components.bcif | |
| upload-docs: | |
| name: Upload documentation to GitHub Releases and documentation website | |
| if: github.event_name == 'release' && github.event.action == 'published' | |
| permissions: | |
| contents: write | |
| needs: | |
| - lint | |
| - test-and-build | |
| - sdist | |
| - test-interfaces | |
| - test-muscle5 | |
| - docs | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Install dependencies for documentation upload | |
| run: pip install requests | |
| - uses: actions/checkout@v4 | |
| - uses: actions/download-artifact@v4 | |
| with: | |
| name: documentation | |
| path: dist | |
| - uses: softprops/action-gh-release@v2.0.5 | |
| with: | |
| files: dist/doc.zip | |
| - name: Unzip documentation | |
| run: unzip dist/doc.zip -d build | |
| - name: Assemble multi-version documentation | |
| run: > | |
| python .github/workflows/multiversion_docs.py | |
| build/doc/_static/switcher.json | |
| dist/assembled_doc | |
| - name: Upload documentation to website (skip for patch releases) | |
| if: endsWith(github.event.release.tag_name, 0) | |
| uses: easingthemes/ssh-deploy@v5.1.0 | |
| with: | |
| SSH_PRIVATE_KEY: ${{ secrets.DOC_PRIVATE_KEY }} | |
| REMOTE_HOST: ${{ secrets.DOC_HOST }} | |
| REMOTE_USER: ${{ secrets.DOC_USER }} | |
| SOURCE: "dist/assembled_doc/*" | |
| TARGET: "biotite" | |
| SCRIPT_BEFORE: "rm -r biotite/*" |