Skip to content

Instantly share code, notes, and snippets.

@foosel
Last active October 12, 2023 10:50
Show Gist options
  • Save foosel/80b22908c008c063b85c819aee12c5ad to your computer and use it in GitHub Desktop.
Save foosel/80b22908c008c063b85c819aee12c5ad to your computer and use it in GitHub Desktop.

This is a test setup for pydantic/pydantic#7689 against various armv7 bookworm setups.

Install Docker and Taskfile and then run tests with

PYDANTIC=<version> task armv7-[pi-|piwheels-]bookworm

If you see something like:

Step 16/16 : RUN /test/bin/python /test/test.py
 ---> Running in 85df32f7a77a
foo='bar'
Removing intermediate container 85df32f7a77a
 ---> 2c5e979b3bf3
Successfully built 2c5e979b3bf3

the test succeeded and the installed pydantic version worked with the test code. If you see

Step 16/16 : RUN /test/bin/python /test/test.py
 ---> [Warning] The requested image's platform (linux/arm/v7) does not match the detected host platform (linux/amd64/v4) and no specific platform was requested
 ---> Running in 1c3af7b9a153
Traceback (most recent call last):
  File "/test/test.py", line 9, in <module>
    class TestModel(BaseModel):
  File "pydantic/main.py", line 186, in pydantic.main.ModelMetaclass.__new__
TypeError: Argument 'bases' has incorrect type (expected list, got tuple)
The command '/bin/sh -c /test/bin/python /test/test.py' returned a non-zero code: 1
task: Failed to run task "armv7-piwheels-bookworm": task: Failed to run task "build-image": exit status 1

it's a test failure and the installed pydantic version runs into pydantic/pydantic#7689.

ARG DOCKER_ARCH
ARG DEBIAN_VERSION
FROM ${DOCKER_ARCH}debian:${DEBIAN_VERSION} as base
RUN apt-get -y update && apt-get -y install gnupg2
# Add RPI packages (the whole base system, since RPI ships its own GCC)
ARG DEBIAN_VERSION
ARG BUILD_TYPE="generic"
RUN [ "$BUILD_TYPE" != "raspi" ] || \
( \
( [ "$(dpkg --print-architecture)" != "armhf" ] || echo "deb http://raspbian.raspberrypi.org/raspbian/ $DEBIAN_VERSION main contrib non-free rpi" > /etc/apt/sources.list ) && \
echo "deb http://archive.raspberrypi.org/debian/ $DEBIAN_VERSION main" > /etc/apt/sources.list.d/raspi.list && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 9165938D90FDDD2E 82B129927FA3303E && \
apt-get -y update && \
apt-get -y install libcamera-dev liblivemedia-dev \
)
RUN apt install -y python3 python3-pip python3-dev python3-setuptools python3.11-venv build-essential
FROM base as test
ARG PIWHEELS
ARG PYDANTIC="1.10.12"
RUN [ "$PIWHEELS" != "enable" ] || [ "$BUILD_TYPE" == "raspi" ] || \
( \
echo "[global]" > /etc/pip.conf && \
echo "extra-index-url=https://www.piwheels.org/simple" >> /etc/pip.conf \
)
RUN cat /etc/pip.conf || true
RUN python3 -m venv /test && /test/bin/pip install pydantic==$PYDANTIC
COPY ./test.py /test/test.py
RUN /test/bin/python /test/test.py
version: "3"
tasks:
build-image:
internal: true
cmds:
- |
docker build --build-arg "DOCKER_ARCH={{.DOCKER_ARCH}}/" --build-arg "DEBIAN_VERSION={{.DEBIAN_VERSION}}" --build-arg "BUILD_TYPE={{.BUILD_TYPE}}" --build-arg "PIWHEELS={{.PIWHEELS}}" --build-arg "PYDANTIC={{.PYDANTIC}}" .
armv7-pi-bookworm:
cmds:
- task: build-image
vars:
DEBIAN_VERSION: bookworm
DOCKER_ARCH: arm32v7
BUILD_TYPE: raspi
PYDANTIC: $PYDANTIC
armv7-piwheels-bookworm:
cmds:
- task: build-image
vars:
DEBIAN_VERSION: bookworm
DOCKER_ARCH: arm32v7
BUILD_TYPE: generic
PIWHEELS: enable
PYDANTIC: $PYDANTIC
armv7-bookworm:
cmds:
- task: build-image
vars:
DEBIAN_VERSION: bookworm
DOCKER_ARCH: arm32v7
BUILD_TYPE: generic
PYDANTIC: $PYDANTIC
from pydantic import BaseModel
class TestModel(BaseModel):
foo: str = "bar"
if __name__ == "__main__":
test = TestModel()
print(test)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment