Skip to content

Commit 5e3483a

Browse files
authored
Use uv instead of pip in development env (home-assistant#113517)
1 parent d44f949 commit 5e3483a

File tree

9 files changed

+49
-28
lines changed

9 files changed

+49
-28
lines changed

.devcontainer/devcontainer.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"postCreateCommand": "script/setup",
66
"postStartCommand": "script/bootstrap",
77
"containerEnv": {
8-
"DEVCONTAINER": "1",
98
"PYTHONASYNCIODEBUG": "1"
109
},
1110
"features": {
@@ -29,7 +28,9 @@
2928
// Please keep this file in sync with settings in home-assistant/.vscode/settings.default.json
3029
"settings": {
3130
"python.experiments.optOutFrom": ["pythonTestAdapter"],
32-
"python.pythonPath": "/usr/local/bin/python",
31+
"python.defaultInterpreterPath": "/home/vscode/.local/ha-venv/bin/python",
32+
"python.pythonPath": "/home/vscode/.local/ha-venv/bin/python",
33+
"python.terminal.activateEnvInCurrentTerminal": true,
3334
"python.testing.pytestArgs": ["--no-cov"],
3435
"editor.formatOnPaste": false,
3536
"editor.formatOnSave": true,

.vscode/tasks.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
{
104104
"label": "Install all Requirements",
105105
"type": "shell",
106-
"command": "pip3 install -r requirements_all.txt",
106+
"command": "uv pip install -r requirements_all.txt",
107107
"group": {
108108
"kind": "build",
109109
"isDefault": true
@@ -117,7 +117,7 @@
117117
{
118118
"label": "Install all Test Requirements",
119119
"type": "shell",
120-
"command": "pip3 install -r requirements_test_all.txt",
120+
"command": "uv pip install -r requirements_test_all.txt",
121121
"group": {
122122
"kind": "build",
123123
"isDefault": true

Dockerfile.dev

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,21 +35,30 @@ RUN \
3535
&& apt-get clean \
3636
&& rm -rf /var/lib/apt/lists/*
3737

38+
# Install uv
39+
RUN pip3 install uv
40+
3841
WORKDIR /usr/src
3942

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

44-
WORKDIR /workspaces
47+
USER vscode
48+
ENV VIRTUAL_ENV="/home/vscode/.local/ha-venv"
49+
RUN uv venv $VIRTUAL_ENV
50+
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
51+
52+
WORKDIR /tmp
4553

4654
# Install Python dependencies from requirements
4755
COPY requirements.txt ./
4856
COPY homeassistant/package_constraints.txt homeassistant/package_constraints.txt
49-
RUN pip3 install -r requirements.txt
57+
RUN uv pip install -r requirements.txt
5058
COPY requirements_test.txt requirements_test_pre_commit.txt ./
51-
RUN pip3 install -r requirements_test.txt
52-
RUN rm -rf requirements.txt requirements_test.txt requirements_test_pre_commit.txt homeassistant/
59+
RUN uv pip install -r requirements_test.txt
60+
61+
WORKDIR /workspaces
5362

5463
# Set the default shell to bash instead of sh
5564
ENV SHELL /bin/bash

script/bootstrap

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,6 @@ set -e
77
cd "$(dirname "$0")/.."
88

99
echo "Installing development dependencies..."
10-
python3 -m pip install wheel --constraint homeassistant/package_constraints.txt --upgrade
11-
python3 -m pip install colorlog $(grep awesomeversion requirements.txt) --constraint homeassistant/package_constraints.txt --upgrade
12-
python3 -m pip install -r requirements_test.txt -c homeassistant/package_constraints.txt --upgrade
10+
uv pip install wheel --constraint homeassistant/package_constraints.txt --upgrade
11+
uv pip install colorlog $(grep awesomeversion requirements.txt) --constraint homeassistant/package_constraints.txt --upgrade
12+
uv pip install -r requirements_test.txt -c homeassistant/package_constraints.txt --upgrade

script/hassfest/requirements.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ def install_requirements(integration: Integration, requirements: set[str]) -> bo
268268
if is_installed:
269269
continue
270270

271-
args = [sys.executable, "-m", "pip", "install", "--quiet"]
271+
args = ["uv", "pip", "install", "--quiet"]
272272
if install_args:
273273
args.append(install_args)
274274
args.append(requirement_arg)

script/install_integration_requirements.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ def main() -> int | None:
3232
requirements = gather_recursive_requirements(args.integration)
3333

3434
cmd = [
35-
sys.executable,
36-
"-m",
35+
"uv",
3736
"pip",
3837
"install",
3938
"-c",

script/monkeytype

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@ cd "$(dirname "$0")/.."
88

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

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

1717
if [ $# -eq 0 ]
1818
then

script/run-in-env.sh

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,18 @@ if [ -s .python-version ]; then
1313
export PYENV_VERSION
1414
fi
1515

16-
# other common virtualenvs
17-
my_path=$(git rev-parse --show-toplevel)
16+
if [ -n "${VIRTUAL_ENV}" ] && [ -f "${VIRTUAL_ENV}/bin/activate" ]; then
17+
. "${VIRTUAL_ENV}/bin/activate"
18+
else
19+
# other common virtualenvs
20+
my_path=$(git rev-parse --show-toplevel)
1821

19-
for venv in venv .venv .; do
20-
if [ -f "${my_path}/${venv}/bin/activate" ]; then
21-
. "${my_path}/${venv}/bin/activate"
22-
break
23-
fi
24-
done
22+
for venv in venv .venv .; do
23+
if [ -f "${my_path}/${venv}/bin/activate" ]; then
24+
. "${my_path}/${venv}/bin/activate"
25+
break
26+
fi
27+
done
28+
fi
2529

2630
exec "$@"

script/setup

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,23 @@ fi
1616

1717
mkdir -p config
1818

19-
if [ ! -n "$DEVCONTAINER" ] && [ ! -n "$VIRTUAL_ENV" ];then
20-
python3 -m venv venv
19+
if [ ! -n "$VIRTUAL_ENV" ]; then
20+
if [ -x "$(command -v uv)" ]; then
21+
uv venv venv
22+
else
23+
python3 -m venv venv
24+
fi
2125
source venv/bin/activate
2226
fi
2327

28+
if ! [ -x "$(command -v uv)" ]; then
29+
python3 -m pip install uv
30+
fi
31+
2432
script/bootstrap
2533

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

3038
hass --script ensure_config -c config

0 commit comments

Comments
 (0)