diff options
| author | Eugene Triguba <hello@eugenetriguba.com> | 2026-03-21 12:27:51 -0400 |
|---|---|---|
| committer | Eugene Triguba <hello@eugenetriguba.com> | 2026-03-21 13:37:32 -0400 |
| commit | 10f49e53af7992ff8901fc3ba60ef53fc676df45 (patch) | |
| tree | 64e87baeee0cf5fa18a1f4add3adcecb0a4f40df /scripts/test.sh | |
| parent | Replace unittest with pytest (diff) | |
| download | taskipy2-10f49e53af7992ff8901fc3ba60ef53fc676df45.zip | |
Add support for Python 3.6, 3.7, and 3.8 on CI
Diffstat (limited to 'scripts/test.sh')
| -rwxr-xr-x | scripts/test.sh | 66 |
1 files changed, 62 insertions, 4 deletions
diff --git a/scripts/test.sh b/scripts/test.sh index d980a1a..08a8ab8 100755 --- a/scripts/test.sh +++ b/scripts/test.sh @@ -4,6 +4,35 @@ set -e PYTHON_VERSION="3.14" main() { + parse_args "$@" + + # NOTE: Python versions <= 3.8 do not have pre-built binary support with uv. + # Therefore, instead, we're using docker to download a pre-built image with + # an older version of Python installed. + if echo "3.6" | grep -qw "$PYTHON_VERSION"; then + export_requirements_txt_file_for_py36 + run_in_docker "$PYTHON_VERSION" " + pip install -r requirements.txt + pytest -v + " + elif echo "3.7 3.8" | grep -qw "$PYTHON_VERSION"; then + uv_install_script=$(get_uv_install_script_commands) + run_in_docker "$PYTHON_VERSION" " + $uv_install_script + export UV_PROJECT_ENVIRONMENT=\".venv-$PYTHON_VERSION\" + uv sync --group test + uv run task test + " + else + export UV_PROJECT_ENVIRONMENT=".venv-$PYTHON_VERSION" + uv python install "$PYTHON_VERSION" + uv python pin "$PYTHON_VERSION" + uv sync --group test + uv run task test + fi +} + +parse_args() { while [ $# -gt 0 ]; do case "$1" in --python-version) @@ -17,11 +46,40 @@ main() { esac shift done +} + +run_in_docker() { + version="$1" + script=" + echo \"$version\" > .python-version + $2 + " + docker run \ + --rm \ + --volume "$(pwd)":/app \ + --workdir /app \ + "python:$version-alpine" \ + sh -c "$script" +} + +export_requirements_txt_file_for_py36() { + # Python 3.6 isn't supported at all by uv (uv tries to use a 'text' keyword + # argument in a subprocess open call which doesn't exist until Python 3.7). + # Therefore, we need to export a requirements.txt file on-demand and then + # install it in a 3.6 container via pip. + uv_install_script=$(get_uv_install_script_commands) + run_in_docker "3.7" " + $uv_install_script + uv export --group test --no-editable --no-hashes > requirements.txt + " +} - uv python install "$PYTHON_VERSION" - uv python pin "$PYTHON_VERSION" - uv sync --group test - uv run task test +get_uv_install_script_commands() { + echo " + apk add curl + curl -fsSL https://astral.sh/uv/install.sh | sh + export PATH=\"\$HOME/.local/bin:\$PATH\" + " } main "$@" |