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 11 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
4 changes: 2 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
{
"label": "Install all Requirements",
"type": "shell",
"command": "pip3 install -r requirements_all.txt",
"command": "uv pip install -r requirements_all.txt",
"group": {
"kind": "build",
"isDefault": true
Expand All @@ -117,7 +117,7 @@
{
"label": "Install all Test Requirements",
"type": "shell",
"command": "pip3 install -r requirements_test_all.txt",
"command": "uv pip install -r requirements_test_all.txt",
"group": {
"kind": "build",
"isDefault": true
Expand Down
33 changes: 22 additions & 11 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -6,47 +6,58 @@ 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"

ARG QEMU_CPU

# Set shell
SHELL ["/bin/ash", "-o", "pipefail", "-c"]
RUN curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/uv/releases/download/0.1.17/uv-installer.sh | sh

WORKDIR /usr/src

## Setup Home Assistant Core dependencies
COPY requirements.txt homeassistant/
COPY homeassistant/package_constraints.txt homeassistant/homeassistant/
RUN pip3 install uv
RUN \
pip3 install \
--only-binary=:all: \
uv pip install \
--system \
--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 --system 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 --system 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 \
--system \
--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 \
--system \
--no-build \
-r homeassistant/requirements_all.txt; \
fi

## Setup Home Assistant Core
COPY . homeassistant/
RUN \
pip3 install \
--only-binary=:all: \
uv pip install \
--system \
-e ./homeassistant \
&& python3 -m compileall \
homeassistant/homeassistant
Expand Down
9 changes: 6 additions & 3 deletions Dockerfile.dev
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,21 @@ RUN \

WORKDIR /usr/src

# Install uv
RUN pip3 install uv

# Setup hass-release
RUN git clone --depth 1 https://github.com/home-assistant/hass-release \
&& pip3 install -e hass-release/
&& uv pip install --system -e hass-release/

WORKDIR /workspaces

# Install Python dependencies from requirements
COPY requirements.txt ./
COPY homeassistant/package_constraints.txt homeassistant/package_constraints.txt
RUN pip3 install -r requirements.txt
RUN uv pip install --system -r requirements.txt
COPY requirements_test.txt requirements_test_pre_commit.txt ./
RUN pip3 install -r requirements_test.txt
RUN uv pip install --system -r requirements_test.txt
RUN rm -rf requirements.txt requirements_test.txt requirements_test_pre_commit.txt homeassistant/

# Set the default shell to bash instead of sh
Expand Down
7 changes: 4 additions & 3 deletions script/bootstrap
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set -e
cd "$(dirname "$0")/.."

echo "Installing development dependencies..."
python3 -m pip install wheel --constraint homeassistant/package_constraints.txt --upgrade
python3 -m pip install colorlog pre-commit $(grep awesomeversion requirements.txt) --constraint homeassistant/package_constraints.txt --upgrade
python3 -m pip install -r requirements_test.txt -c homeassistant/package_constraints.txt --upgrade
python3 -m pip install uv
uv pip install wheel --constraint homeassistant/package_constraints.txt --upgrade
uv pip install colorlog pre-commit $(grep awesomeversion requirements.txt) --constraint homeassistant/package_constraints.txt --upgrade
uv pip install -r requirements_test.txt -c homeassistant/package_constraints.txt --upgrade
33 changes: 22 additions & 11 deletions script/hassfest/docker.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,47 +13,58 @@

# 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"

ARG QEMU_CPU

# Set shell
SHELL ["/bin/ash", "-o", "pipefail", "-c"]
RUN curl --proto '=https' --tlsv1.2 -LsSf https://github.com/astral-sh/uv/releases/download/0.1.17/uv-installer.sh | sh

WORKDIR /usr/src

## Setup Home Assistant Core dependencies
COPY requirements.txt homeassistant/
COPY homeassistant/package_constraints.txt homeassistant/homeassistant/
RUN pip3 install uv
RUN \
pip3 install \
--only-binary=:all: \
uv pip install \
--system \
--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 --system 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 --system 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 \
--system \
--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 \
--system \
--no-build \
-r homeassistant/requirements_all.txt; \
fi

## Setup Home Assistant Core
COPY . homeassistant/
RUN \
pip3 install \
--only-binary=:all: \
uv pip install \
--system \
-e ./homeassistant \
&& python3 -m compileall \
homeassistant/homeassistant
Expand Down
2 changes: 1 addition & 1 deletion script/hassfest/requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ def install_requirements(integration: Integration, requirements: set[str]) -> bo
if is_installed:
continue

args = [sys.executable, "-m", "pip", "install", "--quiet"]
args = ["uv", "pip", "install", "--quiet"]
if install_args:
args.append(install_args)
args.append(requirement_arg)
Expand Down
3 changes: 1 addition & 2 deletions script/install_integration_requirements.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ def main() -> int | None:
requirements = gather_recursive_requirements(args.integration)

cmd = [
sys.executable,
"-m",
"uv",
"pip",
"install",
"-c",
Expand Down
4 changes: 2 additions & 2 deletions script/monkeytype
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ cd "$(dirname "$0")/.."

command -v pytest >/dev/null 2>&1 || {
echo >&2 "This script requires pytest but it's not installed." \
"Aborting. Try: pip install pytest"; exit 1; }
"Aborting. Try: uv pip install pytest"; exit 1; }

command -v monkeytype >/dev/null 2>&1 || {
echo >&2 "This script requires monkeytype but it's not installed." \
"Aborting. Try: pip install monkeytype"; exit 1; }
"Aborting. Try: uv pip install monkeytype"; exit 1; }

if [ $# -eq 0 ]
then
Expand Down
2 changes: 1 addition & 1 deletion script/setup
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fi
script/bootstrap

pre-commit install
python3 -m pip install -e . --config-settings editable_mode=compat --constraint homeassistant/package_constraints.txt
uv pip install -e . --config-settings editable_mode=compat --constraint homeassistant/package_constraints.txt
python3 -m script.translations develop --all

hass --script ensure_config -c config
Expand Down
Loading