Skip to content

Commit

Permalink
Fixed hspylib modules not being installed using venv python
Browse files Browse the repository at this point in the history
  • Loading branch information
yorevs committed Mar 6, 2025
1 parent 71dc114 commit a368f96
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 21 deletions.
8 changes: 5 additions & 3 deletions dotfiles/bash/hhsrc.bash
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ unalias -a
# The Internal Field Separator (IFS). The default value is <space><tab><newline>
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##*/}"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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 !"
Expand Down Expand Up @@ -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)))
Expand Down
38 changes: 20 additions & 18 deletions install.bash
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ usage: $APP_NAME [OPTIONS] <args>
GREEN='\033[32m'
YELLOW='\033[33m'
RED='\033[31m'
MAGENTA='\033[35m'
NC='\033[m'

touch "${INSTALL_LOG}"
Expand Down Expand Up @@ -599,6 +600,7 @@ usage: $APP_NAME [OPTIONS] <args>
configure_gtrash
configure_blesh
configure_python
install_hspylib
configure_askai_rag
;;
local)
Expand Down Expand Up @@ -842,7 +844,6 @@ usage: $APP_NAME [OPTIONS] <args>

echo -e "${GREEN}OK${NC}"
create_venv
install_hspylib
}

# Create HomeSetup virtual environment
Expand All @@ -867,16 +868,18 @@ usage: $APP_NAME [OPTIONS] <args>

# 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
Expand All @@ -885,7 +888,7 @@ usage: $APP_NAME [OPTIONS] <args>
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}"
Expand Down Expand Up @@ -927,7 +930,8 @@ usage: $APP_NAME [OPTIONS] <args>
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 !"
Expand Down Expand Up @@ -1135,7 +1139,7 @@ usage: $APP_NAME [OPTIONS] <args>
# 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
Expand All @@ -1151,16 +1155,14 @@ usage: $APP_NAME [OPTIONS] <args>
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"
Expand Down

0 comments on commit a368f96

Please sign in to comment.