Skip to content

Commit

Permalink
Use realpath of scripts to determine relative locations (#308)
Browse files Browse the repository at this point in the history
Just using paths relative to ${BASH_SOURCE} to access `libexec`
fails if the scripts are symlinked to a location,
such as when installed with Homebrew,
since the `libexec` directory is not linked into `brew --prefix`.

Implement a simple version of `realpath`
and run `${BASH_SOURCE}` through it.
This gets the actual installation directory
relative to which `libexec` is located.

Co-authored-by: Andrew Christianson <achristianson@edmunds.com>
  • Loading branch information
andrew-christianson and Andrew Christianson authored Oct 14, 2022
1 parent 633711a commit c4de255
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
16 changes: 15 additions & 1 deletion bin/pyenv-virtualenv-prefix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,21 @@

set -e
[ -n "$PYENV_DEBUG" ] && set -x
. "${BASH_SOURCE%/*}"/../libexec/pyenv-virtualenv-realpath
if [ -L "${BASH_SOURCE}" ]; then
READLINK=$(type -p greadlink readlink | head -1)
if [ -z "$READLINK" ]; then
echo "pyenv: cannot find readlink - are you missing GNU coreutils?" >&2
exit 1
fi
resolve_link() {
$READLINK -f "$1"
}
script_path=$(resolve_link ${BASH_SOURCE})
else
script_path=${BASH_SOURCE}
fi

. ${script_path%/*}/../libexec/pyenv-virtualenv-realpath

if [ -z "$PYENV_ROOT" ]; then
PYENV_ROOT="${HOME}/.pyenv"
Expand Down
16 changes: 15 additions & 1 deletion bin/pyenv-virtualenvs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,21 @@

set -e
[ -n "$PYENV_DEBUG" ] && set -x
. "${BASH_SOURCE%/*}"/../libexec/pyenv-virtualenv-realpath
if [ -L "${BASH_SOURCE}" ]; then
READLINK=$(type -p greadlink readlink | head -1)
if [ -z "$READLINK" ]; then
echo "pyenv: cannot find readlink - are you missing GNU coreutils?" >&2
exit 1
fi
resolve_link() {
$READLINK -f "$1"
}
script_path=$(resolve_link ${BASH_SOURCE})
else
script_path=${BASH_SOURCE}
fi

. ${script_path%/*}/../libexec/pyenv-virtualenv-realpath

if [ -z "$PYENV_ROOT" ]; then
PYENV_ROOT="${HOME}/.pyenv"
Expand Down

0 comments on commit c4de255

Please sign in to comment.