Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use uv instead of pip on production images #112496

Merged
merged 25 commits into from
Mar 22, 2024
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ jobs:
python -m venv venv
. venv/bin/activate
python --version
pip install "$(cat requirements_test.txt | grep uv)"
pip install "$(cat requirements_test.txt | grep '^uv')"
uv pip install "$(cat requirements_test.txt | grep pre-commit)"
- name: Restore pre-commit environment from cache
id: cache-precommit
Expand Down Expand Up @@ -493,7 +493,7 @@ jobs:
python -m venv venv
. venv/bin/activate
python --version
pip install "$(cat requirements_test.txt | grep uv)"
pip install "$(cat requirements_test.txt | grep '^uv')"
uv pip install -U "pip>=21.3.1" setuptools wheel
uv pip install -r requirements_all.txt
uv pip install -r requirements_test.txt
Expand Down Expand Up @@ -725,7 +725,7 @@ jobs:
# Ideally this should be part of our dependencies
# However this plugin is fairly new and doesn't run correctly
# on a non-GitHub environment.
pip install "$(cat requirements_test.txt | grep uv)"
pip install "$(cat requirements_test.txt | grep '^uv')"
uv pip install pytest-github-actions-annotate-failures==0.1.3
- name: Register pytest slow test problem matcher
run: |
Expand Down Expand Up @@ -879,7 +879,7 @@ jobs:
# Ideally this should be part of our dependencies
# However this plugin is fairly new and doesn't run correctly
# on a non-GitHub environment.
pip install "$(cat requirements_test.txt | grep uv)"
pip install "$(cat requirements_test.txt | grep '^uv')"
uv pip install pytest-github-actions-annotate-failures==0.1.3
- name: Register pytest slow test problem matcher
run: |
Expand Down Expand Up @@ -1007,7 +1007,7 @@ jobs:
# Ideally this should be part of our dependencies
# However this plugin is fairly new and doesn't run correctly
# on a non-GitHub environment.
pip install "$(cat requirements_test.txt | grep uv)"
pip install "$(cat requirements_test.txt | grep '^uv')"
uv pip install pytest-github-actions-annotate-failures==0.1.3
- name: Register pytest slow test problem matcher
run: |
Expand Down
28 changes: 17 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,53 @@ FROM ${BUILD_FROM}

# Synchronize with homeassistant/core.py:async_stop
ENV \
S6_SERVICES_GRACETIME=240000
S6_SERVICES_GRACETIME=240000 \
UV_EXTRA_INDEX_URL="https://wheels.home-assistant.io/musllinux-index/" \
UV_NO_CACHE=true \
PATH="$PATH:/root/.cargo/bin" \
UV_SYSTEM_PYTHON=true

ARG QEMU_CPU

# Install uv
RUN pip3 install "$(cat requirements_test.txt | grep '^uv')"

WORKDIR /usr/src

## Setup Home Assistant Core dependencies
COPY requirements.txt homeassistant/
COPY homeassistant/package_constraints.txt homeassistant/homeassistant/
RUN \
pip3 install \
--only-binary=:all: \
uv pip install \
--no-build \
-r homeassistant/requirements.txt

COPY requirements_all.txt home_assistant_frontend-* home_assistant_intents-* homeassistant/
RUN \
if ls homeassistant/home_assistant_frontend*.whl 1> /dev/null 2>&1; then \
pip3 install homeassistant/home_assistant_frontend-*.whl; \
uv pip install homeassistant/home_assistant_frontend-*.whl; \
fi \
&& if ls homeassistant/home_assistant_intents*.whl 1> /dev/null 2>&1; then \
pip3 install homeassistant/home_assistant_intents-*.whl; \
uv pip install homeassistant/home_assistant_intents-*.whl; \
fi \
&& if [ "${BUILD_ARCH}" = "i386" ]; then \
LD_PRELOAD="/usr/local/lib/libjemalloc.so.2" \
MALLOC_CONF="background_thread:true,metadata_thp:auto,dirty_decay_ms:20000,muzzy_decay_ms:20000" \
linux32 pip3 install \
--only-binary=:all: \
linux32 uv pip install \
--no-build \
-r homeassistant/requirements_all.txt; \
else \
LD_PRELOAD="/usr/local/lib/libjemalloc.so.2" \
MALLOC_CONF="background_thread:true,metadata_thp:auto,dirty_decay_ms:20000,muzzy_decay_ms:20000" \
pip3 install \
--only-binary=:all: \
uv pip install \
--no-build \
-r homeassistant/requirements_all.txt; \
fi

## Setup Home Assistant Core
COPY . homeassistant/
RUN \
pip3 install \
--only-binary=:all: \
uv pip install \
-e ./homeassistant \
&& python3 -m compileall \
homeassistant/homeassistant
Expand Down
2 changes: 1 addition & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ types-pytz==2023.3.1.1
types-PyYAML==6.0.12.12
types-requests==2.31.0.3
types-xmltodict==0.13.0.3
uv==0.1.17
uv==0.1.22
28 changes: 17 additions & 11 deletions script/hassfest/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,53 @@

# Synchronize with homeassistant/core.py:async_stop
ENV \
S6_SERVICES_GRACETIME={timeout}
S6_SERVICES_GRACETIME={timeout} \
UV_EXTRA_INDEX_URL="https://wheels.home-assistant.io/musllinux-index/" \
UV_NO_CACHE=true \
PATH="$PATH:/root/.cargo/bin" \
UV_SYSTEM_PYTHON=true

ARG QEMU_CPU

# Install uv
RUN pip3 install "$(cat requirements_test.txt | grep '^uv')"

WORKDIR /usr/src

## Setup Home Assistant Core dependencies
COPY requirements.txt homeassistant/
COPY homeassistant/package_constraints.txt homeassistant/homeassistant/
RUN \
pip3 install \
--only-binary=:all: \
uv pip install \
--no-build \
-r homeassistant/requirements.txt

COPY requirements_all.txt home_assistant_frontend-* home_assistant_intents-* homeassistant/
RUN \
if ls homeassistant/home_assistant_frontend*.whl 1> /dev/null 2>&1; then \
pip3 install homeassistant/home_assistant_frontend-*.whl; \
uv pip install homeassistant/home_assistant_frontend-*.whl; \
fi \
&& if ls homeassistant/home_assistant_intents*.whl 1> /dev/null 2>&1; then \
pip3 install homeassistant/home_assistant_intents-*.whl; \
uv pip install homeassistant/home_assistant_intents-*.whl; \
fi \
&& if [ "${{BUILD_ARCH}}" = "i386" ]; then \
LD_PRELOAD="/usr/local/lib/libjemalloc.so.2" \
MALLOC_CONF="background_thread:true,metadata_thp:auto,dirty_decay_ms:20000,muzzy_decay_ms:20000" \
linux32 pip3 install \
--only-binary=:all: \
linux32 uv pip install \
--no-build \
-r homeassistant/requirements_all.txt; \
else \
LD_PRELOAD="/usr/local/lib/libjemalloc.so.2" \
MALLOC_CONF="background_thread:true,metadata_thp:auto,dirty_decay_ms:20000,muzzy_decay_ms:20000" \
pip3 install \
--only-binary=:all: \
uv pip install \
--no-build \
-r homeassistant/requirements_all.txt; \
fi

## Setup Home Assistant Core
COPY . homeassistant/
RUN \
pip3 install \
--only-binary=:all: \
uv pip install \
-e ./homeassistant \
&& python3 -m compileall \
homeassistant/homeassistant
Expand Down