diff --git a/README.md b/README.md index eefc7a1..02b4b74 100644 --- a/README.md +++ b/README.md @@ -148,14 +148,14 @@ pyenv uninstall my-virtual-env ``` -### virtualenv and pyvenv +### virtualenv and venv There is a [venv](http://docs.python.org/3/library/venv.html) module available for CPython 3.3 and newer. -It provides a command-line tool `pyvenv` which is the successor of `virtualenv` +It provides an executable module `venv` which is the successor of `virtualenv` and distributed by default. -`pyenv-virtualenv` uses `pyvenv` if it is available and the `virtualenv` +`pyenv-virtualenv` uses `python -m venv` if it is available and the `virtualenv` command is not available. @@ -215,11 +215,11 @@ You can set certain environment variables to control pyenv-virtualenv. * `VIRTUALENV_VERSION`, if set, forces pyenv-virtualenv to install the desired version of virtualenv. If `virtualenv` has not been installed, pyenv-virtualenv will try to install the given version of virtualenv. -* `GET_PIP`, if set and `pyvenv` is preferred over `virtualenv`, +* `GET_PIP`, if set and `venv` is preferred over `virtualenv`, use `get_pip.py` from the specified location. -* `GET_PIP_URL`, if set and `pyvenv` is preferred over +* `GET_PIP_URL`, if set and `venv` is preferred over `virtualenv`, download `get_pip.py` from the specified URL. -* `PIP_VERSION`, if set and `pyvenv` is preferred +* `PIP_VERSION`, if set and `venv` is preferred over `virtualenv`, install the specified version of pip. 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 - pyenv-exec pyvenv --help 2>/dev/null || true + 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 fi @@ -144,16 +141,16 @@ detect_venv() { if [ -x "${prefix}/bin/virtualenv" ]; then HAS_VIRTUALENV=1 fi - if [ -x "${prefix}/bin/pyvenv" ]; then - HAS_PYVENV=1 + if pyenv-exec python -m venv --help 1>/dev/null 2>&1; then + HAS_M_VENV=1 fi fi - # Use pyvenv only if there is pyvenv, virtualenv is not installed, and `-p` not given + # 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 } @@ -359,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").$$" @@ -371,8 +368,8 @@ REQUIREMENTS="${TMP}/requirements.${SEED}.txt" # Upgrade existing virtualenv if [ -n "$UPGRADE" ]; then FORCE=1 - # pyvenv has `--upgrade` by default - if [ -n "${USE_PYVENV}" ]; then + # `python -m venv` has `--upgrade` by default + if [ -n "${USE_M_VENV}" ]; then unset UPGRADE VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--upgrade" fi @@ -405,12 +402,12 @@ if [ -n "${USE_CONDA}" ]; then fi fi else - if [ -n "${USE_PYVENV}" ]; then - # Unset some arguments not supported by pyvenv + if [ -n "${USE_M_VENV}" ]; then + # Unset some arguments not supported by `python -m venv` unset QUIET unset VERBOSE if [ -n "${VIRTUALENV_PYTHON}" ]; then - echo "pyenv-virtualenv: \`--python=${VIRTUALENV_PYTHON}' is not supported by pyvenv." 1>&2 + echo "pyenv-virtualenv: \`--python=${VIRTUALENV_PYTHON}' is not supported by \`python -m venv'." 1>&2 exit 1 fi else @@ -524,8 +521,8 @@ 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 - pyenv-exec pyvenv $QUIET $VERBOSE "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}" || STATUS="$?" + 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="$?" fi 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 57b6d94..325aa33 100644 --- a/test/envs.bats +++ b/test/envs.bats @@ -20,19 +20,20 @@ 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}'" stub pyenv-virtualenv-prefix " : false" - stub pyenv-exec "pyvenv * : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\";mkdir -p \${PYENV_ROOT}/versions/3.5.1/envs/venv/bin" + stub pyenv-exec "python -m venv --help : true" + stub pyenv-exec "python -m venv * : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\";mkdir -p \${PYENV_ROOT}/versions/3.5.1/envs/venv/bin" stub pyenv-exec "python -s -m ensurepip : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\";touch \${PYENV_ROOT}/versions/3.5.1/envs/venv/bin/pip" run pyenv-virtualenv venv assert_success assert_output < "${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/python.bats b/test/python.bats index 47348cc..9e2589d 100644 --- a/test/python.bats +++ b/test/python.bats @@ -31,6 +31,7 @@ teardown() { create_executable "2.7.8" "python2.7" remove_executable "2.7.9" "python2.7" + stub pyenv-exec "python -m venv --help : false" stub pyenv-exec "virtualenv --verbose * : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\"" stub pyenv-exec "python -s -m ensurepip : true" stub pyenv-which "python2.7 : echo ${PYENV_ROOT}/versions/2.7.8/bin/python2.7" @@ -55,6 +56,7 @@ OUT remove_executable "2.7.8" "python2.7" create_executable "2.7.9" "python2.7" + stub pyenv-exec "python -m venv --help : false" stub pyenv-exec "virtualenv --verbose * : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\"" stub pyenv-exec "python -s -m ensurepip : true" stub pyenv-which "python2.7 : false" diff --git a/test/pyvenv.bats b/test/pyvenv.bats index c4cbe97..d5637cd 100644 --- a/test/pyvenv.bats +++ b/test/pyvenv.bats @@ -20,36 +20,38 @@ 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" - stub pyenv-exec "pyvenv * : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\"" + stub pyenv-exec "python -m venv --help : true" + stub pyenv-exec "python -m venv * : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\"" stub pyenv-exec "python -s -m ensurepip : true" run pyenv-virtualenv venv assert_success assert_output <