Merge branch 'virtualenv-without-python-executable'

This commit is contained in:
Yamashita, Yuu
2015-11-26 12:40:57 +00:00
5 changed files with 80 additions and 34 deletions

View File

@@ -37,6 +37,7 @@ for version in "${versions[@]}"; do
exit 1 exit 1
fi fi
PYENV_PREFIX_PATH="$(pyenv-prefix "${version}")" PYENV_PREFIX_PATH="$(pyenv-prefix "${version}")"
if [ -x "${PYENV_PREFIX_PATH}/bin/python" ]; then
if [ -f "${PYENV_PREFIX_PATH}/bin/activate" ]; then if [ -f "${PYENV_PREFIX_PATH}/bin/activate" ]; then
VIRTUALENV_PREFIX_PATH="$(real_prefix "${version}" || base_prefix "${version}" || true)" VIRTUALENV_PREFIX_PATH="$(real_prefix "${version}" || base_prefix "${version}" || true)"
VIRTUALENV_PREFIX_PATHS=("${VIRTUALENV_PREFIX_PATHS[@]}" "${VIRTUALENV_PREFIX_PATH:-${PYENV_PREFIX_PATH}}") VIRTUALENV_PREFIX_PATHS=("${VIRTUALENV_PREFIX_PATHS[@]}" "${VIRTUALENV_PREFIX_PATH:-${PYENV_PREFIX_PATH}}")
@@ -44,6 +45,10 @@ for version in "${versions[@]}"; do
echo "pyenv-virtualenv: version \`${version}' is not a virtualenv" 1>&2 echo "pyenv-virtualenv: version \`${version}' is not a virtualenv" 1>&2
exit 1 exit 1
fi fi
else
echo "pyenv-virtualenv: \`python' not found in version \`${version}'" 1>&2
exit 1
fi
done done
IFS=: echo "${VIRTUALENV_PREFIX_PATHS[*]}" IFS=: echo "${VIRTUALENV_PREFIX_PATHS[*]}"

View File

@@ -4,11 +4,28 @@
# https://github.com/yyuu/pyenv/issues/397 # https://github.com/yyuu/pyenv/issues/397
if [ ! -x "${PYENV_COMMAND_PATH}" ] && [[ "${PYENV_COMMAND_PATH##*/}" == "python"*"-config" ]]; then if [ ! -x "${PYENV_COMMAND_PATH}" ] && [[ "${PYENV_COMMAND_PATH##*/}" == "python"*"-config" ]]; then
virtualenv_prefix="$(pyenv-virtualenv-prefix 2>/dev/null || true)" OLDIFS="${IFS}"
if [ -d "${virtualenv_prefix}" ]; then 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##*/}" virtualenv_command_path="${virtualenv_prefix}/bin/${PYENV_COMMAND_PATH##*/}"
if [ -x "${virtualenv_command_path}" ]; then if [ -x "${virtualenv_command_path}" ]; then
PYENV_COMMAND_PATH="${virtualenv_command_path}" PYENV_COMMAND_PATH="${virtualenv_command_path}"
fi fi
fi fi
fi
fi fi

View File

