9. Continuous Integration¶
Continuous Integration is everything you need to do as a serious software developer. Namely,
have your code on GitHub (or other code hosting services), shared with your collaborators and managed through pull requests and branches
tests suite that you run automatically on your code changes
documentation on ReadTheDocs automatically generated from your code, and automatically updated
pypi package automatically updated with your new code, including version number, and pre-compiled binaries (wheels)
Slack or Discord servers for communication with your collaborators and community
These practices are sometimes referred to as being parts of DevOps or Continuous Delivery practices. We do not make the distinction here.
9.1. Webhooks¶
Webhooks allow you to trigger actions on remote services when certain events happen on your repository.
This allows you to automate updates: - on Slack or Discord servers - automatically update your ReadTheDocs pages
9.2. GitHub Actions¶
GitHub Actions allow you (amongst many other things) to automate your test suite and PyPI package updates. GitHub actions are defined via yaml files in your repository.
See an example here for the PyPI part. You can follow the actions on the GitHub website (see, here for an example).
Here’s a workflow file for running pytest tests on a package after it’s installed from PyPI, triggered manually:
name: Test PyPi Package
on:
workflow_dispatch:
jobs:
test_package:
runs-on: ubuntu-latest
steps:
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: "3.x"
- name: Install package from PyPI
run: |
pip install --upgrade pip
pip install your-package-name # Replace with your actual package name
- name: Run pytest
run: |
pytest tests/*
In this workflow: - The job is triggered manually with workflow_dispatch. - The package is installed directly from PyPI. - pytest is run on the tests located in the tests directory.
For more CI/CD examples, on the test suite, you are encouraged to familiarise yourself with code coverage, for instance with codecov.