From a368f9698afeace5c3307b9a613bcffee5e96fe5 Mon Sep 17 00:00:00 2001 From: Hugo Saporetti Junior Date: Thu, 6 Mar 2025 17:14:50 -0300 Subject: [PATCH] Fixed hspylib modules not being installed using venv python --- dotfiles/bash/hhsrc.bash | 8 +++++--- install.bash | 38 ++++++++++++++++++++------------------ 2 files changed, 25 insertions(+), 21 deletions(-) diff --git a/dotfiles/bash/hhsrc.bash b/dotfiles/bash/hhsrc.bash index 02f81933..bf3e7db9 100644 --- a/dotfiles/bash/hhsrc.bash +++ b/dotfiles/bash/hhsrc.bash @@ -35,6 +35,8 @@ unalias -a # The Internal Field Separator (IFS). The default value is export OLDIFS="${IFS}" +export PYTHON3="${PYTHON3:-python3}" + # The following variables are not inside the bash_env because we need them in the early load process. export HHS_MY_OS="${HHS_MY_OS:-$(uname -s)}" export HHS_MY_SHELL="${SHELL##*/}" @@ -118,7 +120,7 @@ CUSTOM_DOTFILES=( source "${HHS_HOME}/dotfiles/bash/bash_commons.bash" # Re-create the HomeSetup log file. -started="$(python3 -c 'import time; print(int(time.time() * 1000))')" +started="$(${PYTHON3} -c 'import time; print(int(time.time() * 1000))')" echo -e "HomeSetup is starting: $(date)\n" >"${HHS_LOG_FILE}" # Initialization setup. @@ -270,7 +272,7 @@ if [[ ${HHS_EXPORT_SETTINGS} -eq 1 ]] && __hhs_is_venv; then # Update the settings configuration. echo "hhs.setman.database = ${HHS_SETMAN_DB_FILE}" >"${HHS_SETMAN_CONFIG_FILE}" tmp_file="$(mktemp)" - if python3 -m setman source -n hhs -f "${tmp_file}" && source "${tmp_file}"; then + if ${PYTHON3} -m setman source -n hhs -f "${tmp_file}" && source "${tmp_file}"; then __hhs_log "INFO" "System settings loaded !" else __hhs_log "ERROR" "Failed to load system settings !" @@ -367,7 +369,7 @@ if [[ -d "${HHS_MOTD_DIR}" ]]; then done fi -finished="$(python3 -c 'import time; print(int(time.time() * 1000))')" +finished="$(${PYTHON3} -c 'import time; print(int(time.time() * 1000))')" diff_time=$((finished - started)) diff_time_sec=$((diff_time/1000)) diff_time_ms=$((diff_time-(diff_time_sec*1000))) diff --git a/install.bash b/install.bash index 1368f49c..6f6887b2 100755 --- a/install.bash +++ b/install.bash @@ -70,6 +70,7 @@ usage: $APP_NAME [OPTIONS] GREEN='\033[32m' YELLOW='\033[33m' RED='\033[31m' + MAGENTA='\033[35m' NC='\033[m' touch "${INSTALL_LOG}" @@ -599,6 +600,7 @@ usage: $APP_NAME [OPTIONS] configure_gtrash configure_blesh configure_python + install_hspylib configure_askai_rag ;; local) @@ -842,7 +844,6 @@ usage: $APP_NAME [OPTIONS] echo -e "${GREEN}OK${NC}" create_venv - install_hspylib } # Create HomeSetup virtual environment @@ -867,16 +868,18 @@ usage: $APP_NAME [OPTIONS] # Activate the virtual environment echo -en "\n${python3_str} ${WHITE}Activating virtual environment... ${NC}" - if source "${HHS_VENV_PATH}"/bin/activate; then + if source "${HHS_VENV_PATH}"/bin/activate && [[ -n "${VIRTUAL_ENV}" ]]; then echo -e "${GREEN}OK${NC}" - # Python executable from venv - VENV_PYTHON3="${PYTHON3:-$(command -v python3)}" - # Pip executable from venv - VENV_PIP3="${PIP3:-${PYTHON3} -m pip}" + echo -e "\n${python3_str} ${WHITE}Virtual environment activated: ${CYAN}${VENV_PYTHON3}${NC}" else echo -e "${RED}FAILED${NC}" quit 2 "Unable to activate virtual environment!" fi + + # Python executable from venv + VENV_PYTHON3="${VIRTUAL_ENV}/bin/$(basename "${PYTHON3}")" + # Pip executable from venv + VENV_PIP3="${VENV_PYTHON3} -m pip" } # Install HomeSetup python libraries @@ -885,7 +888,7 @@ usage: $APP_NAME [OPTIONS] python3_str="${BLUE}[$(basename "${VENV_PYTHON3}")]" python_version="$(${VENV_PYTHON3} -V)" pip_version="$(${VENV_PIP3} -V | \cut -d ' ' -f1,2)" - echo -e "\n${python3_str} ${WHITE}Using ${YELLOW}v${python_version}${WHITE} and ${YELLOW}v${pip_version} from ${BLUE}\"${VENV_PYTHON3}\" ${NC}" + echo -e "\n${python3_str} ${WHITE}Using ${YELLOW}${python_version}${WHITE} and ${YELLOW}P${pip_version:1} ${WHITE}from ${BLUE}\"${VIRTUAL_ENV}\" ${NC}" echo -e "\n${python3_str} ${WHITE}Installing HSPyLib packages... \n" pkgs=$(mktemp) printf "%s\n" "${PYTHON_MODULES[@]}" >"${pkgs}" @@ -927,7 +930,8 @@ usage: $APP_NAME [OPTIONS] echo -en "\n${WHITE}Checking AI capabilities... ${CYAN}" # TODO: Uncomment when device checks are implemented # ${VENV_PYTHON3} -m askai -r rag "What is HomeSetup?" 2>&1 - ${VENV_PYTHON3} -m askai -v + ASKAI_VER=$(${VENV_PYTHON3} -m askai -v) + echo -en "[${ASKAI_VER}] " echo -e "${GREEN}OK${NC}" else quit 2 "Unable to copy HomeSetup docs into AskAI RAG directory !" @@ -1135,7 +1139,7 @@ usage: $APP_NAME [OPTIONS] # Reload the terminal and apply installed files. activate_dotfiles() { - JOB_NAME='HomeSetup restart!' source "${HOME}/.bashrc" + JOB_NAME='HomeSetup restart!' PYTHON3="${VENV_PYTHON3}" source "${HOME}/.bashrc" # Set the auto-update timestamp. if [[ "${OS_TYPE}" == "macOS" ]]; then @@ -1151,16 +1155,14 @@ usage: $APP_NAME [OPTIONS] echo '' echo -e "${GREEN}${POINTER_ICN} Done installing HomeSetup v$(cat "${INSTALL_DIR}/.VERSION") !" echo -e "${CYAN}" - echo '888 888 888 ' - echo '888 o 888 888 ' - echo '888 d8b 888 888 ' - echo '888 d888b 888 .d88b. 888 .d8888b .d88b. 88888b.d88b. .d88b. ' - echo '888d88888b888 d8P Y8b 888 d88P" d88""88b 888 "888 "88b d8P Y8b ' - echo '88888P Y88888 88888888 888 888 888 888 888 888 888 88888888 ' - echo '8888P Y8888 Y8b. 888 Y88b. Y88..88P 888 888 888 Y8b. ' - echo '888P Y888 "Y8888 888 "Y8888P "Y88P" 888 888 888 "Y8888 ' + echo "____ __ ____ _______ __ ______ ______ .___ ___. _______ " + echo "\ \ / \ / / | ____|| | / | / __ \ | \/ | | ____|" + echo " \ \/ \/ / | |__ | | | ,----'| | | | | \ / | | |__ " + echo " \ / | __| | | | | | | | | | |\/| | | __| " + echo " \ /\ / | |____ | \`----.| \`----.| \`--' | | | | | | |____ " + echo " \__/ \__/ |_______||_______| \______| \______/ |__| |__| |_______|" echo '' - echo -e "${HAND_PEACE_ICN} The ultimate Terminal experience !" + echo -e "${MAGENTA}${HAND_PEACE_ICN} The ultimate Terminal experience !" echo '' echo -e "${YELLOW}${STAR_ICN} To reload your dotfiles, type: ${WHITE}source ${HOME}/.bashrc" echo -e "${YELLOW}${STAR_ICN} To configure your HomeSetup initialization: ${WHITE}hhs setup"