Skip to content

[multi-python] Fixed the kinit path #4124

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 35 additions & 30 deletions tools/scripts/hue.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,29 @@ export SCRIPT_DIR=`dirname $0`
export HUE_HOME_DIR=$(dirname $(dirname "$SCRIPT_DIR"))

source $SCRIPT_DIR/python/python_helper.sh
PYTHON_BIN="${HUE_HOME_DIR}/$(latest_venv_bin_path)/python"
HUE="${HUE_HOME_DIR}/$(latest_venv_bin_path)/hue"
PYTHON_BIN="${VENV_BIN_PATH}/python"
HUE="${VENV_BIN_PATH}/hue"
HUE_LOGLISTENER="${HUE_HOME_DIR}/desktop/core/src/desktop/loglistener.py"

echo "Hue Environment Variables:" 1>&2
env 1>&2

function set_path() {
etpath=$(dirname $2)
if [ "$1" == "PYTHONPATH" ]; then
if [ -z ${PYTHONPATH:+x} ]; then
# Set only if PYTHONPATH is not set to allow for safety valve
export PYTHONPATH=$etpath
else
export PYTHONPATH=$PYTHONPATH:$etpath
fi
elif [ "$1" == "LD_LIBRARY_PATH" ]; then
if [ -z ${LD_LIBRARY_PATH:+x} ]; then
# Set only if LD_LIBRARY_PATH is not set to allow for safety valve
export LD_LIBRARY_PATH=$etpath
else
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$etpath
fi
elif [ "$1" == "PATH" ]; then
if [ -z ${PATH:+x} ]; then
# Set only if PATH is not set to allow for safety valve
export PATH=$etpath
else
export PATH=$PATH:$etpath
Expand Down Expand Up @@ -93,36 +97,27 @@ function set_env_var() {
}

add_postgres_to_pythonpath_for_version() {
local version="$1" # e.g. "3.8", "3.9", "3.10"
local version="${1:-$SELECTED_PYTHON_VERSION}" # Use first arg if provided, otherwise use SELECTED_PYTHON_VERSION

# If postgres engine is detected in *.ini files then check for proper psycopg2 version.
if grep -q '^\s*engine\s*=\s*postgres\+' *.ini; then
if [ -z ${LD_LIBRARY_PATH:+x} ]; then
list=("/usr/lib*" "/usr/local/lib/python${version}/*-packages" \
"/usr/lib64/python${version}/*-packages" \
"/opt/rh/rh-postgresql*/root/usr/lib64" \
"/usr/pgsql-*/lib" \
)
set_env_var "libpq.so" "LD_LIBRARY_PATH" "${list[@]}"
else
echo "LD_LIBRARY_PATH is taken from safety valve, $LD_LIBRARY_PATH"
fi

if [ -z ${PYTHONPATH:+x} ]; then
# If we've included a PSYCOPG2 for this platform, override on PYTHONPATH
list=("/usr/bin" "/opt/rh/rh-python${version//./}/root/usr/local/lib64/python${version}/site-packages" \
"/usr/local/lib/python${version}/*-packages" \
"/usr/lib64/python${version}/*-packages" \
)
set_env_var "psycopg2" "PYTHONPATH" "${list[@]}"
else
echo "PYTHONPATH is taken from safety valve, $PYTHONPATH"
fi
list=("/usr/lib*" "/usr/local/lib/python${version}/*-packages" \
"/usr/lib64/python${version}/*-packages" \
"/opt/rh/rh-postgresql*/root/usr/lib64" \
"/usr/pgsql-*/lib" \
)
set_env_var "libpq.so" "LD_LIBRARY_PATH" "${list[@]}"

list=("/usr/bin" "/opt/rh/rh-python${version//./}/root/usr/local/lib64/python${version}/site-packages" \
"/usr/local/lib/python${version}/*-packages" \
"/usr/lib64/python${version}/*-packages" \
)
set_env_var "psycopg2" "PYTHONPATH" "${list[@]}"
fi
}

add_mysql_to_pythonpath_for_version() {
local version="$1" # e.g. "3.8", "3.9", "3.10"
local version="${1:-$SELECTED_PYTHON_VERSION}" # Use first arg if provided, otherwise use SELECTED_PYTHON_VERSION

# If mysql engine is detected in *.ini files then check for proper MySQL-python version.
if grep -q '^\s*engine\s*=\s*mysql\+' *.ini; then
Expand Down Expand Up @@ -150,8 +145,8 @@ add_mysql_to_pythonpath_for_version() {
fi
}

add_postgres_to_pythonpath_for_version "$(selected_python_version)"
add_mysql_to_pythonpath_for_version "$(selected_python_version)"
add_postgres_to_pythonpath_for_version "$SELECTED_PYTHON_VERSION"
add_mysql_to_pythonpath_for_version "$SELECTED_PYTHON_VERSION"

function stop_previous_hueprocs() {
for p in $(cat /tmp/hue_${HUE_PORT}.pid); do
Expand All @@ -166,6 +161,16 @@ function run_syncdb_and_migrate_subcommands() {
"$HUE" migrate --fake-initial
}

if [[ "$1" == "kt_renewer" ]]; then
# The Kerberos ticket renewer needs to know where kinit is.
if [ -d /usr/kerberos/bin ]; then
export PATH=/usr/kerberos/bin:$PATH
fi
KINIT_PATH=`which kinit`
KINIT_PATH=${KINIT_PATH-/usr/bin/kinit}
perl -pi -e "s#\{\{KINIT_PATH}}#$KINIT_PATH#g" $HUE_CONF_DIR/*.ini
fi

if [[ "dumpdata" == "$1" ]]; then
umask 037
"$HUE" "$1" --indent 2 > "$2"
Expand Down
2 changes: 1 addition & 1 deletion tools/scripts/python/hue_py_shebang.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ export HUE_HOME_DIR=$(dirname $(dirname $(dirname "$SCRIPT_DIR")))

source $SCRIPT_DIR/python_helper.sh

PYTHON_BIN="${HUE_HOME_DIR}/$(latest_venv_bin_path)/python"
PYTHON_BIN="${VENV_BIN_PATH}/python"

exec "$PYTHON_BIN" "$@"
9 changes: 6 additions & 3 deletions tools/scripts/python/python_helper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ _python_bin_path() {
return 1
}

selected_python_version() {
_choose_python_version() {
# returns the latest py version, e.g., 3.11, 3.9 or 3.8
# if HUE_PYTHON_VERSION is set, use it
if [ -n "$HUE_PYTHON_VERSION" ]; then
Expand All @@ -87,10 +87,10 @@ selected_python_version() {
return 1
}

latest_venv_bin_path() {
_venv_path() {
# returns the path to the env/bin of the latest python,
# relative to the top-level hue directory.
local version="$(selected_python_version)"
local version="$1"

if [ -z "$version" ]; then
return 1 # Return error if no version provided/found
Expand All @@ -102,3 +102,6 @@ latest_venv_bin_path() {
echo "build/venvs/python${version}/bin"
fi
}

export SELECTED_PYTHON_VERSION="$(_choose_python_version)"
export VENV_BIN_PATH=${HUE_HOME_DIR}/$(_venv_path "$SELECTED_PYTHON_VERSION")