mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-10 12:33:54 -05:00
enable creating virtualenv based on "system" python.
*NOTE* change first argument of python-virtualenv to path to the python executable, not a prefix of python installation.
This commit is contained in:
@@ -53,9 +53,31 @@ for script in $(pyenv-hooks virtualenv); do
|
||||
source "$script"
|
||||
done
|
||||
|
||||
PYTHON_PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}"
|
||||
PYTHON_BIN=$(PYENV_VERSION="${VERSION_NAME}" pyenv-which python)
|
||||
if [ ! -x "${PYTHON_BIN}" ]; then
|
||||
echo "pyenv-virtualenv: could not obtain python executable: ${PYTHON_BIN}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# find canonical name of python executable.
|
||||
# virtualenv will create "bin/python" executable as same name as its bootstraped python.
|
||||
if [ -L "${PYTHON_BIN}" ]; then
|
||||
while [ -L "${PYTHON_BIN}" ]; do # retrieve symlinks
|
||||
PYTHON_BIN="$(dirname "${PYTHON_BIN}")/$(resolve_link "${PYTHON_BIN}")"
|
||||
done
|
||||
else
|
||||
# python 2.6 and older don't have "bin/python" as symlink.
|
||||
# so we must traverse files like "bin/python*" to obtain canonical name.
|
||||
for python in ${PYENV_ROOT}/versions/${VERSION_NAME}/bin/python*; do
|
||||
if ( basename "$python" | grep '^python[0-9][0-9]*\.[0-9][0-9]*$' && cmp "$PYTHON_BIN" "$python" ) >/dev/null; then
|
||||
PYTHON_BIN="${python}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
VIRTUALENV_NAME="${ARGUMENTS[1]##*/}"
|
||||
VIRTUALENV_PATH="${PYENV_ROOT}/versions/${VIRTUALENV_NAME}"
|
||||
|
||||
python-virtualenv $VERBOSE "${VIRTUALENV_OPTIONS[@]}" "$PYTHON_PREFIX" "$VIRTUALENV_PATH"
|
||||
python-virtualenv $VERBOSE "${VIRTUALENV_OPTIONS[@]}" "$PYTHON_BIN" "$VIRTUALENV_PATH"
|
||||
pyenv rehash
|
||||
|
||||
@@ -30,19 +30,11 @@ lib() {
|
||||
done
|
||||
}
|
||||
|
||||
if [ "$1" == "--$FUNCNAME" ]; then
|
||||
declare -f "$FUNCNAME"
|
||||
echo "$FUNCNAME \"\$1\";"
|
||||
exit
|
||||
fi
|
||||
}
|
||||
lib "$1"
|
||||
|
||||
resolve_link() {
|
||||
resolve_link() {
|
||||
$(type -p greadlink readlink | head -1) "$1"
|
||||
}
|
||||
}
|
||||
|
||||
abs_dirname() {
|
||||
abs_dirname() {
|
||||
local cwd="$(pwd)"
|
||||
local path="$1"
|
||||
|
||||
@@ -54,7 +46,15 @@ abs_dirname() {
|
||||
|
||||
pwd
|
||||
cd "$cwd"
|
||||
}
|
||||
|
||||
if [ "$1" == "--$FUNCNAME" ]; then
|
||||
declare -f "$FUNCNAME"
|
||||
echo "$FUNCNAME \"\$1\";"
|
||||
exit
|
||||
fi
|
||||
}
|
||||
lib "$1"
|
||||
|
||||
version() {
|
||||
echo "python-virtualenv ${PYTHON_VIRTUALENV_VERSION}"
|
||||
@@ -99,11 +99,11 @@ for option in "${OPTIONS[@]}"; do
|
||||
esac
|
||||
done
|
||||
|
||||
PYTHON_PREFIX="${ARGUMENTS[0]}"
|
||||
if [ -z "$PYTHON_PREFIX" ]; then
|
||||
PYTHON_BIN="${ARGUMENTS[0]}"
|
||||
if [ -z "${PYTHON_BIN}" ]; then
|
||||
usage
|
||||
elif [ ! -x "${PYTHON_PREFIX}/bin/python" ]; then
|
||||
echo "python-virtualenv: python not found: ${PYTHON_PREFIX}" >&2
|
||||
elif [ ! -x "${PYTHON_BIN}" ]; then
|
||||
echo "python-virtualenv: given python is not an executable: ${PYTHON_BIN}" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
@@ -112,35 +112,17 @@ if [ -z "$VIRTUALENV_PATH" ]; then
|
||||
usage
|
||||
fi
|
||||
|
||||
BOOTSTRAP_PYTHON_BIN="${PYTHON_PREFIX}/bin/python"
|
||||
PYTHON_BIN="${VIRTUALENV_PATH}/bin/python"
|
||||
|
||||
# find canonical name of python executable.
|
||||
# virtualenv will create "bin/python" executable as same name as its bootstraped python.
|
||||
if test -L "${BOOTSTRAP_PYTHON_BIN}"; then
|
||||
while test -L "${BOOTSTRAP_PYTHON_BIN}"; do # retrieve symlinks
|
||||
BOOTSTRAP_PYTHON_BIN="$(dirname "${BOOTSTRAP_PYTHON_BIN}")/$(resolve_link "${BOOTSTRAP_PYTHON_BIN}")"
|
||||
done
|
||||
else
|
||||
# python 2.6 and older don't have "bin/python" as symlink.
|
||||
# so we must traverse files like "bin/python*" to obtain canonical name.
|
||||
for python in ${PYTHON_PREFIX}/bin/python*; do
|
||||
if ( basename "$python" | grep '^python[0-9][0-9]*\.[0-9][0-9]*$' && cmp "$BOOTSTRAP_PYTHON_BIN" "$python" ) >/dev/null; then
|
||||
BOOTSTRAP_PYTHON_BIN="${python}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
VIRTUALENV_PYTHON_BIN="${VIRTUALENV_PATH}/bin/python"
|
||||
|
||||
# create virtualenv
|
||||
"${BOOTSTRAP_PYTHON_BIN}" "${PYTHON_VIRTUALENV_ROOT}/libexec/virtualenv.py" "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}"
|
||||
"${PYTHON_BIN}" "${PYTHON_VIRTUALENV_ROOT}/libexec/virtualenv.py" "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}"
|
||||
|
||||
# create symlink of `python' bound for actual executable
|
||||
if [ ! -f "$PYTHON_BIN" ]; then
|
||||
if test -f "${VIRTUALENV_PATH}/bin/$(basename "${BOOTSTRAP_PYTHON_BIN}")"; then
|
||||
if [ ! -f "$VIRTUALENV_PYTHON_BIN" ]; then
|
||||
if [ -f "${VIRTUALENV_PATH}/bin/$(basename "${PYTHON_BIN}")" ]; then
|
||||
{
|
||||
cd ${VIRTUALENV_PATH}/bin
|
||||
ln -fs "$(basename "${BOOTSTRAP_PYTHON_BIN}")" python
|
||||
ln -fs "$(basename "${PYTHON_BIN}")" python
|
||||
}
|
||||
fi
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user