From 61d67e17610b5a1de2158179589b336915de2de8 Mon Sep 17 00:00:00 2001 From: Cooper Ry Lees Date: Sun, 22 Oct 2023 12:48:23 -0700 Subject: [PATCH 1/4] Move Docker image to hatch + compile - Move to hatch to build wheel - Install wheel into venv we copy with colorama + d Fixes #3928 Test: - See we can get black to execute: TODO: Update when compiled is working ``` crl-m1:black cooper$ docker run --rm black_compiled black --version black, 23.10.1.dev1+g882d879.d20231022 (compiled: no) Python (CPython) 3.11.6 ``` - Check size: TODO: Update when compiled ``` crl-m1:black cooper$ docker image ls | grep black_compiled black_compiled latest 9db38fb7f1d0 4 minutes ago 180MB ``` --- Dockerfile | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index a9e0ea5081e..d7e58a38b1c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,12 +3,13 @@ FROM python:3.11-slim AS builder RUN mkdir /src COPY . /src/ ENV VIRTUAL_ENV=/opt/venv +# Install build tools to compile dependencies that don't have prebuilt wheels +RUN apt update && apt install -y build-essential git python3-dev RUN python -m venv $VIRTUAL_ENV -RUN . /opt/venv/bin/activate && pip install --no-cache-dir --upgrade pip setuptools wheel \ - # Install build tools to compile dependencies that don't have prebuilt wheels - && apt update && apt install -y git build-essential \ - && cd /src \ - && pip install --no-cache-dir .[colorama,d] +RUN python -m pip install --no-cache-dir hatch +RUN . /opt/venv/bin/activate && pip install --no-cache-dir --upgrade pip setuptools \ + && cd /src && hatch build -t wheel \ + && pip install --no-cache-dir dist/*[colorama,d] FROM python:3.11-slim From 5add19827f811c04c3db337bf3db3987c7151292 Mon Sep 17 00:00:00 2001 From: Cooper Ry Lees Date: Sun, 22 Oct 2023 13:00:57 -0700 Subject: [PATCH 2/4] Add change log entry + note on docs --- CHANGES.md | 1 + docs/usage_and_configuration/black_docker_image.md | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index 79b5c6034e8..cb728c1b6a1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -21,6 +21,7 @@ ### Packaging +- Change Dockerfile to hatch + compile black (#3965) ### Parser diff --git a/docs/usage_and_configuration/black_docker_image.md b/docs/usage_and_configuration/black_docker_image.md index 85aec91ef1c..c97c25af328 100644 --- a/docs/usage_and_configuration/black_docker_image.md +++ b/docs/usage_and_configuration/black_docker_image.md @@ -24,6 +24,8 @@ created for all unreleased [commits on the `main` branch](https://github.com/psf/black/commits/main). This tag is not meant to be used by external users. +From version 23.11.0 the Docker image installs a compiled black into the image. + ## Usage A permanent container doesn't have to be created to use _Black_ as a Docker image. It's From 56b9bdb2822b827d9186bf10543a9c14db9a45d4 Mon Sep 17 00:00:00 2001 From: Cooper Ry Lees Date: Sun, 22 Oct 2023 13:36:19 -0700 Subject: [PATCH 3/4] Add env var, extra deps + better glob to get compiled wheel only for pip install - Also install uvloop --- CHANGES.md | 1 + Dockerfile | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index cb728c1b6a1..23b11688369 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -21,6 +21,7 @@ ### Packaging + - Change Dockerfile to hatch + compile black (#3965) ### Parser diff --git a/Dockerfile b/Dockerfile index d7e58a38b1c..8a70db80dcd 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,13 +3,14 @@ FROM python:3.11-slim AS builder RUN mkdir /src COPY . /src/ ENV VIRTUAL_ENV=/opt/venv +ENV HATCH_BUILD_HOOKS_ENABLE=1 # Install build tools to compile dependencies that don't have prebuilt wheels RUN apt update && apt install -y build-essential git python3-dev RUN python -m venv $VIRTUAL_ENV -RUN python -m pip install --no-cache-dir hatch +RUN python -m pip install --no-cache-dir hatch hatch-fancy-pypi-readme hatch-vcs RUN . /opt/venv/bin/activate && pip install --no-cache-dir --upgrade pip setuptools \ && cd /src && hatch build -t wheel \ - && pip install --no-cache-dir dist/*[colorama,d] + && pip install --no-cache-dir dist/*-cp*[colorama,d,uvloop] FROM python:3.11-slim From 9f965314381bf217e6d70a62cdad5153698976e3 Mon Sep 17 00:00:00 2001 From: Cooper Ry Lees Date: Sun, 22 Oct 2023 14:12:19 -0700 Subject: [PATCH 4/4] Fix comment as why we need apt install --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 8a70db80dcd..bfd9acccb99 100644 --- a/Dockerfile +++ b/Dockerfile @@ -4,7 +4,7 @@ RUN mkdir /src COPY . /src/ ENV VIRTUAL_ENV=/opt/venv ENV HATCH_BUILD_HOOKS_ENABLE=1 -# Install build tools to compile dependencies that don't have prebuilt wheels +# Install build tools to compile black + dependencies RUN apt update && apt install -y build-essential git python3-dev RUN python -m venv $VIRTUAL_ENV RUN python -m pip install --no-cache-dir hatch hatch-fancy-pypi-readme hatch-vcs