mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-11 13:03:52 -05:00
Merge branch 'virtualenv-without-python-executable'
This commit is contained in:
@@ -37,11 +37,16 @@ for version in "${versions[@]}"; do
|
||||
exit 1
|
||||
fi
|
||||
PYENV_PREFIX_PATH="$(pyenv-prefix "${version}")"
|
||||
if [ -f "${PYENV_PREFIX_PATH}/bin/activate" ]; then
|
||||
VIRTUALENV_PREFIX_PATH="$(real_prefix "${version}" || base_prefix "${version}" || true)"
|
||||
VIRTUALENV_PREFIX_PATHS=("${VIRTUALENV_PREFIX_PATHS[@]}" "${VIRTUALENV_PREFIX_PATH:-${PYENV_PREFIX_PATH}}")
|
||||
if [ -x "${PYENV_PREFIX_PATH}/bin/python" ]; then
|
||||
if [ -f "${PYENV_PREFIX_PATH}/bin/activate" ]; then
|
||||
VIRTUALENV_PREFIX_PATH="$(real_prefix "${version}" || base_prefix "${version}" || true)"
|
||||
VIRTUALENV_PREFIX_PATHS=("${VIRTUALENV_PREFIX_PATHS[@]}" "${VIRTUALENV_PREFIX_PATH:-${PYENV_PREFIX_PATH}}")
|
||||
else
|
||||
echo "pyenv-virtualenv: version \`${version}' is not a virtualenv" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
else
|
||||
echo "pyenv-virtualenv: version \`${version}' is not a virtualenv" 1>&2
|
||||
echo "pyenv-virtualenv: \`python' not found in version \`${version}'" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -4,11 +4,28 @@
|
||||
# https://github.com/yyuu/pyenv/issues/397
|
||||
|
||||
if [ ! -x "${PYENV_COMMAND_PATH}" ] && [[ "${PYENV_COMMAND_PATH##*/}" == "python"*"-config" ]]; then
|
||||
virtualenv_prefix="$(pyenv-virtualenv-prefix 2>/dev/null || true)"
|
||||
if [ -d "${virtualenv_prefix}" ]; then
|
||||
virtualenv_command_path="${virtualenv_prefix}/bin/${PYENV_COMMAND_PATH##*/}"
|
||||
if [ -x "${virtualenv_command_path}" ]; then
|
||||
PYENV_COMMAND_PATH="${virtualenv_command_path}"
|
||||
OLDIFS="${IFS}"
|
||||
IFS=:
|
||||
version="$(pyenv-version-name)"
|
||||
IFS="${OLDIFS}"
|
||||
if [ -f "${PYENV_ROOT}/versions/${version}/bin/activate" ]; then
|
||||
if [ -f "${PYENV_ROOT}/versions/${version}/bin/conda" ]; then
|
||||
: # do nothing for conda's environments
|
||||
else
|
||||
if [ -f "${PYENV_ROOT}/versions/${version}/bin/pyvenv.cfg" ]; then
|
||||
# pyvenv
|
||||
virtualenv_binpath="$(cut -b 1-1024 "${PYENV_ROOT}/versions/${version}/pyvenv.cfg" | sed -n '/^ *home *= */s///p' || true)"
|
||||
virtualenv_prefix="${virtualenv_binpath%/bin}"
|
||||
else
|
||||
# virtualenv
|
||||
shopt -s nullglob
|
||||
virtualenv_prefix="$(cat "${PYENV_ROOT}/versions/${version}/lib/"*"/orig-prefix.txt" </dev/null 2>&1 || true)"
|
||||
shopt -u nullglob
|
||||
fi
|
||||
virtualenv_command_path="${virtualenv_prefix}/bin/${PYENV_COMMAND_PATH##*/}"
|
||||
if [ -x "${virtualenv_command_path}" ]; then
|
||||
PYENV_COMMAND_PATH="${virtualenv_command_path}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -4,28 +4,38 @@
|
||||
# https://github.com/yyuu/pyenv-virtualenv/issues/62
|
||||
|
||||
if [ ! -x "${PYENV_COMMAND_PATH}" ]; then
|
||||
virtualenv_prefix="$(pyenv-virtualenv-prefix 2>/dev/null || true)"
|
||||
if [ -d "${virtualenv_prefix}" ]; then
|
||||
OLDIFS="${IFS}"
|
||||
IFS=:
|
||||
version="$(pyenv-version-name)"
|
||||
IFS="${OLDIFS}"
|
||||
if [ -f "${PYENV_ROOT}/versions/${version}/bin/activate" ]; then
|
||||
unset include_system_site_packages
|
||||
if [ -f "$(pyenv-prefix)/pyvenv.cfg" ]; then
|
||||
# pyvenv
|
||||
if grep -q -i "include-system-site-packages *= *true" "$(pyenv-prefix)/pyvenv.cfg" 1>/dev/null 2>&1; then
|
||||
include_system_site_packages=1
|
||||
fi
|
||||
if [ -f "${PYENV_ROOT}/versions/${version}/bin/conda" ]; then
|
||||
: # do nothing for conda's environments
|
||||
else
|
||||
# virtualenv
|
||||
shopt -s nullglob
|
||||
no_global_site_packages="$(echo "$(pyenv-prefix)/lib/"*"/no-global-site-packages.txt")"
|
||||
shopt -u nullglob
|
||||
if [ ! -f "${no_global_site_packages}" ]; then
|
||||
include_system_site_packages=1
|
||||
if [ -f "${PYENV_ROOT}/versions/${version}/pyvenv.cfg" ]; then
|
||||
# pyvenv
|
||||
virtualenv_binpath="$(cut -b 1-1024 "${PYENV_ROOT}/versions/${version}/pyvenv.cfg" | sed -n '/^ *home *= */s///p' || true)"
|
||||
virtualenv_prefix="${virtualenv_binpath%/bin}"
|
||||
if grep -q -i "include-system-site-packages *= *true" "${PYENV_ROOT}/versions/${version}/pyvenv.cfg" 1>/dev/null 2>&1; then
|
||||
include_system_site_packages=1
|
||||
fi
|
||||
else
|
||||
# virtualenv
|
||||
shopt -s nullglob
|
||||
virtualenv_prefix="$(cat "${PYENV_ROOT}/versions/${version}/lib/"*"/orig-prefix.txt" </dev/null 2>&1 || true)"
|
||||
no_global_site_packages="$(echo "${PYENV_ROOT}/versions/${version}/lib/"*"/no-global-site-packages.txt")"
|
||||
shopt -u nullglob
|
||||
if [ ! -f "${no_global_site_packages}" ]; then
|
||||
include_system_site_packages=1
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
if [ -n "${include_system_site_packages}" ]; then
|
||||
# virtualenv is created with `--system-site-packages`
|
||||
virtualenv_command_path="${virtualenv_prefix}/bin/${PYENV_COMMAND_PATH##*/}"
|
||||
if [ -x "${virtualenv_command_path}" ]; then
|
||||
PYENV_COMMAND_PATH="${virtualenv_command_path}"
|
||||
if [ -n "${include_system_site_packages}" ]; then
|
||||
# virtualenv is created with `--system-site-packages`
|
||||
virtualenv_command_path="${virtualenv_prefix}/bin/${PYENV_COMMAND_PATH##*/}"
|
||||
if [ -x "${virtualenv_command_path}" ]; then
|
||||
PYENV_COMMAND_PATH="${virtualenv_command_path}"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -6,13 +6,23 @@ setup() {
|
||||
export PYENV_ROOT="${TMP}/pyenv"
|
||||
}
|
||||
|
||||
create_virtualenv() {
|
||||
create_version() {
|
||||
mkdir -p "${PYENV_ROOT}/versions/$1/bin"
|
||||
touch "${PYENV_ROOT}/versions/$1/bin/python"
|
||||
chmod +x "${PYENV_ROOT}/versions/$1/bin/python"
|
||||
}
|
||||
|
||||
remove_version() {
|
||||
rm -fr "${PYENV_ROOT}/versions/$1"
|
||||
}
|
||||
|
||||
create_virtualenv() {
|
||||
create_version "$@"
|
||||
touch "${PYENV_ROOT}/versions/$1/bin/activate"
|
||||
}
|
||||
|
||||
remove_virtualenv() {
|
||||
rm -fr "${PYENV_ROOT}/versions/$1"
|
||||
remove_version "$@"
|
||||
}
|
||||
|
||||
@test "display prefix with using sys.real_prefix" {
|
||||
@@ -118,13 +128,13 @@ OUT
|
||||
@test "should fail if the version is not a virtualenv" {
|
||||
stub pyenv-version-name "echo 3.4.0"
|
||||
stub pyenv-prefix "3.4.0 : echo \"${PYENV_ROOT}/versions/3.4.0\""
|
||||
mkdir -p "${PYENV_ROOT}/versions/3.4.0"
|
||||
create_version "3.4.0"
|
||||
|
||||
PYENV_VERSION="3.4.0" run pyenv-virtualenv-prefix
|
||||
|
||||
unstub pyenv-version-name
|
||||
unstub pyenv-prefix
|
||||
rmdir "${PYENV_ROOT}/versions/3.4.0"
|
||||
remove_version "3.4.0"
|
||||
|
||||
assert_failure
|
||||
assert_output <<OUT
|
||||
@@ -139,7 +149,7 @@ OUT
|
||||
stub pyenv-exec "false" \
|
||||
"echo \"${PYENV_ROOT}/versions/3.3.3\""
|
||||
create_virtualenv "venv33"
|
||||
mkdir -p "${PYENV_ROOT}/versions/3.4.0"
|
||||
create_version "3.4.0"
|
||||
|
||||
PYENV_VERSION="venv33:3.4.0" run pyenv-virtualenv-prefix
|
||||
|
||||
@@ -147,7 +157,7 @@ OUT
|
||||
unstub pyenv-prefix
|
||||
unstub pyenv-exec
|
||||
remove_virtualenv "venv33"
|
||||
rmdir "${PYENV_ROOT}/versions/3.4.0"
|
||||
remove_version "3.4.0"
|
||||
|
||||
assert_failure
|
||||
assert_output <<OUT
|
||||
|
||||
@@ -123,12 +123,16 @@ create_conda() {
|
||||
mkdir -p "${PYENV_ROOT}/versions/$version/bin"
|
||||
touch "${PYENV_ROOT}/versions/$version/bin/activate"
|
||||
touch "${PYENV_ROOT}/versions/$version/bin/conda"
|
||||
touch "${PYENV_ROOT}/versions/$version/bin/python"
|
||||
chmod +x "${PYENV_ROOT}/versions/$version/bin/conda"
|
||||
chmod +x "${PYENV_ROOT}/versions/$version/bin/python"
|
||||
local conda_env
|
||||
for conda_env; do
|
||||
mkdir -p "${PYENV_ROOT}/versions/$version/envs/$conda_env/bin"
|
||||
touch "${PYENV_ROOT}/versions/$version/envs/$conda_env/bin/activate"
|
||||
touch "${PYENV_ROOT}/versions/$version/envs/$conda_env/bin/conda"
|
||||
touch "${PYENV_ROOT}/versions/$version/envs/$conda_env/bin/python"
|
||||
chmod +x "${PYENV_ROOT}/versions/$version/envs/$conda_env/bin/conda"
|
||||
chmod +x "${PYENV_ROOT}/versions/$version/envs/$conda_env/bin/python"
|
||||
done
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user