From 41f0b911cff79cad34824640ac9a633832420c17 Mon Sep 17 00:00:00 2001 From: orent Date: Wed, 31 Mar 2021 09:32:45 +0300 Subject: [PATCH 1/2] Remove unnecessary special cases for bash/zsh The internal shell utility hash is standard posix. There is no need to special-case it only for bash and zsh. In fact, this check can break the script on shells such as the built-in sh on BSD systems, ksh, ash or busybox sh which are otherwise perfectly capable of running it. The script is a valid posix shell script, as verified by shellcheck. The one feature that depends on bash (checking that the script is sourced rather than executed) will work only on bash, but it is only a safety check. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/hash.html --- src/virtualenv/activation/bash/activate.sh | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/virtualenv/activation/bash/activate.sh b/src/virtualenv/activation/bash/activate.sh index 4981be123..7380ecf3e 100644 --- a/src/virtualenv/activation/bash/activate.sh +++ b/src/virtualenv/activation/bash/activate.sh @@ -23,12 +23,10 @@ deactivate () { unset _OLD_VIRTUAL_PYTHONHOME fi - # This should detect bash and zsh, which have a hash command that must - # be called to get it to forget past commands. Without forgetting - # past commands the $PATH changes we made may not be respected - if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then - hash -r 2>/dev/null - fi + # The hash command must be called to get it to forget past + # commands. Without forgetting past commands the $PATH changes + # we made may not be respected + hash -r 2>/dev/null if ! [ -z "${_OLD_VIRTUAL_PS1+_}" ] ; then PS1="$_OLD_VIRTUAL_PS1" @@ -79,9 +77,7 @@ pydoc () { python -m pydoc "$@" } -# This should detect bash and zsh, which have a hash command that must -# be called to get it to forget past commands. Without forgetting -# past commands the $PATH changes we made may not be respected -if [ -n "${BASH-}" ] || [ -n "${ZSH_VERSION-}" ] ; then - hash -r 2>/dev/null -fi +# The hash command must be called to get it to forget past +# commands. Without forgetting past commands the $PATH changes +# we made may not be respected +hash -r 2>/dev/null From c097017f1d69b37d139ed4f43ecba2a0760c84b1 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 31 Mar 2021 06:34:47 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/virtualenv/activation/bash/activate.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/virtualenv/activation/bash/activate.sh b/src/virtualenv/activation/bash/activate.sh index 7380ecf3e..dd7956ef3 100644 --- a/src/virtualenv/activation/bash/activate.sh +++ b/src/virtualenv/activation/bash/activate.sh @@ -24,7 +24,7 @@ deactivate () { fi # The hash command must be called to get it to forget past - # commands. Without forgetting past commands the $PATH changes + # commands. Without forgetting past commands the $PATH changes # we made may not be respected hash -r 2>/dev/null @@ -78,6 +78,6 @@ pydoc () { } # The hash command must be called to get it to forget past -# commands. Without forgetting past commands the $PATH changes +# commands. Without forgetting past commands the $PATH changes # we made may not be respected hash -r 2>/dev/null