From 5b9245ca108376dae8acc78970245fafaae98f4f Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Mon, 4 Apr 2022 16:21:25 +0200 Subject: [PATCH] Updating Python environment in requirements.txt and update-env.sh --- requirements.txt | 1 - update-env.sh | 139 +++++++++++++++++------------------------------ 2 files changed, 50 insertions(+), 90 deletions(-) diff --git a/requirements.txt b/requirements.txt index 8116824..043e2f0 100644 --- a/requirements.txt +++ b/requirements.txt @@ -8,7 +8,6 @@ paramiko dnspython flake8 docker-py -pathlib fb_logging fb_tools Babel diff --git a/update-env.sh b/update-env.sh index cee6295..9f3a154 100755 --- a/update-env.sh +++ b/update-env.sh @@ -7,31 +7,26 @@ VERBOSE="n" DEBUG="n" QUIET='n' -VERSION="2.1" +VERSION="2.4" # console colors: RED="" YELLOW="" GREEN="" -BLUE="" +# BLUE="" CYAN="" NORMAL="" -HAS_TTY='y' - -BASENAME="$(basename ${0})" -BASE_DIR=$( dirname $0 ) -cd ${BASE_DIR} +BASENAME=$( basename "${0}" ) +BASE_DIR=$( dirname "$0" ) +cd "${BASE_DIR}" BASE_DIR=$( readlink -f . ) +declare -a VALID_PY_VERSIONS=("3.10" "3.9" "3.8" "3.7" "3.6") + PIP_OPTIONS= export VIRTUAL_ENV_DISABLE_PROMPT=y -declare -a VALID_PY_VERSIONS=("3.8" "3.7" "3.6" "3.5") -PY_VERSION_FINAL= -PYTHON= -VENV_BIN='virtualenv' - #------------------------------------------------------------------- detect_color() { @@ -41,16 +36,17 @@ detect_color() { local term= if [[ -f ~/.dir_colors ]] ; then - match_lhs="${match_lhs}$( cat ~/.dir_colors | grep '^TERM ' | sed -e 's/^TERM *//' -e 's/ .*//')" + match_lhs="${match_lhs}$( grep '^TERM ' ~/.dir_colors | sed -e 's/^TERM *//' -e 's/ .*//')" fi if [[ -f /etc/DIR_COLORS ]] ; then - match_lhs="${match_lhs}$( cat /etc/DIR_COLORS | grep '^TERM ' | sed -e 's/^TERM *//' -e 's/ .*//')" + match_lhs="${match_lhs}$( grep '^TERM ' /etc/DIR_COLORS | sed -e 's/^TERM *//' -e 's/ .*//')" fi if [[ -z ${match_lhs} ]] ; then type -P dircolors >/dev/null && \ match_lhs=$(dircolors --print-database | grep '^TERM ' | sed -e 's/^TERM *//' -e 's/ .*//') fi for term in ${match_lhs} ; do + # shellcheck disable=SC2053 if [[ "${safe_term}" == ${term} || "${TERM}" == ${term} ]] ; then use_color="true" break @@ -62,31 +58,28 @@ detect_color() { RED="\033[38;5;196m" YELLOW="\033[38;5;226m" GREEN="\033[38;5;46m" - BLUE="\033[38;5;27m" + # BLUE="\033[38;5;27m" CYAN="\033[38;5;36m" NORMAL="\033[39m" - HAS_COLORS="y" else RED="" YELLOW="" GREEN="" - BLUE="" + # BLUE="" CYAN="" NORMAL="" fi - local my_tty=$(tty) + local my_tty + my_tty=$( tty ) if [[ "${my_tty}" =~ 'not a tty' ]] ; then my_tty='-' fi - if [[ "${my_tty}" = '-' || "${safe_term}" = "dump" ]] ; then - HAS_TTY='n' - fi - } detect_color +#------------------------------------------------------------------------------ my_date() { date +'%F %T.%N %:::z' } @@ -96,7 +89,7 @@ debug() { if [[ "${VERBOSE}" != "y" ]] ; then return 0 fi - echo -e " * [$(my_date)] [${BASENAME}:${CYAN}DEBUG${NORMAL}]: $@" >&2 + echo -e " * [$(my_date)] [${BASENAME}:${CYAN}DEBUG${NORMAL}]: $*" >&2 } #------------------------------------------------------------------------------ @@ -105,27 +98,27 @@ info() { return 0 fi if [[ "${VERBOSE}" == "y" ]] ; then - echo -e " ${GREEN}*${NORMAL} [$(my_date)] [${BASENAME}:${GREEN}INFO${NORMAL}] : $@" + echo -e " ${GREEN}*${NORMAL} [$(my_date)] [${BASENAME}:${GREEN}INFO${NORMAL}] : $*" else - echo -e " ${GREEN}*${NORMAL} $@" + echo -e " ${GREEN}*${NORMAL} $*" fi } #------------------------------------------------------------------------------ warn() { if [[ "${VERBOSE}" == "y" ]] ; then - echo -e " ${YELLOW}*${NORMAL} [$(my_date)] [${BASENAME}:${YELLOW}WARN${NORMAL}] : $@" >&2 + echo -e " ${YELLOW}*${NORMAL} [$(my_date)] [${BASENAME}:${YELLOW}WARN${NORMAL}] : $*" >&2 else - echo -e " ${YELLOW}*${NORMAL} [${BASENAME}:${YELLOW}WARN${NORMAL}] : $@" >&2 + echo -e " ${YELLOW}*${NORMAL} [${BASENAME}:${YELLOW}WARN${NORMAL}] : $*" >&2 fi } #------------------------------------------------------------------------------ error() { if [[ "${VERBOSE}" == "y" ]] ; then - echo -e " ${RED}*${NORMAL} [$(my_date)] [${BASENAME}:${RED}ERROR${NORMAL}]: $@" >&2 + echo -e " ${RED}*${NORMAL} [$(my_date)] [${BASENAME}:${RED}ERROR${NORMAL}]: $*" >&2 else - echo -e " ${RED}*${NORMAL} [${BASENAME}:${RED}ERROR${NORMAL}]: $@" >&2 + echo -e " ${RED}*${NORMAL} [${BASENAME}:${RED}ERROR${NORMAL}]: $*" >&2 fi } @@ -180,13 +173,11 @@ get_options() { local tmp= local short_options="dvqhV" local long_options="debug,verbose,quiet,help,version" - local venv_found="n" - local py_version= - local py_found="n" set +e tmp=$( getopt -o "${short_options}" --long "${long_options}" -n "${BASENAME}" -- "$@" ) - if [[ $? != 0 ]] ; then + ret="$?" + if [[ "${ret}" != 0 ]] ; then echo "" >&2 usage >&2 exit 1 @@ -211,20 +202,18 @@ get_options() { RED="" YELLOW="" GREEN="" - BLUE="" + # BLUE="" CYAN="" NORMAL="" - HAS_COLORS="n" shift ;; --nocolor) RED="" YELLOW="" GREEN="" - BLUE="" + # BLUE="" CYAN="" NORMAL="" - HAS_COLORS="n" shift ;; -h|--help) @@ -257,49 +246,6 @@ get_options() { exit 1 fi - py_found="n" - info "Searching for valid Python …" - for py_version in "${VALID_PY_VERSIONS[@]}" ; do - PYTHON="python${py_version}" - debug "Testing Python binary '${CYAN}${PYTHON}${NORMAL}' …" - if type -t ${PYTHON} >/dev/null ; then - py_found="y" - PY_VERSION_FINAL="${py_version}" - empty_line - info "Found '${GREEN}${PYTHON}${NORMAL}'." - break - fi - done - - if [[ "${py_found}" == "n" ]] ; then - empty_line >&2 - error "Did not found a usable Python version." >&2 - error "Usable Python versions are: ${YELOW}${VALID_PY_VERSIONS[*]}${NORMAL}." >&2 - empty_line >&2 - exit 5 - fi - - venv_found="n" - info "Searching for valid virtualenv …" - VENV_BIN="virtualenv-${PY_VERSION_FINAL}" - debug "Testing '${VENV_BIN}' …" - if type -t ${VENV_BIN} >/dev/null ; then - venv_found="y" - else - VENV_BIN="virtualenv" - debug "Testing '${VENV_BIN}' …" - if type -t ${VENV_BIN} >/dev/null ; then - venv_found="y" - else - empty_line >&2 - error "Did not found a usable virtualenv." >&2 - error "Command '${RED}virtualenv${NORMAL}' not found, please install package '${YELLOW}python-virtualenv${NORMAL}' or appropriate." - empty_line >&2 - exit 6 - fi - fi - info "Found '${GREEN}${VENV_BIN}${NORMAL}'." - if type -t msgfmt >/dev/null ; then : else @@ -318,6 +264,10 @@ get_options() { #------------------------------------------------------------------------------ init_venv() { + local py_version= + local python= + local found="n" + empty_line line info "Preparing virtual environment …" @@ -325,19 +275,30 @@ init_venv() { if [[ ! -f venv/bin/activate ]] ; then - - empty_line - if [[ "${VENV_BIN}" == 'virtualenv' ]] ; then - virtualenv --python=${PYTHON} venv - else - ${VENV_BIN} venv + found="n" + for py_version in "${VALID_PY_VERSIONS[@]}" ; do + python="python${py_version}" + debug "Testing Python binary '${CYAN}${python}${NORMAL}' …" + if type -t "${python}" >/dev/null ; then + found="y" + empty_line + info "Found '${GREEN}${python}${NORMAL}'." + empty_line + "${python}" -m venv venv + break + fi + done + if [[ "${found}" == "n" ]] ; then + empty_line >&2 + error "Did not found a usable Python version." >&2 + error "Usable Python versions are: ${YELLOW}${VALID_PY_VERSIONS[*]}${NORMAL}." >&2 + empty_line >&2 + exit 5 fi - fi + # shellcheck disable=SC1091 . venv/bin/activate || exit 5 - debug "Which pip: $(which pip)" - debug "Which python: $(which python)" } -- 2.39.5