@@ -10,24 +10,63 @@ PACKAGE_ROOT="$(dirname "$SCRIPT_DIR")"
1010export HYPRWHSPR_ROOT=" $PACKAGE_ROOT "
1111export PYTHONPATH=" $PACKAGE_ROOT /lib:$PYTHONPATH "
1212
13+ # Find system Python, avoiding mise/pyenv/asdf managed versions
14+ # CLI commands use system Python since deps are installed via package manager
15+ get_system_python () {
16+ # Check common system Python paths across distros
17+ for py in /usr/bin/python3 /usr/bin/python /usr/local/bin/python3 /usr/local/bin/python; do
18+ if [ -x " $py " ]; then
19+ echo " $py "
20+ return 0
21+ fi
22+ done
23+ # No system Python found
24+ return 1
25+ }
26+
27+ # Check if mise/pyenv/asdf is active
28+ is_version_manager_active () {
29+ # Check for mise
30+ [[ -n " $MISE_SHELL " || -n " $__MISE_ACTIVATE " || -n " $MISE_DATA_DIR " ]] && return 0
31+ # Check for pyenv
32+ [[ -n " $PYENV_ROOT " && " $PATH " == * " $PYENV_ROOT " * ]] && return 0
33+ # Check for asdf
34+ [[ -n " $ASDF_DIR " && " $PATH " == * " $ASDF_DIR " * ]] && return 0
35+ return 1
36+ }
37+
38+ # Determine which Python to use for CLI commands
39+ # Use system Python when version manager is active (deps are in system packages)
40+ if is_version_manager_active; then
41+ CLI_PYTHON=" $( get_system_python) "
42+ if [[ -z " $CLI_PYTHON " ]]; then
43+ echo " Error: Version manager detected but no system Python found." >&2
44+ echo " hyprwhspr requires system Python with distro packages (python3-rich, etc.)." >&2
45+ echo " Please install Python via your package manager or temporarily deactivate your version manager." >&2
46+ exit 1
47+ fi
48+ else
49+ CLI_PYTHON=" python3"
50+ fi
51+
1352# Find venv Python (for main app execution)
1453VENV_PYTHON=" ${XDG_DATA_HOME:- $HOME / .local/ share} /hyprwhspr/venv/bin/python"
1554if [ -f " $VENV_PYTHON " ]; then
1655 PYTHON_CMD=" $VENV_PYTHON "
1756else
1857 # Fallback to system Python if venv doesn't exist
19- PYTHON_CMD=" python3 "
58+ PYTHON_CMD=" $CLI_PYTHON "
2059fi
2160
2261# Help handling: route any -h/--help or leading "help" to CLI help
2362for arg in " $@ " ; do
2463 if [[ " $arg " == " -h" || " $arg " == " --help" ]]; then
25- exec python3 " $PACKAGE_ROOT /lib/cli.py" --help
64+ exec " $CLI_PYTHON " " $PACKAGE_ROOT /lib/cli.py" --help
2665 fi
2766done
2867
2968if [[ " $1 " == " help" ]]; then
30- exec python3 " $PACKAGE_ROOT /lib/cli.py" --help
69+ exec " $CLI_PYTHON " " $PACKAGE_ROOT /lib/cli.py" --help
3170fi
3271
3372# Subcommands: route to CLI if recognized
@@ -36,7 +75,7 @@ if [[ "$1" == "test" ]]; then
3675 exec " $PYTHON_CMD " " $PACKAGE_ROOT /lib/cli.py" " $@ "
3776fi
3877if [[ " $1 " =~ ^(setup| install| config| waybar| systemd| status| model| validate| uninstall| backend| state| mic-osd| keyboard)$ ]]; then
39- exec python3 " $PACKAGE_ROOT /lib/cli.py" " $@ "
78+ exec " $CLI_PYTHON " " $PACKAGE_ROOT /lib/cli.py" " $@ "
4079fi
4180
4281# Set up CUDA library path if CUDA is installed
0 commit comments