From 1e8d7baa54b9ed39885e11ae8e40201e7147e28c Mon Sep 17 00:00:00 2001 From: j4n Date: Thu, 11 Jun 2026 07:55:58 +0200 Subject: [PATCH] fix(cmdeploy): check venv python versions and purge if mismatched `cmdeploy run` fails after system upgrade to Debian 13 with "Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding" , indicating a Python version missmatch. Check for both versions and remove old `remote_venv_dir` on mismatch to allow clean reinitialization by subsequent pip.virtualenv(). --- cmdeploy/src/cmdeploy/deployers.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/cmdeploy/src/cmdeploy/deployers.py b/cmdeploy/src/cmdeploy/deployers.py index 0555d3a0..eebaf323 100644 --- a/cmdeploy/src/cmdeploy/deployers.py +++ b/cmdeploy/src/cmdeploy/deployers.py @@ -102,6 +102,23 @@ def _install_remote_venv_with_chatmaild(deployer) -> None: dest=remote_dist_file, ) + # Remove venv if its Python major.minor doesn't match the system Python + server.shell( + name="remove stale chatmaild venv if python version changed", + commands=[ + "\n".join( + [ + r"re='[0-9]+\.[0-9]+'", # major.minor out of 'Python X.Y.Z' + 'sys_version=$(python3 --version 2>/dev/null | grep -oE "$re")', + f'venv_version=$({remote_venv_dir}/bin/python --version 2>/dev/null | grep -oE "$re")', + # an empty sys_version means we could not tell: keep the venv + f'[ -z "$sys_version" ] || [ "$sys_version" = "$venv_version" ] ' + f"|| rm -rf {remote_venv_dir}", + ] + ) + ], + ) + pip.virtualenv( name=f"chatmaild virtualenv {remote_venv_dir}", path=remote_venv_dir,