From 56c232610ab44feffef40513c33fbbed22f07034 Mon Sep 17 00:00:00 2001 From: Yamashita Yuu Date: Tue, 29 Apr 2014 00:51:57 +0900 Subject: [PATCH] Check the usage of virtualenv(s) before the uninstallation of versions --- etc/pyenv.d/uninstall/virtualenv.bash | 25 +++++++++++++++++++++++++ install.sh | 3 +++ 2 files changed, 28 insertions(+) create mode 100644 etc/pyenv.d/uninstall/virtualenv.bash diff --git a/etc/pyenv.d/uninstall/virtualenv.bash b/etc/pyenv.d/uninstall/virtualenv.bash new file mode 100644 index 0000000..0146001 --- /dev/null +++ b/etc/pyenv.d/uninstall/virtualenv.bash @@ -0,0 +1,25 @@ +VERSION_NAME="${DEFINITION##*/}" +PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}" + +if ! pyenv-virtualenv-prefix "${VERSION_NAME}" 1>/dev/null 2>&1; then + OLDIFS="$IFS" + IFS=$'\n' virtualenvs=($(pyenv-virtualenvs --bare)) + IFS="$OLDIFS" + + declare -a dependencies + for venv in "${virtualenvs[@]}"; do + venv_prefix="$(pyenv-virtualenv-prefix "${venv}" 2>/dev/null || true)" + if [ -d "${venv_prefix}" ] && [ "${PREFIX}" = "${venv_prefix}" ]; then + dependencies[${#dependencies[*]}]="${venv}" + fi + done + + if [ -z "$FORCE" ] && [ -n "$dependencies" ]; then + echo "pyenv: ${#dependencies[@]} virtualenv(s) is depending on $PREFIX." >&2 + read -p "continue with uninstallation? (y/N) " + case "$REPLY" in + y* | Y* ) ;; + * ) exit 1 ;; + esac + fi +fi diff --git a/install.sh b/install.sh index 1608daf..d3a19fc 100755 --- a/install.sh +++ b/install.sh @@ -12,7 +12,10 @@ if [ -z "${PREFIX}" ]; then fi BIN_PATH="${PREFIX}/bin" +ETC_PATH="${PREFIX}/etc/pyenv.d" mkdir -p "$BIN_PATH" +mkdir -p "$ETC_PATH" install -p bin/* "$BIN_PATH" +cp -RPp etc/pyenv.d/* "$ETC_PATH"