python-cstruct
python-cstruct copied to clipboard
make ast module usage compatible to python 3.14
Python 3.8 deprecated some AST nodes, which got removed in Python 3.14.
The Python 3.14 releaes notes for the ast module state:
- Remove the following classes, which have been deprecated aliases of
Constantsince Python 3.8 and have emitted deprecation warnings since Python 3.12:
BytesEllipsisNameConstantNumStr[...]
- Remove the following deprecated properties on ast.Constant, which were present for compatibility with the now-removed AST classes:
- Constant.n
- Constant.s
Use Constant.value instead. (Contributed by Alex Waygood in gh-119562.)
Running the tests with Python 3.12 or 3.13 already prints deprecation warnings.
DeprecationWarning: ast.Num is deprecated and will be removed in Python 3.14; use ast.Constant instead
DeprecationWarning: ast.Str is deprecated and will be removed in Python 3.14; use ast.Constant instead
So far I've tested this with the following python versions:
- [x] Python 3.6 (used
make testfrom docker/i386/Makefile) (alpine) - [x] Python 3.7 (debian 10 docker container. see spoiler below) (alpine)
- [x] Python 3.8 (alpine)
- [x] Python 3.9 (alpine)
- [x] Python 3.10 (alpine) (applied patch to nixpkgs version)
- [x] Python 3.11 (alpine) (applied patch to nixpkgs version)
- [x] Python 3.12 (alpine) (applied patch to nixpkgs version)
- [x] Python 3.13 (applied patch to nixpkgs version)
- [x] Python 3.14 (applied patch to nixpkgs version)
Details on how I ran the tests against python 3.7 (click to unfold)
# docker build -t debian-10-python-cstruct . && docker run --rm -it debian-10-python-cstruct
FROM debian:10
RUN cat <<EOF > /etc/apt/sources.list
deb http://archive.debian.org/debian/ buster contrib main non-free
EOF
RUN apt-get update && apt-get install -y git python3 python3-pytest curl make
RUN git clone https://github.com/andreax79/python-cstruct/
WORKDIR python-cstruct
RUN git config user.email "[email protected]"
RUN git config user.name "Your Name"
COPY 0001-make-ast-module-usage-compatible-to-python-3.14.patch .
RUN git am 0001-make-ast-module-usage-compatible-to-python-3.14.patch
RUN python3 -m pytest
==================================================================== test session starts =====================================================================
platform linux -- Python 3.7.3, pytest-3.10.1, py-1.7.0, pluggy-0.8.0
rootdir: /python-cstruct, inifile: pytest.ini
collected 82 items
tests/test_alignment.py ....... [ 8%]
tests/test_c_expr.py ...... [ 15%]
tests/test_cenum.py ......... [ 26%]
tests/test_cstruct.py .............. [ 43%]
tests/test_cstruct_var.py . [ 45%]
tests/test_define.py ...... [ 52%]
tests/test_flexible_array.py .... [ 57%]
tests/test_get_type.py . [ 58%]
tests/test_memcstruct.py .............. [ 75%]
tests/test_native_types.py .. [ 78%]
tests/test_nested.py ........... [ 91%]
tests/test_padding.py .. [ 93%]
tests/test_pickle.py .. [ 96%]
tests/test_typdef.py . [ 97%]
tests/test_union.py .. [100%]
================================================================= 82 passed in 0.15 seconds ==================================================================
Details on how I ran the tests against many alpine and python versions (click to unfold)
template = """FROM alpine:{version}
RUN apk update && apk add python3 py3-pytest
COPY python-cstruct/ python-cstruct/
WORKDIR python-cstruct
RUN pytest-3
"""
versions = [
"3.23",
"3.22",
"3.21",
"3.20",
"3.19",
"3.18",
"3.17",
"3.16",
"3.15",
"3.14",
"3.13",
"3.12",
"3.11",
"3.10",
"3.9",
"3.8",
"3.7",
"3.6",
]
for version in versions:
content = template.format(version=version)
with open(f"Dockerfile-alpine-{version}", "w") as f:
f.write(content)
#!/bin/bash
set -eu
PROJECT="python-cstruct"
TARGETS=""
TARGETS="${TARGETS} alpine-3.23" # python 3.12.12
TARGETS="${TARGETS} alpine-3.22" # python 3.12.12
TARGETS="${TARGETS} alpine-3.21" # python 3.12.12
TARGETS="${TARGETS} alpine-3.20" # python 3.12.12
TARGETS="${TARGETS} alpine-3.19" # python 3.11.14
TARGETS="${TARGETS} alpine-3.18" # python 3.11.12
TARGETS="${TARGETS} alpine-3.17" # python 3.10.15
TARGETS="${TARGETS} alpine-3.16" # python 3.10.14
TARGETS="${TARGETS} alpine-3.15" # python 3.9.18
TARGETS="${TARGETS} alpine-3.14" # python 3.9.17
TARGETS="${TARGETS} alpine-3.13" # python 3.8.15
TARGETS="${TARGETS} alpine-3.12" # python 3.8.10
TARGETS="${TARGETS} alpine-3.11" # python 3.8.10
TARGETS="${TARGETS} alpine-3.10" # python 3.7.10
TARGETS="${TARGETS} alpine-3.9" # python 3.6.9
TARGETS="${TARGETS} alpine-3.8" # python 3.6.9
TARGETS="${TARGETS} alpine-3.7" # python 3.6.9
TARGETS="${TARGETS} alpine-3.6" # python 3.6.8
if test ! -z "$@"; then
TARGETS="$@"
fi
echo "TARGETS=${TARGETS}"
if which podman >/dev/null; then
DOCKER=podman
elif which docker >/dev/null; then
DOCKER=docker
else
echo "ERROR: no podman or docker found!" >&2
exit 1
fi
for TARGET in $TARGETS; do
$DOCKER build -t "almost-ci-${PROJECT}-${TARGET}" -f "Dockerfile-${TARGET}"
done
for TARGET in $TARGETS; do
echo -n "${TARGET} -> "
$DOCKER run --rm -it "almost-ci-${PROJECT}-${TARGET}" /usr/bin/python3 --version
done
Successfully ran pytest on:
- alpine v3.23 (Python 3.12.12)
- alpine v3.22 (Python 3.12.12)
- alpine v3.21 (Python 3.12.12)
- alpine v3.20 (Python 3.12.12)
- alpine v3.19 (Python 3.11.14)
- alpine v3.18 (Python 3.11.12)
- alpine v3.17 (Python 3.10.15)
- alpine v3.16 (Python 3.10.14)
- alpine v3.15 (Python 3.9.18)
- alpine v3.14 (Python 3.9.17)
- alpine v3.13 (Python 3.8.15)
- alpine v3.12 (Python 3.8.10)
- alpine v3.11 (Python 3.8.10)
- alpine v3.10 (Python 3.7.10)
- alpine v3.9 (Python 3.6.9)
- alpine v3.8 (Python 3.6.9)
- alpine v3.7 (Python 3.6.9)
- alpine v3.6 (Python 3.6.8)