863cef5e64
Packages anki and aqt do not pin their requirements, which breaks anki <= 2.1.49 because of protobuf major version bump. While it's possible to use requirements.txt as constraints, it might not be the best idea: * requirements.txt can’t be used as constraints without some careful sed’ding to remove hashes and extras; * its location changes between versions; * you can’t get this file for a pre-release version of Anki since these don't get git tags; * it’s rarely updated anyway and hence won’t reliably produce the environment that actual Anki uses. So use a pypi-timemachine, which prevents pip from using packages that were uploaded after a specified date. While the code is a tad complex, it feels slightly less hacky, and is likely to be producing more accurate environments.
21 lines
740 B
Bash
21 lines
740 B
Bash
#!/bin/bash
|
|
|
|
set -eux
|
|
trap '[[ -v SERVER_PID ]] && pkill -P $SERVER_PID' EXIT
|
|
print_first_group() { perl -snle 'm/$re/; print $1; exit 0' -- -re="$1"; }
|
|
|
|
envname="$1"
|
|
toxworkdir="$2"
|
|
packages=("${@:3}")
|
|
|
|
version=$(print_first_group 'anki([\d\.a-z]+)' <<< "$envname")
|
|
upload_time=$(curl https://pypi.org/pypi/anki/json \
|
|
| jq --arg v "$version" -r '.releases[$v][0].upload_time_iso_8601')
|
|
cutoff_time=$(date --utc -d "$upload_time +1 hour" '+%Y-%m-%dT%H:%M:%S')
|
|
|
|
coproc SERVER { "$toxworkdir"/.tox/bin/python -um pypi_timemachine "$cutoff_time"; }
|
|
index_url=$(print_first_group '(http\S+)' <&"${SERVER[0]}")
|
|
|
|
python -m pip install --index-url "$index_url" "anki==$version" "$AQT==$version"
|
|
python -m pip install "${packages[@]}"
|