Skip to content

Commit b3a2fbb

Browse files
authored
changedetection: migrate Python install to uv venv (#14995)
The update path installed into the global interpreter with a global --ignore-installed flag, which leaves the previous *.dist-info behind on every dependency bump. Duplicate metadata makes pip resolve against stale requirements (e.g. downgrading pydantic-core) and the service crashes at the next restart. Fixes the typing_extensions workaround (#13548) at the root: in a venv there are no Debian-owned packages to conflict with, so neither --ignore-installed nor --break-system-packages is needed. Follows the existing setup_uv + venv-or-migrate pattern from prometheus-pve-exporter and esphome. Existing installs are migrated automatically on the next update; the systemd unit is repointed to the venv binary. Fixes #14987
1 parent 373b138 commit b3a2fbb

2 files changed

Lines changed: 33 additions & 17 deletions

File tree

ct/changedetection.sh

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,32 @@ function update_script() {
3434

3535
NODE_VERSION="24" setup_nodejs
3636

37-
msg_info "Updating ${APP}"
38-
$STD pip3 install changedetection.io --upgrade --break-system-packages --ignore-installed typing_extensions
39-
msg_ok "Updated ${APP}"
37+
VENV_PATH="/opt/changedetection/.venv"
38+
CHANGEDETECTION_BIN="${VENV_PATH}/bin/changedetection.io"
4039

41-
msg_info "Updating Playwright"
42-
$STD pip3 install playwright --upgrade --break-system-packages
43-
msg_ok "Updated Playwright"
40+
PYTHON_VERSION="3.13" setup_uv
41+
42+
if [[ ! -d "$VENV_PATH" || ! -x "$CHANGEDETECTION_BIN" ]]; then
43+
msg_info "Migrating to uv/venv"
44+
rm -rf "$VENV_PATH"
45+
$STD uv venv --clear "$VENV_PATH"
46+
$STD "$VENV_PATH/bin/python" -m ensurepip --upgrade
47+
$STD "$VENV_PATH/bin/python" -m pip install --upgrade pip
48+
$STD "$VENV_PATH/bin/python" -m pip install changedetection.io playwright
49+
msg_ok "Migrated to uv/venv"
50+
else
51+
msg_info "Updating ${APP}"
52+
$STD "$VENV_PATH/bin/python" -m pip install --upgrade changedetection.io playwright
53+
msg_ok "Updated ${APP}"
54+
fi
55+
56+
SERVICE_FILE="/etc/systemd/system/changedetection.service"
57+
if ! grep -q "${VENV_PATH}/bin/changedetection.io" "$SERVICE_FILE"; then
58+
msg_info "Updating systemd service"
59+
sed -i "s|^ExecStart=.*|ExecStart=${VENV_PATH}/bin/changedetection.io -d /opt/changedetection -p 5000|" "$SERVICE_FILE"
60+
$STD systemctl daemon-reload
61+
msg_ok "Updated systemd service"
62+
fi
4463

4564
if [[ -f /etc/systemd/system/browserless.service ]]; then
4665
msg_info "Updating Browserless (Patience)"

install/changedetection-install.sh

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,16 @@ $STD apt-get install -y \
4343
ca-certificates
4444
msg_ok "Installed Dependencies"
4545

46-
msg_info "Setup Python3"
47-
$STD apt-get install -y \
48-
python3 \
49-
python3-dev \
50-
python3-pip
51-
rm -rf /usr/lib/python3.*/EXTERNALLY-MANAGED
52-
msg_ok "Setup Python3"
46+
PYTHON_VERSION="3.13" setup_uv
5347

5448
NODE_VERSION="24" setup_nodejs
5549

5650
msg_info "Installing Change Detection"
57-
mkdir /opt/changedetection
58-
$STD pip3 install changedetection.io
51+
mkdir -p /opt/changedetection
52+
$STD uv venv --clear /opt/changedetection/.venv
53+
$STD /opt/changedetection/.venv/bin/python -m ensurepip --upgrade
54+
$STD /opt/changedetection/.venv/bin/python -m pip install --upgrade pip
55+
$STD /opt/changedetection/.venv/bin/python -m pip install changedetection.io
5956
cat <<EOF >/opt/changedetection/.env
6057
WEBDRIVER_URL=http://127.0.0.1:4444/wd/hub
6158
PLAYWRIGHT_DRIVER_URL=ws://localhost:3000/chrome?launch=eyJkZWZhdWx0Vmlld3BvcnQiOnsiaGVpZ2h0Ijo3MjAsIndpZHRoIjoxMjgwfSwiaGVhZGxlc3MiOmZhbHNlLCJzdGVhbHRoIjp0cnVlfQ==&blockAds=true
@@ -64,7 +61,7 @@ msg_ok "Installed Change Detection"
6461

6562
msg_info "Installing Browserless & Playwright"
6663
mkdir /opt/browserless
67-
$STD python3 -m pip install playwright
64+
$STD /opt/changedetection/.venv/bin/python -m pip install playwright
6865
$STD git clone https://github.com/browserless/chrome /opt/browserless
6966
$STD npm ci --include=optional --include=dev --prefix /opt/browserless
7067
$STD /opt/browserless/node_modules/playwright-core/cli.js install --with-deps &>/dev/null
@@ -121,7 +118,7 @@ Wants=browserless.service
121118
Type=simple
122119
EnvironmentFile=/opt/changedetection/.env
123120
WorkingDirectory=/opt/changedetection
124-
ExecStart=changedetection.io -d /opt/changedetection -p 5000
121+
ExecStart=/opt/changedetection/.venv/bin/changedetection.io -d /opt/changedetection -p 5000
125122
126123
[Install]
127124
WantedBy=multi-user.target

0 commit comments

Comments
 (0)