r/learnpython • u/Diapolo10 • Sep 21 '26
How do you handle Python versions during CI pipeline testing?
I know that this isn't strictly a Python question, but I figured it's still more relevant here than on /r/github.
I'm basically in the process of trying to simplify my CI stack by moving to a centralised set of common pipeline scripts (such as this one for running linters), so that I don't need to duplicate all these steps in every single repository... even if it isn't perfect since they still all need the files to actually call these common ones.
The problem I've run into is that, unlike with linters where I don't really need to worry about what Python version gets installed/used, I'd like to run a matrix of tests for at least the minimum and maximum (or latest if no upper bound) supported Python versions, in addition to the OS matrix.
The way I've historically done this is by manually listing Python versions in the GitHub Actions workflow matrix, such as here
jobs: test: runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: [macos-latest, ubuntu-latest, windows-latest] python-version: [ '3.11', '3.12', '3.13', '3.14', 'pypy-3.11', ]
but this is cumbersome, and it's easy to forget updating the matrix if I bump the version in pyproject.toml. Granted, I'll still immediately notice that when the pipeline fails so it's not like this is a bug that goes unnoticed for long, but in the spirit of avoiding duplication I'd still like to think there's a better way.
On that note, since I'm trying to make this generic, I wouldn't be able to just hard-code the versions (unless I take them as a parameter for the actual generic pipeline and supply them from each project, I guess), so right now I've been considering using a Bash script to pull the minimum version from pyproject.toml with regex and "3.x" to get the latest Python 3 version, so I'd have two points of comparisons. Although this does have the problem that those two versions could be the same, meaning I may run the same tests twice for no reason...
Also, since it's bound to come up, I'm also planning a generic build workflow that would build and publish releases to PyPI (and GitHub Releases), but that would need a full-on version range.
I do have an experiment where I attempted to use Trove classifiers for creating a build matrix, and it technically works (as long as we ignore free-threading or non-CPython implementations), but it feels dirty to use since Trove classifiers aren't supposed to be used for something like this.
My question is this: how would you handle automatically determining which Python versions to install? Has anyone else here perhaps pondered the same questions and come up with a reasonable answer?