From 237938ba9abef63f521cce138a1259dbf2045f01 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Wed, 9 Feb 2022 09:31:02 +0100 Subject: [PATCH] Fixing creation of virtual environment in update-env.sh --- requirements.txt | 1 - update-env.sh | 54 +++++++++++++++++++++++++----------------------- 2 files changed, 28 insertions(+), 27 deletions(-) diff --git a/requirements.txt b/requirements.txt index db5cbc8..1b1fd35 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,6 +1,5 @@ fb_logging fb_tools -ansible ldap3 PyYAML tzlocal diff --git a/update-env.sh b/update-env.sh index 3bc2b8b..b707648 100755 --- a/update-env.sh +++ b/update-env.sh @@ -28,7 +28,6 @@ export VIRTUAL_ENV_DISABLE_PROMPT=y declare -a VALID_PY_VERSIONS=("3.9" "3.8" "3.7" "3.6" "3.5") PY_VERSION_FINAL= PYTHON= -VENV_BIN='virtualenv' #------------------------------------------------------------------- detect_color() { @@ -127,6 +126,22 @@ error() { fi } +#------------------------------------------------------------------------------ +RM() { + + local cmd="rm $*" + if [[ "${VERBOSE}" == "y" ]] ; then + cmd="rm --verbose $*" + fi + debug "Executing: ${cmd}" + if [[ "${VERBOSE}" != "y" ]] ; then + rm "$@" + else + rm --verbose "$@" + fi + +} + #------------------------------------------------------------------------------ description() { cat <<-EOF @@ -278,26 +293,6 @@ get_options() { exit 5 fi - info "Searching for valid virtualenv …" - VENV_BIN="virtualenv-${PY_VERSION_FINAL}" - debug "Testing '${VENV_BIN}' …" - if type -t "${VENV_BIN}" >/dev/null ; then - : - else - VENV_BIN="virtualenv" - debug "Testing '${VENV_BIN}' …" - if type -t "${VENV_BIN}" >/dev/null ; then - : - 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 @@ -324,13 +319,20 @@ init_venv() { if [[ ! -f venv/bin/activate ]] ; then - empty_line - if [[ "${VENV_BIN}" == 'virtualenv' ]] ; then - virtualenv --python="${PYTHON}" venv - else - ${VENV_BIN} venv + if [[ -e 'venv' ]] ; then + if [[ -d 'venv' ]] ; then + info "Removing directory '${CYAN}venv${NORMAL}' ..." + RM -r 'venv' + else + error "Path '${RED}venv${NORMAL}' exists, but is not a directory." + exit 11 + fi fi + empty_line + info "Creating virtual environment in '${CYAN}venv${NORMAL}' ..." + "${PYTHON}" -m venv venv + fi # shellcheck disable=SC1091 -- 2.39.5