Skip to content

Commit

Permalink
Merge pull request #230 from pyenv/gen-pydoc-executable
Browse files Browse the repository at this point in the history
Generate `pydoc` executable after creating new virtualenv
  • Loading branch information
yyuu authored Aug 23, 2017
2 parents 2727087 + 927914b commit c2ba495
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 8 deletions.
11 changes: 11 additions & 0 deletions bin/pyenv-virtualenv
Original file line number Diff line number Diff line change
Expand Up @@ -533,6 +533,17 @@ if [ -d "${VIRTUALENV_PATH}" ] && [ -n "${COMPAT_VIRTUALENV_PATH}" ]; then
ln -fs "${VIRTUALENV_PATH}" "${COMPAT_VIRTUALENV_PATH}"
fi

if [ ! -e "${VIRTUALENV_PATH}/bin/pydoc" ]; then
mkdir -p "${VIRTUALENV_PATH}/bin"
cat <<EOS > "${VIRTUALENV_PATH}/bin/pydoc"
#!${VIRTUALENV_PATH}/bin/python
import pydoc
if __name__ == '__main__':
pydoc.cli()
EOS
chmod +x "${VIRTUALENV_PATH}/bin/pydoc"
fi

if [ -z "${NO_ENSUREPIP}" ]; then
## Install setuptools and pip.
PYENV_VERSION="${VIRTUALENV_NAME}" build_package_ensurepip
Expand Down
16 changes: 11 additions & 5 deletions test/pyvenv.bats
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,12 @@ unstub_pyenv() {

run pyenv-virtualenv venv

assert_success
assert_output <<OUT
PYENV_VERSION=3.5.1 python -m venv ${PYENV_ROOT}/versions/3.5.1/envs/venv
rehashed
OUT
assert [ -x "${PYENV_ROOT}/versions/3.5.1/envs/venv/bin/pydoc" ]
assert_success

unstub_pyenv
unstub pyenv-virtualenv-prefix
Expand All @@ -57,19 +58,20 @@ OUT

run pyenv-virtualenv venv

assert_success
assert_output <<OUT
PYENV_VERSION=3.5.1 virtualenv ${PYENV_ROOT}/versions/3.5.1/envs/venv
rehashed
OUT
assert [ -x "${PYENV_ROOT}/versions/3.5.1/envs/venv/bin/pydoc" ]
assert_success

unstub_pyenv
unstub pyenv-virtualenv-prefix
unstub pyenv-exec
teardown_m_venv "3.5.1"
}

@test "install virtualenv if venv is not avaialble" {
@test "install virtualenv if venv is not available" {
export PYENV_VERSION="3.2.1"
setup_version "3.2.1"
stub_pyenv "${PYENV_VERSION}"
Expand All @@ -81,12 +83,13 @@ OUT

run pyenv-virtualenv venv

assert_success
assert_output <<OUT
PYENV_VERSION=3.2.1 pip install virtualenv==13.1.2
PYENV_VERSION=3.2.1 virtualenv ${PYENV_ROOT}/versions/3.2.1/envs/venv
rehashed
OUT
assert [ -x "${PYENV_ROOT}/versions/3.2.1/envs/venv/bin/pydoc" ]
assert_success

unstub_pyenv
unstub pyenv-virtualenv-prefix
Expand All @@ -112,6 +115,7 @@ PYENV_VERSION=3.5.1 pip install virtualenv
PYENV_VERSION=3.5.1 virtualenv --python=${TMP}/python3 ${PYENV_ROOT}/versions/3.5.1/envs/venv
rehashed
OUT
assert [ -x "${PYENV_ROOT}/versions/3.5.1/envs/venv/bin/pydoc" ]
assert_success

unstub_pyenv
Expand All @@ -138,6 +142,7 @@ PYENV_VERSION=3.5.1 pip install virtualenv
PYENV_VERSION=3.5.1 virtualenv --python=${TMP}/python3 ${PYENV_ROOT}/versions/3.5.1/envs/venv
rehashed
OUT
assert [ -x "${PYENV_ROOT}/versions/3.5.1/envs/venv/bin/pydoc" ]
assert_success

unstub_pyenv
Expand All @@ -158,12 +163,13 @@ OUT

PIP_REQUIRE_VENV="true" run pyenv-virtualenv venv

assert_success
assert_output <<OUT
PIP_REQUIRE_VENV= PYENV_VERSION=3.2.1 pip install virtualenv==13.1.2
PIP_REQUIRE_VENV= PYENV_VERSION=3.2.1 virtualenv ${PYENV_ROOT}/versions/3.2.1/envs/venv
rehashed
OUT
assert [ -x "${PYENV_ROOT}/versions/3.2.1/envs/venv/bin/pydoc" ]
assert_success

unstub_pyenv
unstub pyenv-virtualenv-prefix
Expand Down
11 changes: 8 additions & 3 deletions test/virtualenv.bats
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,13 @@ unstub_pyenv() {

run pyenv-virtualenv "2.7.11" "venv"

assert_success
assert_output <<OUT
PYENV_VERSION=2.7.11 virtualenv ${PYENV_ROOT}/versions/2.7.11/envs/venv
Installing pip from https://bootstrap.pypa.io/get-pip.py...
rehashed
OUT
assert [ -x "${PYENV_ROOT}/versions/2.7.11/envs/venv/bin/pydoc" ]
assert_success

unstub_pyenv
unstub pyenv-virtualenv-prefix
Expand All @@ -60,12 +61,13 @@ OUT

run pyenv-virtualenv venv

assert_success
assert_output <<OUT
PYENV_VERSION=2.7.11 virtualenv ${PYENV_ROOT}/versions/2.7.11/envs/venv
Installing pip from https://bootstrap.pypa.io/get-pip.py...
rehashed
OUT
assert [ -x "${PYENV_ROOT}/versions/2.7.11/envs/venv/bin/pydoc" ]
assert_success

unstub_pyenv
unstub pyenv-version-name
Expand All @@ -92,6 +94,7 @@ PYENV_VERSION=2.7.11 virtualenv --verbose --python=${TMP}/python ${PYENV_ROOT}/v
Installing pip from https://bootstrap.pypa.io/get-pip.py...
rehashed
OUT
assert [ -x "${PYENV_ROOT}/versions/2.7.11/envs/venv/bin/pydoc" ]
assert_success

unstub_pyenv
Expand Down Expand Up @@ -119,6 +122,7 @@ PYENV_VERSION=2.7.11 virtualenv --verbose --python=${TMP}/python ${PYENV_ROOT}/v
Installing pip from https://bootstrap.pypa.io/get-pip.py...
rehashed
OUT
assert [ -x "${PYENV_ROOT}/versions/2.7.11/envs/venv/bin/pydoc" ]
assert_success

unstub_pyenv
Expand Down Expand Up @@ -176,12 +180,13 @@ OUT

run pyenv-virtualenv "2.7.11" "2.7.11/envs/foo"

assert_success
assert_output <<OUT
PYENV_VERSION=2.7.11 virtualenv ${PYENV_ROOT}/versions/2.7.11/envs/foo
Installing pip from https://bootstrap.pypa.io/get-pip.py...
rehashed
OUT
assert [ -x "${PYENV_ROOT}/versions/2.7.11/envs/foo/bin/pydoc" ]
assert_success

unstub_pyenv
unstub pyenv-virtualenv-prefix
Expand Down

0 comments on commit c2ba495

Please sign in to comment.