Skip to content

Commit b6107d7

Browse files
cbeauchesneclaude
andcommitted
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 <noreply@anthropic.com>
1 parent f5980cb commit b6107d7

1 file changed

Lines changed: 40 additions & 2 deletions

File tree

‎scripts/_spec_ddtrace_dep.sh‎

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,43 @@ replace_ddtrace_dep() {
3131
perl -i -0777 -pe "s|ddtrace = \[[^\]]*\]|$1|gs" pyproject.toml
3232
}
3333

34+
# Return 0 if Python $1 (e.g. "3.15") satisfies the Requires-Python of wheel $2.
35+
# Handles the >=, >, <=, < and == bounds on major.minor; other clauses are
36+
# ignored. A wheel without Requires-Python is accepted.
37+
_wheel_supports_python() {
38+
local python_version=$1
39+
local wheel=$2
40+
local requires
41+
requires=$(unzip -p "$wheel" '*.dist-info/METADATA' 2>/dev/null \
42+
| sed -n 's/^Requires-Python: *//p' | head -n 1 | tr -d ' \r')
43+
[ -z "$requires" ] && return 0
44+
local want=$(( ${python_version%%.*} * 1000 + ${python_version#*.} ))
45+
local clause op ver major minor have
46+
IFS=',' read -ra clauses <<< "$requires"
47+
for clause in "${clauses[@]}"; do
48+
op=$(sed -E 's/^([<>=!~]+).*/\1/' <<< "$clause")
49+
ver=$(sed -E 's/^[<>=!~]+//' <<< "$clause")
50+
major=${ver%%.*}
51+
minor=$(cut -d. -f2 <<< "$ver.0")
52+
[[ "$major" =~ ^[0-9]+$ && "$minor" =~ ^[0-9]+$ ]] || continue
53+
have=$(( major * 1000 + minor ))
54+
case "$op" in
55+
">=") [ "$want" -ge "$have" ] || return 1 ;;
56+
">") [ "$want" -gt "$have" ] || return 1 ;;
57+
"<=") [ "$want" -le "$have" ] || return 1 ;;
58+
"<") [ "$want" -lt "$have" ] || return 1 ;;
59+
"==") [ "$want" -eq "$have" ] || return 1 ;;
60+
esac
61+
done
62+
return 0
63+
}
64+
3465
# Search S3 for a wheel matching basename + index, then rewrite the ddtrace
3566
# dep to point at the downloaded file. Globals required:
36-
# S3_BASE, PY_TAG, PLATFORM
37-
# Returns 0 on success, 1 if no matching wheel was found at the index.
67+
# S3_BASE, PY_TAG, PLATFORM, PYTHON_VERSION
68+
# Returns 0 on success, 1 if no matching wheel was found at the index, or if
69+
# the wheel doesn't support PYTHON_VERSION (e.g. a dd-trace-py release branch
70+
# older than the runtime): the caller then keeps the released ddtrace.
3871
_search_and_spec_s3_wheel() {
3972
local basename=$1
4073
local index=$2
@@ -47,6 +80,11 @@ _search_and_spec_s3_wheel() {
4780
return 1
4881
fi
4982
curl -sSfL "${S3_BASE}/${wheel_file}" -o "${wheel_file}"
83+
if ! _wheel_supports_python "${PYTHON_VERSION}" "${wheel_file}"; then
84+
echo "S3 wheel ${wheel_file} does not support Python ${PYTHON_VERSION}, not using it"
85+
rm -f "${wheel_file}"
86+
return 1
87+
fi
5088
echo "Using S3 wheel: ${wheel_file}"
5189
replace_ddtrace_dep "${basename} = { file = \"${wheel_file}\" }"
5290
}

0 commit comments

Comments
 (0)