@@ -4,18 +4,27 @@
# https://github.com/yyuu/pyenv-virtualenv/issues/62 # https://github.com/yyuu/pyenv-virtualenv/issues/62
if [ ! -x "${PYENV_COMMAND_PATH}" ]; then if [ ! -x "${PYENV_COMMAND_PATH}" ]; then
virtualenv_prefix="$(pyenv-virtualenv-prefix 2>/dev/null || true)" OLDIFS="${IFS}"
if [ -d "${virtualenv_prefix}" ]; then IFS=:
version="$(pyenv-version-name)"
IFS="${OLDIFS}"
if [ -f "${PYENV_ROOT}/versions/${version}/bin/activate" ]; then
unset include_system_site_packages unset include_system_site_packages
if [ -f "$(pyenv-prefix)/pyvenv.cfg" ]; then if [ -f "${PYENV_ROOT}/versions/${version}/bin/conda" ]; then
: # do nothing for conda's environments
else
if [ -f "${PYENV_ROOT}/versions/${version}/pyvenv.cfg" ]; then
# pyvenv # pyvenv
if grep -q -i "include-system-site-packages *= *true" "$(pyenv-prefix)/pyvenv.cfg" 1>/dev/null 2>&1; then 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 include_system_site_packages=1
fi fi
else else
# virtualenv # virtualenv
shopt -s nullglob shopt -s nullglob
no_global_site_packages="$(echo "$(pyenv-prefix)/lib/"*"/no-global-site-packages.txt")" 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 shopt -u nullglob
if [ ! -f "${no_global_site_packages}" ]; then if [ ! -f "${no_global_site_packages}" ]; then
include_system_site_packages=1 include_system_site_packages=1
@@ -29,4 +38,5 @@ if [ ! -x "${PYENV_COMMAND_PATH}" ]; then
fi fi
fi fi
fi fi
fi
fi fi

View File

@@ -6,13 +6,23 @@ setup() {
export PYENV_ROOT="${TMP}/pyenv" export PYENV_ROOT="${TMP}/pyenv"
} }
create_virtualenv() { create_version() {
mkdir -p "${PYENV_ROOT}/versions/$1/bin" 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" touch "${PYENV_ROOT}/versions/$1/bin/activate"
} }
remove_virtualenv() { remove_virtualenv() {
rm -fr "${PYENV_ROOT}/versions/$1" remove_version "$@"
} }
@test "display prefix with using sys.real_prefix" { @test "display prefix with using sys.real_prefix" {
@@ -118,13 +128,13 @@ OUT
@test "should fail if the version is not a virtualenv" { @test "should fail if the version is not a virtualenv" {
stub pyenv-version-name "echo 3.4.0" stub pyenv-version-name "echo 3.4.0"
stub pyenv-prefix "3.4.0 : echo \"${PYENV_ROOT}/versions/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 PYENV_VERSION="3.4.0" run pyenv-virtualenv-prefix
unstub pyenv-version-name unstub pyenv-version-name
unstub pyenv-prefix unstub pyenv-prefix
rmdir "${PYENV_ROOT}/versions/3.4.0" remove_version "3.4.0"
assert_failure assert_failure
assert_output <<OUT assert_output <<OUT
@@ -139,7 +149,7 @@ OUT
stub pyenv-exec "false" \ stub pyenv-exec "false" \
"echo \"${PYENV_ROOT}/versions/3.3.3\"" "echo \"${PYENV_ROOT}/versions/3.3.3\""
create_virtualenv "venv33" 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 PYENV_VERSION="venv33:3.4.0" run pyenv-virtualenv-prefix
@@ -147,7 +157,7 @@ OUT
unstub pyenv-prefix unstub pyenv-prefix
unstub pyenv-exec unstub pyenv-exec
remove_virtualenv "venv33" remove_virtualenv "venv33"
rmdir "${PYENV_ROOT}/versions/3.4.0" remove_version "3.4.0"
assert_failure assert_failure
assert_output <<OUT assert_output <<OUT

View File

@@ -123,12 +123,16 @@ create_conda() {
mkdir -p "${PYENV_ROOT}/versions/$version/bin" mkdir -p "${PYENV_ROOT}/versions/$version/bin"
touch "${PYENV_ROOT}/versions/$version/bin/activate" touch "${PYENV_ROOT}/versions/$version/bin/activate"
touch "${PYENV_ROOT}/versions/$version/bin/conda" 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/conda"
chmod +x "${PYENV_ROOT}/versions/$version/bin/python"
local conda_env local conda_env
for conda_env; do for conda_env; do
mkdir -p "${PYENV_ROOT}/versions/$version/envs/$conda_env/bin" 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/activate"
touch "${PYENV_ROOT}/versions/$version/envs/$conda_env/bin/conda" 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/conda"
chmod +x "${PYENV_ROOT}/versions/$version/envs/$conda_env/bin/python"
done done
} }