diff --git a/components/cli_runner/mpf_python_runner.py b/components/cli_runner/mpf_python_runner.py index ba6f9d13..0771e8c5 100644 --- a/components/cli_runner/mpf_python_runner.py +++ b/components/cli_runner/mpf_python_runner.py @@ -24,13 +24,12 @@ # limitations under the License. # ############################################################################# -import pkg_resources -from typing import Any, Mapping, Union, Iterable +import importlib.metadata +from typing import Any, Iterable, Mapping, Union import mpf_cli_runner_util as util import mpf_component_api -from mpf_component_api import ImageLocation, VideoTrack, AudioTrack, GenericTrack - +from mpf_component_api import AudioTrack, GenericTrack, ImageLocation, VideoTrack class PythonComponentHandle(util.ComponentHandle): @@ -42,26 +41,26 @@ def __init__(self, descriptor: Mapping[str, Any]): self.track_type = descriptor['algorithm']['trackType'] - @classmethod - def _load_component(cls, descriptor) -> type: + @staticmethod + def _load_component(descriptor) -> type: distribution_name = descriptor['batchLibrary'] - entry_points = pkg_resources.get_entry_map(distribution_name, 'mpf.exported_component') - + dist = importlib.metadata.distribution(distribution_name) + entry_points = dist.entry_points.select(group='mpf.exported_component') if not entry_points: raise RuntimeError(f'The "{distribution_name}" component did not declare a ' '"mpf.exported_component" entrypoint') # The left hand side of the '=' in entry point declaration should be "component". # For example: 'mpf.exported_component': 'component = my_module:MyComponentClass' - component_entry_point = entry_points.get('component') - if component_entry_point is None: + if component_entry_points := entry_points.select(name='component'): + return next(iter(component_entry_points)).load() + else: # An entry point in the "mpf.exported_component" group was found, # but the left hand side of the '=' was something else. # For example: 'mpf.exported_component': 'MyComponentClass = my_module:MyComponentClass' # We really only care about the entry point group, since we don't do anything with # entry point name. - component_entry_point = next(iter(entry_points.values())) - return component_entry_point.load() + return next(iter(entry_points)).load() def supports(self, media_type: util.MediaType) -> bool: diff --git a/components/cli_runner/tests/Dockerfile b/components/cli_runner/tests/Dockerfile index 48b2146f..22b9d8bf 100644 --- a/components/cli_runner/tests/Dockerfile +++ b/components/cli_runner/tests/Dockerfile @@ -24,7 +24,7 @@ # limitations under the License. # ############################################################################# -FROM python:3.8-alpine +FROM python:3.12-alpine RUN wget https://download.docker.com/linux/static/stable/x86_64/docker-20.10.3.tgz -O- \ | tar --extract --gzip --directory /bin --strip-components 1 docker/docker diff --git a/components/cpp_executor/Dockerfile b/components/cpp_executor/Dockerfile index 9c3f8ed2..8dda41c7 100644 --- a/components/cpp_executor/Dockerfile +++ b/components/cpp_executor/Dockerfile @@ -43,16 +43,19 @@ RUN --mount=type=tmpfs,target=/var/cache/apt \ --mount=type=tmpfs,target=/tmp \ apt-get update; \ apt-get upgrade -y; \ - apt-get install --no-install-recommends -y \ - python3.8 libpython3.8 wget ca-certificates gnupg2; \ + apt-get install --no-install-recommends -y wget ca-certificates gnupg2; \ # Can't set up cuda repo at the beginning because it requires wget ca-certificates gnupg2 wget -O- https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub \ | apt-key add -; \ echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 /" \ > /etc/apt/sources.list.d/cuda.list; \ + wget -O- 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xba6932366a755776' \ + | apt-key add -; \ + echo 'deb http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal main' \ + > /etc/apt/sources.list.d/deadsnakes.list; \ apt-get update; \ - apt-get install -y --no-install-recommends cuda-cudart-11-4; \ - ln --symbolic /usr/bin/python3.8 /usr/bin/python3 + apt-get install -y --no-install-recommends cuda-cudart-11-4 python3.12 libpython3.12; \ + ln --symbolic /usr/bin/python3.12 /usr/local/bin/python3 COPY --from=openmpf_build /usr/local/bin/ffmpeg /usr/local/bin/ffprobe /usr/local/bin/ @@ -85,8 +88,8 @@ COPY --from=openmpf_build /build-artifacts/install/bin/amq_detection_component \ # component executor log config COPY --from=openmpf_build /build-artifacts/install/config/Log4cxxConfig.xml $MPF_HOME/config/ -COPY --from=openmpf_build /build-artifacts/install/lib/mpf_cpp_sdk.cpython-38-x86_64-linux-gnu.so \ - /usr/lib/python3.8/lib-dynload +COPY --from=openmpf_build /build-artifacts/install/lib/mpf_cpp_sdk.cpython-312-x86_64-linux-gnu.so \ + /usr/lib/python3.12/lib-dynload COPY --from=openmpf_build /scripts/* /scripts/ diff --git a/components/java_executor/Dockerfile b/components/java_executor/Dockerfile index a12fdf56..f5a7ed21 100644 --- a/components/java_executor/Dockerfile +++ b/components/java_executor/Dockerfile @@ -43,8 +43,14 @@ RUN --mount=type=tmpfs,target=/var/cache/apt \ --mount=type=tmpfs,target=/tmp \ apt-get update; \ apt-get upgrade -y; \ - apt-get install --no-install-recommends -y openjdk-17-jre-headless python3.8; \ - ln --symbolic /usr/bin/python3.8 /usr/bin/python3; + apt-get install --no-install-recommends -y openjdk-17-jre-headless wget ca-certificates gnupg2; \ + wget -O- 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xba6932366a755776' \ + | apt-key add -; \ + echo 'deb http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal main' \ + > /etc/apt/sources.list.d/deadsnakes.list; \ + apt-get update; \ + apt-get install -y --no-install-recommends python3.12; \ + ln --symbolic /usr/bin/python3.12 /usr/local/bin/python3; COPY --from=openmpf_build /usr/local/bin/ffmpeg /usr/local/bin/ffprobe /usr/local/bin/ diff --git a/components/python/Dockerfile b/components/python/Dockerfile index a029f104..08ef20b4 100644 --- a/components/python/Dockerfile +++ b/components/python/Dockerfile @@ -38,15 +38,24 @@ SHELL ["/bin/bash", "-o", "errexit", "-o", "pipefail", "-c"] ENV LANG C.UTF-8 ENV LC_ALL C.UTF-8 + RUN --mount=type=tmpfs,target=/var/cache/apt \ --mount=type=tmpfs,target=/var/lib/apt/lists \ --mount=type=tmpfs,target=/tmp \ apt-get update; \ apt-get upgrade -y; \ + apt-get install --no-install-recommends -y wget ca-certificates gnupg2; \ + wget -O- 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xba6932366a755776' \ + | apt-key add -; \ + echo 'deb http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal main' \ + > /etc/apt/sources.list.d/deadsnakes.list; \ + apt-get update; \ apt-get install --no-install-recommends -y \ - python3.8 python3.8-venv libpython3.8 \ + python3.12 python3.12-venv libpython3.12 \ # Required for opencv-python - libglib2.0-0 libgl1-mesa-glx; + libglib2.0-0 libgl1-mesa-glx; \ + python3.12 -m ensurepip --upgrade --default-pip; \ + ln --symbolic /usr/bin/python3.12 /usr/local/bin/python3; COPY --from=openmpf_build /usr/local/bin/ffmpeg /usr/local/bin/ffprobe /usr/local/bin/ @@ -67,7 +76,7 @@ RUN --mount=type=tmpfs,target=/var/cache/apt \ apt-get update; \ # Some pip packages will try to compile C/C++ extensions during install. To compile the C/C++ # extensions, a C++ compiler and the Python development headers must be installed. - apt-get install --no-install-recommends -y g++ python3.8-dev + apt-get install --no-install-recommends -y g++ python3.12-dev RUN python3 -m venv "$COMPONENT_VIRTUALENV"; \ pip config --site set global.no-cache-dir true; \ diff --git a/openmpf_build/Dockerfile b/openmpf_build/Dockerfile index 638ea476..c77aa123 100644 --- a/openmpf_build/Dockerfile +++ b/openmpf_build/Dockerfile @@ -48,7 +48,7 @@ RUN --mount=type=tmpfs,target=/var/cache/apt \ DEBIAN_FRONTEND=noninteractive apt-get install --no-install-recommends -y \ wget ca-certificates gnupg2 unzip xz-utils cmake make g++ libgtest-dev mediainfo libssl-dev \ liblog4cxx-dev libboost-dev file openjdk-17-jdk-headless \ - python3.8-dev python3-pip libgl1-mesa-glx \ + libgl1-mesa-glx \ # libheif build deps libde265-dev git nasm ninja-build pkg-config \ # OpenCV build deps \ @@ -56,18 +56,25 @@ RUN --mount=type=tmpfs,target=/var/cache/apt \ libavutil-dev libswscale-dev libavresample-dev libharfbuzz-dev libfreetype-dev; \ # Can't set up cuda repo at the beginning because it requires wget ca-certificates gnupg2 wget -O- https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/3bf863cc.pub \ - | apt-key add -; \ + | apt-key add -; \ echo "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64 /" \ > /etc/apt/sources.list.d/cuda.list; \ + wget -O- 'https://keyserver.ubuntu.com/pks/lookup?op=get&search=0xba6932366a755776' \ + | apt-key add -; \ + echo 'deb http://ppa.launchpad.net/deadsnakes/ppa/ubuntu focal main' \ + > /etc/apt/sources.list.d/deadsnakes.list; \ apt-get update; \ apt-get install -y --no-install-recommends cuda-minimal-build-11-4 libcufft-dev-11-4 \ libnpp-dev-11-4 libcudnn8-dev=8.2.4.15-1+cuda11.4 libcudnn8=8.2.4.15-1+cuda11.4 \ - libcublas-dev-11-4; \ + libcublas-dev-11-4 \ + python3.12-dev python3.12-venv; \ # OpenCV doesn't use the statically compiled CUDA libraries except for libcudart and they are relatively large. find /usr/local/cuda/lib64/ -name '*.a' -not -name 'libcudart_static.a' -delete; \ rm /usr/lib/x86_64-linux-gnu/libcudnn*.a; \ ln --symbolic /usr/include/x86_64-linux-gnu/openblas-pthread/cblas.h /usr/include/cblas.h; \ - ln --symbolic /usr/bin/cmake /usr/bin/cmake3; + ln --symbolic /usr/bin/cmake /usr/bin/cmake3; \ + python3.12 -m ensurepip --upgrade --default-pip; \ + ln --symbolic /usr/bin/python3.12 /usr/local/bin/python3; FROM apt_install AS ocv_install diff --git a/subject-components/python/Dockerfile b/subject-components/python/Dockerfile index a3484f48..c77ee131 100644 --- a/subject-components/python/Dockerfile +++ b/subject-components/python/Dockerfile @@ -44,8 +44,15 @@ RUN --mount=type=tmpfs,target=/var/cache/apt \ < /etc/apt/sources.list.d/deadsnakes.list + apt-get update + apt-get install --no-install-recommends -y python3.12 python3.12-venv libpython3.12 + ln --symbolic /usr/bin/python3.12 /usr/local/bin/python3 eot ENV MPF_HOME /opt/mpf @@ -65,19 +72,20 @@ RUN --mount=type=tmpfs,target=/var/cache/apt \ --mount=type=tmpfs,target=/tmp \ < /etc/apt/sources.list.d/deadsnakes.list; \ + apt-get update; \ + apt-get install --no-install-recommends -y python3.12-venv; \ + python3.12 -m ensurepip --upgrade --default-pip; \ + ln --symbolic /usr/bin/python3.12 /usr/local/bin/python3; RUN wget --directory-prefix /scripts \