File tree Expand file tree Collapse file tree 5 files changed +40
-3
lines changed Expand file tree Collapse file tree 5 files changed +40
-3
lines changed Original file line number Diff line number Diff line change 11ARG PYTHON_VERSION=3.10
22FROM python:${PYTHON_VERSION}-slim-bookworm
3+ ARG POETRY_EXTRAS
4+
5+ ENV PYTHONPATH=/workspace
36
47ENV POETRY_NO_INTERACTION=1 \
58 POETRY_VIRTUALENVS_IN_PROJECT=1 \
@@ -20,10 +23,18 @@ RUN bash -c 'python -m venv /opt/poetry-venv && source $_/bin/activate && pip in
2023# install dependencies with poetry
2124COPY pyproject.toml .
2225COPY poetry.lock .
23- RUN poetry install --all-extras --with dev --no-root
26+ RUN if [ "$POETRY_EXTRAS" = "" ]; then \
27+ poetry install --all-extras --with dev --no-root; \
28+ else \
29+ poetry install --extras "$POETRY_EXTRAS" --with dev --no-root; \
30+ fi
2431
2532# copy project source
2633COPY . .
2734
2835# install project with poetry
29- RUN poetry install --all-extras --with dev
36+ RUN if [ "$POETRY_EXTRAS" = "" ]; then \
37+ poetry install --all-extras --with dev; \
38+ else \
39+ poetry install --extras "$POETRY_EXTRAS" --with dev; \
40+ fi
Original file line number Diff line number Diff line change 44from typing import Callable
55from testcontainers .core .container import DockerClient
66from pprint import pprint
7+ from testcontainers .core .utils import is_arm
78import sys
89
10+ from .list_arm_extras import get_arm_extras
11+
912PROJECT_DIR = Path (__file__ ).parent .parent .parent .resolve ()
1013
1114
@@ -25,11 +28,16 @@ def python_testcontainer_image() -> str:
2528 py_version = "." .join (map (str , sys .version_info [:2 ]))
2629 image_name = f"testcontainers-python:{ py_version } "
2730 client = DockerClient ()
31+ build_args = {"PYTHON_VERSION" : py_version }
32+
33+ if is_arm ():
34+ build_args ["POETRY_EXTRAS" ] = get_arm_extras ()
35+
2836 client .build (
2937 path = str (PROJECT_DIR ),
3038 tag = image_name ,
3139 rm = False ,
32- buildargs = { "PYTHON_VERSION" : py_version } ,
40+ buildargs = build_args ,
3341 )
3442 return image_name
3543
Original file line number Diff line number Diff line change 1+ from pathlib import Path
2+ from testcontainers .core .utils import is_arm
3+
4+ try :
5+ import tomllib # Python 3.11+
6+ except ImportError :
7+ import tomli as tomllib
8+
9+ SKIPPED_EXTRAS = {"db2" } # skip incompatible extras
10+
11+
12+ def get_arm_extras ():
13+ with Path ("pyproject.toml" ).open ("rb" ) as f :
14+ data = tomllib .load (f )
15+
16+ extras = data ["tool" ]["poetry" ]["extras" ]
17+ skip = SKIPPED_EXTRAS
18+ return " " .join (k for k in extras if k not in skip )
You can’t perform that action at this time.
0 commit comments