From b6107d7a4feb8d574cf2ae176a11479e95ff1692 Mon Sep 17 00:00:00 2001 From: Charles de Beauchesne Date: Thu, 19 Nov 2026 16:13:45 +0100 Subject: [PATCH] ci: skip upstream ddtrace wheels that don't support the layer's Python version When UPSTREAM_PIPELINE_ID is set, ignore the dd-trace-py wheel if its Requires-Python excludes the Python version being built, as if no wheel was found: the layer is built with the released ddtrace. dd-trace-py PRs on release branches older than 4.17 declare requires-python <3.15, so build-layer (python315-*) failed in the pipelines they trigger. Co-Authored-By: Claude Opus 5.5 --- scripts/_spec_ddtrace_dep.sh | 42 ++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/scripts/_spec_ddtrace_dep.sh b/scripts/_spec_ddtrace_dep.sh index bb64bb178..9d61b2318 100644 --- a/scripts/_spec_ddtrace_dep.sh +++ b/scripts/_spec_ddtrace_dep.sh @@ -31,10 +31,43 @@ replace_ddtrace_dep() { perl -i -0777 -pe "s|ddtrace = \[[^\]]*\]|$1|gs" pyproject.toml } +# Return 0 if Python $1 (e.g. "3.15") satisfies the Requires-Python of wheel $2. +# Handles the >=, >, <=, < and == bounds on major.minor; other clauses are +# ignored. A wheel without Requires-Python is accepted. +_wheel_supports_python() { + local python_version=$1 + local wheel=$2 + local requires + requires=$(unzip -p "$wheel" '*.dist-info/METADATA' 2>/dev/null \ + | sed -n 's/^Requires-Python: *//p' | head -n 1 | tr -d ' \r') + [ -z "$requires" ] && return 0 + local want=$(( ${python_version%%.*} * 1000 + ${python_version#*.} )) + local clause op ver major minor have + IFS=',' read -ra clauses <<< "$requires" + for clause in "${clauses[@]}"; do + op=$(sed -E 's/^([<>=!~]+).*/\1/' <<< "$clause") + ver=$(sed -E 's/^[<>=!~]+//' <<< "$clause") + major=${ver%%.*} + minor=$(cut -d. -f2 <<< "$ver.0") + [[ "$major" =~ ^[0-9]+$ && "$minor" =~ ^[0-9]+$ ]] || continue + have=$(( major * 1000 + minor )) + case "$op" in + ">=") [ "$want" -ge "$have" ] || return 1 ;; + ">") [ "$want" -gt "$have" ] || return 1 ;; + "<=") [ "$want" -le "$have" ] || return 1 ;; + "<") [ "$want" -lt "$have" ] || return 1 ;; + "==") [ "$want" -eq "$have" ] || return 1 ;; + esac + done + return 0 +} + # Search S3 for a wheel matching basename + index, then rewrite the ddtrace # dep to point at the downloaded file. Globals required: -# S3_BASE, PY_TAG, PLATFORM -# Returns 0 on success, 1 if no matching wheel was found at the index. +# S3_BASE, PY_TAG, PLATFORM, PYTHON_VERSION +# Returns 0 on success, 1 if no matching wheel was found at the index, or if +# the wheel doesn't support PYTHON_VERSION (e.g. a dd-trace-py release branch +# older than the runtime): the caller then keeps the released ddtrace. _search_and_spec_s3_wheel() { local basename=$1 local index=$2 @@ -47,6 +80,11 @@ _search_and_spec_s3_wheel() { return 1 fi curl -sSfL "${S3_BASE}/${wheel_file}" -o "${wheel_file}" + if ! _wheel_supports_python "${PYTHON_VERSION}" "${wheel_file}"; then + echo "S3 wheel ${wheel_file} does not support Python ${PYTHON_VERSION}, not using it" + rm -f "${wheel_file}" + return 1 + fi echo "Using S3 wheel: ${wheel_file}" replace_ddtrace_dep "${basename} = { file = \"${wheel_file}\" }" }