mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-13 05:53:52 -05:00
Use conda create to create virtualenv if the source version is a Anaconda/Miniconda
This commit is contained in:
@@ -103,45 +103,57 @@ http_get_wget() {
|
|||||||
version() {
|
version() {
|
||||||
detect_venv
|
detect_venv
|
||||||
local version
|
local version
|
||||||
|
if [ -n "${USE_CONDA}" ]; then
|
||||||
|
version="$(pyenv-exec conda --version 2>/dev/null || true)"
|
||||||
|
echo "pyenv-virtualenv ${PYENV_VIRTUALENV_VERSION} (conda ${version:-unknown})"
|
||||||
|
else
|
||||||
if [ -n "$USE_PYVENV" ]; then
|
if [ -n "$USE_PYVENV" ]; then
|
||||||
version="$(pyenv-which pyvenv 2>/dev/null || true)"
|
version="$(pyenv-which pyvenv 2>/dev/null || true)"
|
||||||
version="${version#${PYENV_ROOT}/versions/}"
|
version="${version#${PYENV_ROOT}/versions/}"
|
||||||
version="${version%/bin/pyvenv}"
|
version="${version%/bin/pyvenv}"
|
||||||
echo "pyenv-virtualenv ${PYENV_VIRTUALENV_VERSION} (pyvenv ${version:-unknown})"
|
echo "pyenv-virtualenv ${PYENV_VIRTUALENV_VERSION} (pyvenv ${version:-unknown})"
|
||||||
else
|
else
|
||||||
version="$(venv --version 2>/dev/null || true)"
|
version="$(pyenv-exec virtualenv --version 2>/dev/null || true)"
|
||||||
echo "pyenv-virtualenv ${PYENV_VIRTUALENV_VERSION} (virtualenv ${version:-unknown})"
|
echo "pyenv-virtualenv ${PYENV_VIRTUALENV_VERSION} (virtualenv ${version:-unknown})"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
# We can remove the sed fallback once pyenv 0.2.0 is widely available.
|
# We can remove the sed fallback once pyenv 0.2.0 is widely available.
|
||||||
pyenv-help virtualenv 2>/dev/null || sed -ne '/^#/!q;s/.//;s/.//;1,4d;p' < "$0"
|
pyenv-help virtualenv 2>/dev/null || sed -ne '/^#/!q;s/.//;s/.//;1,4d;p' < "$0"
|
||||||
venv --help 2>/dev/null || true
|
if [ -n "${USE_CONDA}" ]; then
|
||||||
|
pyenv-exec conda create --help 2>/dev/null || true
|
||||||
|
else
|
||||||
|
if [ -n "${USE_PYVENV}" ]; then
|
||||||
|
pyenv-exec pyvenv --help 2>/dev/null || true
|
||||||
|
else
|
||||||
|
pyenv-exec virtualenv --help 2>/dev/null || true
|
||||||
|
fi
|
||||||
|
fi
|
||||||
[ -z "$1" ] || exit "$1"
|
[ -z "$1" ] || exit "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
detect_venv() {
|
detect_venv() {
|
||||||
# Check the existence of executables as a workaround for the issue with pyenv-which-ext
|
# Check the existence of executables as a workaround for the issue with pyenv-which-ext
|
||||||
# https://github.com/yyuu/pyenv-virtualenv/issues/26
|
# https://github.com/yyuu/pyenv-virtualenv/issues/26
|
||||||
|
if [ -x "$(pyenv-prefix)/bin/conda" ]; then
|
||||||
|
HAS_CONDA=1
|
||||||
|
else
|
||||||
if [ -x "$(pyenv-prefix)/bin/virtualenv" ]; then
|
if [ -x "$(pyenv-prefix)/bin/virtualenv" ]; then
|
||||||
HAS_VIRTUALENV=1
|
HAS_VIRTUALENV=1
|
||||||
fi
|
fi
|
||||||
if [ -x "$(pyenv-prefix)/bin/pyvenv" ]; then
|
if [ -x "$(pyenv-prefix)/bin/pyvenv" ]; then
|
||||||
HAS_PYVENV=1
|
HAS_PYVENV=1
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
# Use pyvenv only if there is pyvenv, virtualenv is not installed, and `-p` not given
|
# Use pyvenv only if there is pyvenv, virtualenv is not installed, and `-p` not given
|
||||||
|
if [ -n "${HAS_CONDA}" ]; then
|
||||||
|
USE_CONDA=1
|
||||||
|
else
|
||||||
if [ -n "${HAS_PYVENV}" ] && [ -z "${HAS_VIRTUALENV}" ] && [ -z "${VIRTUALENV_PYTHON}" ]; then
|
if [ -n "${HAS_PYVENV}" ] && [ -z "${HAS_VIRTUALENV}" ] && [ -z "${VIRTUALENV_PYTHON}" ]; then
|
||||||
USE_PYVENV=1
|
USE_PYVENV=1
|
||||||
fi
|
fi
|
||||||
}
|
|
||||||
|
|
||||||
venv() {
|
|
||||||
local args=("$@")
|
|
||||||
if [ -n "${USE_PYVENV}" ]; then
|
|
||||||
pyenv-exec pyvenv "${args[@]}"
|
|
||||||
else
|
|
||||||
pyenv-exec virtualenv "${args[@]}"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,12 +308,13 @@ fi
|
|||||||
export PYENV_VERSION="${VERSION_NAME}"
|
export PYENV_VERSION="${VERSION_NAME}"
|
||||||
|
|
||||||
# Source version must exist before creating virtualenv.
|
# Source version must exist before creating virtualenv.
|
||||||
if ! pyenv-prefix 1>/dev/null 2>&1; then
|
PREFIX="$(pyenv-prefix 2>/dev/null || true)"
|
||||||
|
if [ ! -d "${PREFIX}" ]; then
|
||||||
echo "pyenv-virtualenv: \`${PYENV_VERSION}' is not installed in pyenv." 1>&2
|
echo "pyenv-virtualenv: \`${PYENV_VERSION}' is not installed in pyenv." 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if pyenv-virtualenv-prefix "${VERSION_NAME}" 1>/dev/null 2>&1; then
|
if [[ "${PREFIX}" != "${PREFIX%/envs/*}" ]]; then
|
||||||
echo "pyenv-virtualenv: nested virtualenv is not supported." 1>&2
|
echo "pyenv-virtualenv: nested virtualenv is not supported." 1>&2
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
@@ -333,6 +346,7 @@ fi
|
|||||||
|
|
||||||
unset HAS_VIRTUALENV
|
unset HAS_VIRTUALENV
|
||||||
unset HAS_PYVENV
|
unset HAS_PYVENV
|
||||||
|
unset USE_CONDA
|
||||||
unset USE_PYVENV
|
unset USE_PYVENV
|
||||||
detect_venv
|
detect_venv
|
||||||
|
|
||||||
@@ -350,6 +364,9 @@ if [ -n "$UPGRADE" ]; then
|
|||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [ -n "${USE_CONDA}" ]; then
|
||||||
|
:
|
||||||
|
else
|
||||||
if [ -n "${USE_PYVENV}" ]; then
|
if [ -n "${USE_PYVENV}" ]; then
|
||||||
# Unset some arguments not supported by pyvenv
|
# Unset some arguments not supported by pyvenv
|
||||||
unset QUIET
|
unset QUIET
|
||||||
@@ -383,6 +400,7 @@ else
|
|||||||
HAS_VIRTUALENV=1
|
HAS_VIRTUALENV=1
|
||||||
fi
|
fi
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
# Unset environment variables which start with `VIRTUALENV_`.
|
# Unset environment variables which start with `VIRTUALENV_`.
|
||||||
# These variables are reserved for virtualenv.
|
# These variables are reserved for virtualenv.
|
||||||
@@ -456,7 +474,15 @@ STATUS=0
|
|||||||
# Change to cache directory to reuse them between invocations.
|
# Change to cache directory to reuse them between invocations.
|
||||||
mkdir -p "${PYENV_VIRTUALENV_CACHE_PATH}"
|
mkdir -p "${PYENV_VIRTUALENV_CACHE_PATH}"
|
||||||
cd "${PYENV_VIRTUALENV_CACHE_PATH}"
|
cd "${PYENV_VIRTUALENV_CACHE_PATH}"
|
||||||
venv $QUIET $VERBOSE "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}" || STATUS="$?"
|
if [ -n "${USE_CONDA}" ]; then
|
||||||
|
pyenv-exec conda create $QUIET $VERBOSE --name "${VIRTUALENV_PATH##*/}" --yes "${VIRTUALENV_OPTIONS[@]}" python || STATUS="$?"
|
||||||
|
else
|
||||||
|
if [ -n "${USE_PYVENV}" ]; then
|
||||||
|
pyenv-exec pyvenv $QUIET $VERBOSE "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}" || STATUS="$?"
|
||||||
|
else
|
||||||
|
pyenv-exec virtualenv $QUIET $VERBOSE "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}" || STATUS="$?"
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
## Create symlink in the `versions` directory for backward compatibility
|
## Create symlink in the `versions` directory for backward compatibility
|
||||||
if [ -d "${VIRTUALENV_PATH}" ] && [ -n "${COMPAT_VIRTUALENV_PATH}" ]; then
|
if [ -d "${VIRTUALENV_PATH}" ] && [ -n "${COMPAT_VIRTUALENV_PATH}" ]; then
|
||||||
|
|||||||
Reference in New Issue
Block a user