|
| 1 | +#!/bin/bash -e |
| 2 | + |
| 3 | +# This script checks to make sure that the vendored version of requests shipped |
| 4 | +# with pip meets the minimum required version of requests as defined by the |
| 5 | +# datadog package. |
| 6 | + |
| 7 | +if [[ -z $ARCHITECTURE ]]; then |
| 8 | + DOCKER_DEFAULT_PLATFORM='linux/amd64' |
| 9 | +else |
| 10 | + DOCKER_DEFAULT_PLATFORM=$ARCHITECTURE |
| 11 | +fi |
| 12 | + |
| 13 | +if [[ -z $PYTHON_VERSION ]]; then |
| 14 | + PYTHON_VERSION=latest |
| 15 | +fi |
| 16 | + |
| 17 | +# create virtual environment |
| 18 | +rm -rf venv |
| 19 | +pip install virtualenv |
| 20 | +virtualenv venv |
| 21 | +source venv/bin/activate |
| 22 | + |
| 23 | +# determine highest available version of requests |
| 24 | +pip install . |
| 25 | +highest=$(pip freeze | grep requests | tr -d 'requests==') |
| 26 | +echo "Highest available version of requests: $highest" |
| 27 | + |
| 28 | +# determine minumum required version of requests |
| 29 | +pip uninstall -y requests |
| 30 | +pip install uv |
| 31 | +uv pip install --resolution=lowest . |
| 32 | +lowest=$(pip freeze | grep requests | tr -d 'requests==') |
| 33 | +echo "Minimum required version of requests: $lowest" |
| 34 | + |
| 35 | +# determine version of requests packaged with pip |
| 36 | +vendored=$( |
| 37 | + DOCKER_DEFAULT_PLATFORM=$DOCKER_DEFAULT_PLATFORM \ |
| 38 | + docker run --entrypoint='' public.ecr.aws/lambda/python:$PYTHON_VERSION \ |
| 39 | + python -c "import pip._vendor.requests; print(pip._vendor.requests.__version__)" |
| 40 | +) |
| 41 | +echo "Version of vendored requests: $vendored" |
| 42 | + |
| 43 | +# compare versions |
| 44 | +compared=$(python -c " |
| 45 | +parse = lambda v: tuple(map(int, v.split('.'))) |
| 46 | +print(parse('$lowest') <= parse('$vendored'))") |
| 47 | + |
| 48 | +if [[ "$compared" == "True" ]]; then |
| 49 | + echo "The vendored version of requests meets the minimum requirement" |
| 50 | + echo " lowest required ($lowest) <= vendored version ($vendored) <= highest available ($highest)" |
| 51 | +else |
| 52 | + echo "The vendored version of requests does not meet the minimum requirement" |
| 53 | + echo " vendered version ($vendored) < lowest required ($lowest) <= highest available ($highest)" |
| 54 | + exit 1 |
| 55 | +fi |
0 commit comments