mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-08 11:33:55 -05:00
support newer conda
pyenv-virtualenvs could not list conda environments & pyenv shell would only activate the base conda environment the conda detection criteria of testing the presence of `conda` or `activate` files under `$(pyenv root)/versions/$version/bin` appears to be the culprit, since newer environments no longer include these files: those files reside in the base conda environment - add detection criteria of `$(pyenv root)/versions/$version/conda-meta` - compute the real prefix to the base environment from `realpath $(realpath $(pyenv root)/versions/$version)/../..` - to allow that, enhance substitute `realpath` in `pyenv-virtualenvs` to reduce relative paths `.` & `..`, and factor that code out to a file under `libexec` for reuse - hook `which` to locate conda from the real prefix
This commit is contained in:
50
libexec/pyenv-virtualenv-realpath
Normal file
50
libexec/pyenv-virtualenv-realpath
Normal file
@@ -0,0 +1,50 @@
|
||||
#!/usr/bin/env bash
|
||||
# Summary: Substitute realpath if unavailable as a builtin or file
|
||||
# Usage: . pyenv-virtualenv-realpath
|
||||
|
||||
if ! {
|
||||
enable -f "${BASH_SOURCE%/*}"/../libexec/pyenv-realpath.dylib realpath ||
|
||||
type realpath
|
||||
} >/dev/null 2>&1; then
|
||||
if [ -n "$PYENV_NATIVE_EXT" ]; then
|
||||
echo "pyenv: failed to load \`realpath' builtin" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
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 "$1"
|
||||
}
|
||||
|
||||
realpath() {
|
||||
local f="$*" \
|
||||
name dir
|
||||
[[ $f ]] || {
|
||||
>&2 echo ${FUNCNAME[0]}: missing operand
|
||||
return
|
||||
}
|
||||
while [[ -L $f ]]; do
|
||||
f="$(resolve_link "$f")"
|
||||
done
|
||||
if [[ ! -d $f ]]; then
|
||||
name="/${f##*/}"
|
||||
# parent?
|
||||
dir="${f%/*}"
|
||||
if [[ $dir == $f ]]; then
|
||||
#lacks /: parent is current directory
|
||||
f="$PWD"
|
||||
else
|
||||
f="$dir"
|
||||
fi
|
||||
fi
|
||||
#absolute directory
|
||||
dir="$(cd "$f"
|
||||
pwd)"
|
||||
echo "$dir$name"
|
||||
}
|
||||
fi
|
||||
Reference in New Issue
Block a user