From 8c7dd0195493742811147f7422f937102e564311 Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Sat, 16 Jul 2016 06:50:50 +0000 Subject: [PATCH] Replaced `pyvenv` by `-m venv` --- bin/pyenv-sh-activate | 2 +- bin/pyenv-sh-deactivate | 2 +- bin/pyenv-virtualenv | 20 +++++++++---------- bin/pyenv-virtualenv-prefix | 2 +- etc/pyenv.d/which/python-config.bash | 2 +- etc/pyenv.d/which/system-site-packages.bash | 2 +- test/conda.bats | 6 +++--- test/envs.bats | 4 ++-- test/pip.bats | 8 ++++---- test/prefix.bats | 20 +++++++++---------- test/pyvenv.bats | 22 ++++++++++----------- test/test_helper.bash | 4 ++-- test/version.bats | 7 +++---- 13 files changed, 50 insertions(+), 51 deletions(-) diff --git a/bin/pyenv-sh-activate b/bin/pyenv-sh-activate index 3a8d96c..ec3454a 100755 --- a/bin/pyenv-sh-activate +++ b/bin/pyenv-sh-activate @@ -160,7 +160,7 @@ EOS IFS="$OLDIFS" fi -# virtualenv/pyvenv +# virtualenv/venv case "${shell}" in fish ) cat </dev/null || true else - if [ -n "${USE_PYVENV}" ]; then + if [ -n "${USE_M_VENV}" ]; then pyenv-exec python -m venv --help 2>/dev/null || true else pyenv-exec virtualenv --help 2>/dev/null || true @@ -142,15 +142,15 @@ detect_venv() { HAS_VIRTUALENV=1 fi if pyenv-exec python -m venv --help 1>/dev/null 2>&1; then - HAS_PYVENV=1 + HAS_M_VENV=1 fi fi # Use `python -m venv` only if there is venv available, 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 - USE_PYVENV=1 + if [ -n "${HAS_M_VENV}" ] && [ -z "${HAS_VIRTUALENV}" ] && [ -z "${VIRTUALENV_PYTHON}" ]; then + USE_M_VENV=1 fi fi } @@ -356,9 +356,9 @@ if [ -n "${COMPAT_VIRTUALENV_PATH}" ]; then fi unset HAS_VIRTUALENV -unset HAS_PYVENV +unset HAS_M_VENV unset USE_CONDA -unset USE_PYVENV +unset USE_M_VENV detect_venv SEED="$(date "+%Y%m%d%H%M%S").$$" @@ -369,7 +369,7 @@ REQUIREMENTS="${TMP}/requirements.${SEED}.txt" if [ -n "$UPGRADE" ]; then FORCE=1 # `python -m venv` has `--upgrade` by default - if [ -n "${USE_PYVENV}" ]; then + if [ -n "${USE_M_VENV}" ]; then unset UPGRADE VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--upgrade" fi @@ -402,7 +402,7 @@ if [ -n "${USE_CONDA}" ]; then fi fi else - if [ -n "${USE_PYVENV}" ]; then + if [ -n "${USE_M_VENV}" ]; then # Unset some arguments not supported by `python -m venv` unset QUIET unset VERBOSE @@ -521,7 +521,7 @@ cd "${PYENV_VIRTUALENV_CACHE_PATH}" 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 + if [ -n "${USE_M_VENV}" ]; then pyenv-exec python -m venv $QUIET $VERBOSE "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}" || STATUS="$?" else pyenv-exec virtualenv $QUIET $VERBOSE "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}" || STATUS="$?" diff --git a/bin/pyenv-virtualenv-prefix b/bin/pyenv-virtualenv-prefix index c517062..934a18f 100755 --- a/bin/pyenv-virtualenv-prefix +++ b/bin/pyenv-virtualenv-prefix @@ -33,7 +33,7 @@ for version in "${versions[@]}"; do VIRTUALENV_PREFIX_PATH="${PYENV_PREFIX_PATH}" else if [ -f "${PYENV_ROOT}/versions/${version}/pyvenv.cfg" ]; then - # pyvenv + # venv virtualenv_binpath="$(cut -b 1-1024 "${PYENV_ROOT}/versions/${version}/pyvenv.cfg" | sed -n '/^ *home *= */s///p' || true)" VIRTUALENV_PREFIX_PATH="${virtualenv_binpath%/bin}" else diff --git a/etc/pyenv.d/which/python-config.bash b/etc/pyenv.d/which/python-config.bash index 2785f6b..a0df899 100644 --- a/etc/pyenv.d/which/python-config.bash +++ b/etc/pyenv.d/which/python-config.bash @@ -13,7 +13,7 @@ if [ ! -x "${PYENV_COMMAND_PATH}" ] && [[ "${PYENV_COMMAND_PATH##*/}" == "python : # do nothing for conda's environments else if [ -f "${PYENV_ROOT}/versions/${version}/bin/pyvenv.cfg" ]; then - # pyvenv + # venv virtualenv_binpath="$(cut -b 1-1024 "${PYENV_ROOT}/versions/${version}/pyvenv.cfg" | sed -n '/^ *home *= */s///p' || true)" virtualenv_prefix="${virtualenv_binpath%/bin}" else diff --git a/etc/pyenv.d/which/system-site-packages.bash b/etc/pyenv.d/which/system-site-packages.bash index 8283793..ef7ad08 100644 --- a/etc/pyenv.d/which/system-site-packages.bash +++ b/etc/pyenv.d/which/system-site-packages.bash @@ -14,7 +14,7 @@ if [ ! -x "${PYENV_COMMAND_PATH}" ]; then : # do nothing for conda's environments else if [ -f "${PYENV_ROOT}/versions/${version}/pyvenv.cfg" ]; then - # pyvenv + # venv 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 diff --git a/test/conda.bats b/test/conda.bats index 3c6ef02..43a7bf6 100644 --- a/test/conda.bats +++ b/test/conda.bats @@ -40,7 +40,7 @@ OUT unstub_pyenv unstub pyenv-virtualenv-prefix unstub pyenv-exec - teardown_pyvenv "miniconda3-3.16.0" + teardown_m_venv "miniconda3-3.16.0" } @test "create virtualenv by conda create with -p" { @@ -63,7 +63,7 @@ OUT unstub_pyenv unstub pyenv-virtualenv-prefix unstub pyenv-exec - teardown_pyvenv "miniconda3-3.16.0" + teardown_m_venv "miniconda3-3.16.0" } @test "create virtualenv by conda create with --python" { @@ -86,5 +86,5 @@ OUT unstub_pyenv unstub pyenv-virtualenv-prefix unstub pyenv-exec - teardown_pyvenv "miniconda3-3.16.0" + teardown_m_venv "miniconda3-3.16.0" } diff --git a/test/envs.bats b/test/envs.bats index 3dcc703..325aa33 100644 --- a/test/envs.bats +++ b/test/envs.bats @@ -20,7 +20,7 @@ unstub_pyenv() { @test "path should be handled properly even if there is 'envs' in PYENV_ROOT" { export PYENV_VERSION="3.5.1" - setup_pyvenv "3.5.1" + setup_m_venv "3.5.1" stub_pyenv "${PYENV_VERSION}" stub pyenv-version-name "echo '${PYENV_VERSION}'" stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'" @@ -43,5 +43,5 @@ OUT unstub pyenv-version-name unstub pyenv-virtualenv-prefix unstub pyenv-exec - teardown_pyvenv "3.5.1" + teardown_m_venv "3.5.1" } diff --git a/test/pip.bats b/test/pip.bats index 6e31f24..88aa7b7 100644 --- a/test/pip.bats +++ b/test/pip.bats @@ -22,7 +22,7 @@ unstub_pyenv() { @test "install pip with ensurepip" { export PYENV_VERSION="3.5.1" - setup_pyvenv "3.5.1" + setup_m_venv "3.5.1" stub_pyenv "${PYENV_VERSION}" stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'" stub pyenv-virtualenv-prefix " : false" @@ -43,12 +43,12 @@ OUT unstub_pyenv unstub pyenv-virtualenv-prefix unstub pyenv-exec - teardown_pyvenv "3.5.1" + teardown_m_venv "3.5.1" } @test "install pip without using ensurepip" { export PYENV_VERSION="3.3.6" - setup_pyvenv "3.3.6" + setup_m_venv "3.3.6" stub_pyenv "${PYENV_VERSION}" stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'" stub pyenv-virtualenv-prefix " : false" @@ -72,5 +72,5 @@ OUT unstub_pyenv unstub pyenv-virtualenv-prefix unstub pyenv-exec - teardown_pyvenv "3.3.6" + teardown_m_venv "3.3.6" } diff --git a/test/prefix.bats b/test/prefix.bats index 471d6b2..a21c3f9 100644 --- a/test/prefix.bats +++ b/test/prefix.bats @@ -45,14 +45,14 @@ remove_virtualenv() { remove_version "${2:-$1}" } -create_pyvenv() { +create_m_venv() { create_version "$1" create_version "${2:-$1}" echo "home = ${PYENV_ROOT}/versions/${2:-$1}/bin" > "${PYENV_ROOT}/versions/$1/pyvenv.cfg" touch "${PYENV_ROOT}/versions/$1/bin/activate" } -remove_pyvenv() { +remove_m_venv() { remove_version "${2:-$1}" } @@ -141,10 +141,10 @@ OUT remove_virtualenv "bar" "3.5.1" } -@test "display prefix of virtualenv created by pyvenv" { +@test "display prefix of virtualenv created by venv" { stub pyenv-version-name "echo foo" stub pyenv-prefix "foo : echo \"${PYENV_ROOT}/versions/foo\"" - create_pyvenv "foo" "3.3.6" + create_m_venv "foo" "3.3.6" PYENV_VERSION="foo" run pyenv-virtualenv-prefix @@ -155,15 +155,15 @@ OUT unstub pyenv-version-name unstub pyenv-prefix - remove_pyvenv "foo" "3.3.6" + remove_m_venv "foo" "3.3.6" } -@test "display prefixes of virtualenv created by pyvenv" { +@test "display prefixes of virtualenv created by venv" { stub pyenv-version-name "echo foo:bar" stub pyenv-prefix "foo : echo \"${PYENV_ROOT}/versions/foo\"" \ "bar : echo \"${PYENV_ROOT}/versions/bar\"" - create_pyvenv "foo" "3.3.6" - create_pyvenv "bar" "3.4.4" + create_m_venv "foo" "3.3.6" + create_m_venv "bar" "3.4.4" PYENV_VERSION="foo:bar" run pyenv-virtualenv-prefix @@ -174,8 +174,8 @@ OUT unstub pyenv-version-name unstub pyenv-prefix - remove_pyvenv "foo" "3.3.6" - remove_pyvenv "bar" "3.4.4" + remove_m_venv "foo" "3.3.6" + remove_m_venv "bar" "3.4.4" } @test "display prefix of virtualenv created by conda" { diff --git a/test/pyvenv.bats b/test/pyvenv.bats index 082f62a..d5637cd 100644 --- a/test/pyvenv.bats +++ b/test/pyvenv.bats @@ -20,9 +20,9 @@ unstub_pyenv() { unstub pyenv-rehash } -@test "use pyvenv if virtualenv is not available" { +@test "use venv if virtualenv is not available" { export PYENV_VERSION="3.5.1" - setup_pyvenv "3.5.1" + setup_m_venv "3.5.1" stub_pyenv "${PYENV_VERSION}" stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'" stub pyenv-virtualenv-prefix " : false" @@ -41,12 +41,12 @@ OUT unstub_pyenv unstub pyenv-virtualenv-prefix unstub pyenv-exec - teardown_pyvenv "3.5.1" + teardown_m_venv "3.5.1" } -@test "not use pyvenv if virtualenv is available" { +@test "not use venv if virtualenv is available" { export PYENV_VERSION="3.5.1" - setup_pyvenv "3.5.1" + setup_m_venv "3.5.1" create_executable "3.5.1" "virtualenv" stub_pyenv "${PYENV_VERSION}" stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'" @@ -66,10 +66,10 @@ OUT unstub_pyenv unstub pyenv-virtualenv-prefix unstub pyenv-exec - teardown_pyvenv "3.5.1" + teardown_m_venv "3.5.1" } -@test "install virtualenv if pyvenv is not avaialble" { +@test "install virtualenv if venv is not avaialble" { export PYENV_VERSION="3.2.1" setup_version "3.2.1" stub_pyenv "${PYENV_VERSION}" @@ -96,7 +96,7 @@ OUT @test "install virtualenv if -p has given" { export PYENV_VERSION="3.5.1" - setup_pyvenv "3.5.1" + setup_m_venv "3.5.1" stub_pyenv "${PYENV_VERSION}" stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'" stub pyenv-virtualenv-prefix " : false" @@ -117,12 +117,12 @@ OUT unstub_pyenv unstub pyenv-virtualenv-prefix unstub pyenv-exec - teardown_pyvenv "3.5.1" + teardown_m_venv "3.5.1" } @test "install virtualenv if --python has given" { export PYENV_VERSION="3.5.1" - setup_pyvenv "3.5.1" + setup_m_venv "3.5.1" stub_pyenv "${PYENV_VERSION}" stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'" stub pyenv-virtualenv-prefix " : false" @@ -143,7 +143,7 @@ OUT unstub_pyenv unstub pyenv-virtualenv-prefix unstub pyenv-exec - teardown_pyvenv "3.5.1" + teardown_m_venv "3.5.1" } @test "install virtualenv with unsetting troublesome pip options" { diff --git a/test/test_helper.bash b/test/test_helper.bash index f419d42..78a4f28 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -137,13 +137,13 @@ teardown_virtualenv() { rm -fr "${PYENV_ROOT}/versions/$1" } -setup_pyvenv() { +setup_m_venv() { create_executable "$1" "python" create_executable "$1" "activate" remove_executable "$1" "conda" } -teardown_pyvenv() { +teardown_m_venv() { rm -fr "${PYENV_ROOT}/versions/$1" } diff --git a/test/version.bats b/test/version.bats index 7384958..67efd28 100644 --- a/test/version.bats +++ b/test/version.bats @@ -22,11 +22,10 @@ setup() { teardown_virtualenv "2.7.7" } -@test "display pyvenv version" { - setup_pyvenv "3.4.1" +@test "display venv version" { + setup_m_venv "3.4.1" stub pyenv-prefix "echo '${PYENV_ROOT}/versions/3.4.1'" stub pyenv-exec "python -m venv --help : true" - stub pyenv-which "pyvenv : echo \"${PYENV_ROOT}/versions/3.4.1/bin/pyvenv\"" run pyenv-virtualenv --version @@ -34,5 +33,5 @@ setup() { [[ "$output" == "pyenv-virtualenv 20"*" (python -m venv)" ]] unstub pyenv-prefix - teardown_pyvenv "3.4.1" + teardown_m_venv "3.4.1" }