From a77175b7cade597faf4bde54942d821bd403ee85 Mon Sep 17 00:00:00 2001 From: carnivorecookies Date: Mon, 27 Oct 2025 17:34:56 -0400 Subject: [PATCH] Detect pyenv python installations, and ignore (presumed) python installations that don't have semver formatting. Before, an executable with a name like `python-config` would be detected as python, and it would be assumed that `python-config --version` would return a version in the form of `X.XX.X`. However, this is not always the case with custom commands. Additionally, pyenv installations were not detected, which is common on some systems that only have one python version in their repo. Signed-off-by: carnivorecookies --- boot/bootloader.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/boot/bootloader.py b/boot/bootloader.py index a58b0a6e..a760337e 100644 --- a/boot/bootloader.py +++ b/boot/bootloader.py @@ -147,7 +147,12 @@ def check_for_python(path, found=None, venv=False): except: continue - major, minor, patch = versiontext.split('.') + versionparts = versiontext.split('.') + # file may not be a python executable + if len(versionparts) < 3: + continue + + major, minor, patch = versionparts if not patch.isdigit(): fixed = '' @@ -257,6 +262,10 @@ def check_for_python(path, found=None, venv=False): installed.extend(check_for_python('/usr/bin') or []) installed.extend(check_for_python('/usr/local/bin', found=installed) or []) + pyenv_shims = os.path.expanduser('~/.pyenv/shims') + if os.path.exists(pyenv_shims): + installed.extend(check_for_python(pyenv_shims, found=installed) or []) + if os.path.exists('/Library/Frameworks/Python.framework/Versions'): for item in os.listdir('/Library/Frameworks/Python.framework/Versions'): installed.extend(check_for_python(f'/Library/Frameworks/Python.framework/Versions/{item}/bin', found=installed) or [])