ci: install tox from a hash-pinned requirements file#293
Merged
Conversation
`pip install tox` was unpinned, which OpenSSF Scorecard flags as PinnedDependenciesID (alert #41). A single hash-pinned file cannot serve the whole 3.9-3.13 matrix: from Python 3.10 on, virtualenv requires `filelock >= 3.24.2`, and no filelock that new supports 3.9, so `pip install --require-hashes` fails on one end or the other. tox is therefore installed under a fixed Python 3.13 and pointed at the matrix interpreter with `--discover`, using the absolute path that `actions/setup-python` reports. The test envs still run under the matrix Python. `--discover` is used instead of relying on PATH order because actions/setup-python does not document that an earlier version stays reachable as `pythonX.Y` once a later one is set up. Also quotes the tox factor subshell, silencing a pre-existing shellcheck SC2046 warning. Verified in a Fedora 44 container: tox 4.56.4 running under Python 3.13 builds and runs a py39 env with Python 3.9.25 when that interpreter is off PATH and passed via `--discover`; without it, tox fails with "could not find python interpreter matching any of the specs py39".
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves the
PinnedDependenciesIDScorecard alert (#41):pip install toxwas unpinned.Why this is not just a requirements file
A single hash-pinned file cannot serve the whole 3.9-3.13 matrix. From Python 3.10 on,
virtualenvrequiresfilelock >= 3.24.2, and nofilelockthat new supports 3.9. Compiling on 3.9 pinsfilelock==3.19.1, and installing that with--require-hashesunder 3.12 fails:So tox is installed under a fixed Python 3.13 and pointed at the matrix interpreter with
--discover. The test envs still run under the matrix Python; only the tox process itself moves. That is what tox is designed for.--discovertakes the absolute path fromactions/setup-pythonspython-pathoutput rather than relying on PATH order, because the action documents only that "the last specified version will be used as a default one" - it does not promise that an earlier version stays reachable aspythonX.Y.Verification
In a Fedora 44 container with Python 3.13.14 and 3.9.25, tox 4.56.4 installed under 3.13:
python3.9moved off PATH and no--discover:py39-ansible215: failed with could not find python interpreter matching any of the specs py39--discover /opt/py39: env builds andsys.version_inforeports3.9,congratulations :)pip install --require-hashes -r .github/tox/requirements.txtresolves cleanly under 3.13.actionlintis clean.Dependabot already maintains the hash-pinned
.github/pre-commit/requirements.txt(#234), so a watchpoint for.github/toxkeeps these hashes current too.Also quotes the tox factor subshell, silencing a pre-existing shellcheck SC2046 warning.