1 Commits

Author SHA1 Message Date
Yamashita Yuu
4d527c51e3 v20131216 2013-12-16 13:57:25 +09:00
24 changed files with 112 additions and 1927 deletions

View File

@@ -1,6 +0,0 @@
install: git clone https://github.com/sstephenson/bats.git
script: bats/bin/bats --tap test
language: c
notifications:
email:
on_success: never

125
README.md
View File

@@ -1,6 +1,4 @@
# pyenv-virtualenv # pyenv-virtualenv (a.k.a. [python-virtualenv](https://github.com/yyuu/python-virtualenv))
[![Build Status](https://travis-ci.org/yyuu/pyenv-virtualenv.png)](https://travis-ci.org/yyuu/pyenv-virtualenv)
pyenv-virtualenv is a [pyenv](https://github.com/yyuu/pyenv) plugin pyenv-virtualenv is a [pyenv](https://github.com/yyuu/pyenv) plugin
that provides a `pyenv virtualenv` command to create virtualenv for Python that provides a `pyenv virtualenv` command to create virtualenv for Python
@@ -14,30 +12,15 @@ to manage your virtualenvs.)
### Installing as a pyenv plugin ### Installing as a pyenv plugin
Installing pyenv-virtualenv as a pyenv plugin will give you access to the
`pyenv virtualenv` command.
$ git clone git://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
This will install the latest development version of pyenv-virtualenv into This will install the latest development version of pyenv-virtualenv into
the `~/.pyenv/plugins/pyenv-virtualenv` directory. the `~/.pyenv/plugins/pyenv-virtualenv` directory. From that directory, you
can check out a specific release tag. To update pyenv-virtualenv, run `git
**Important note:** If you installed pyenv into a non-standard directory, make sure that you clone this pull` to download the latest changes.
repo into the 'plugins' directory of wherever you installed into.
From inside that directory you can:
- Check out a specific release tag.
- Get the latest development release by running `git pull` to download the latest changes.
1. **Check out pyenv-virtualenv into plugin directory**
$ git clone https://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
2. **Add `pyenv virtualenv-init` to your shell** to enable activation of virtualenv
$ echo 'eval "$(pyenv virtualenv-init -)"' >> ~/.bash_profile
**Zsh note**: Modify your `~/.zshenv` file instead of `~/.bash_profile`.
3. **Restart your shell to the enable pyenv-virtualenv**
$ exec "$SHELL"
### Installing with Homebrew (for OS X users) ### Installing with Homebrew (for OS X users)
@@ -49,18 +32,11 @@ installed, you will also be able to use the `pyenv virtualenv` command.
*This is recommended method of installation if you installed pyenv *This is recommended method of installation if you installed pyenv
with Homebrew.* with Homebrew.*
``` brew install pyenv-virtualenv
$ brew install pyenv-virtualenv
```
Or, if you would like to install the latest development release: Or, if you would like to install the latest development release:
``` brew install --HEAD pyenv-virtualenv
$ brew install --HEAD pyenv-virtualenv
```
After installation, you'll still need to add `eval "$(pyenv virtualenv-init -)"` to your
profile (as stated in the caveats). You'll only ever have to do this once.
## Usage ## Usage
@@ -68,15 +44,13 @@ profile (as stated in the caveats). You'll only ever have to do this once.
### Using `pyenv virtualenv` with pyenv ### Using `pyenv virtualenv` with pyenv
To create a virtualenv for the Python version use with pyenv, run To create a virtualenv for the Python version use with pyenv, run
`pyenv virtualenv`, specifying the Python version you want and the name `pyenv virtualenv` with tha exact name of the version you want to create
of the virtualenv directory. For example, virtualenv. For example,
``` $ pyenv virtualenv 2.7.5 venv27
$ pyenv virtualenv 2.7.7 my-virtual-env-2.7.7
```
will create a virtualenv based on Python 2.7.7 virtualenvs will be created into a directory of the same name
under `~/.pyenv/versions` in a folder called `my-virtual-env-2.7.7`. under `~/.pyenv/versions`.
### Create virtualenv from current version ### Create virtualenv from current version
@@ -85,35 +59,21 @@ If there is only one argument is given to `pyenv virtualenv`,
virtualenv will be created with given name based on current virtualenv will be created with given name based on current
version. version.
``` $ pyenv version
$ pyenv version 3.3.2 (set by /home/yyuu/.pyenv/version)
3.4.1 (set by /home/yyuu/.pyenv/version) $ pyenv virtualenv venv33
$ pyenv virtualenv venv34
```
### List existing virtualenvs ### List existing virtualenvs
`pyenv virtualenvs` shows you the list of existing virtualenvs. `pyenv virtualenvs` shows you the list of existing virtualenvs.
``` $ pyenv shell venv27
$ pyenv shell venv27 $ pyenv virtualenvs
$ pyenv virtualenvs * venv27 (created from /home/yyuu/.pyenv/versions/2.7.5)
* venv27 (created from /home/yyuu/.pyenv/versions/2.7.7) venv33 (created from /home/yyuu/.pyenv/versions/3.3.2)
venv34 (created from /home/yyuu/.pyenv/versions/3.4.1)
```
### Activate virtualenv
Some external tools (e.g. [jedi](https://github.com/davidhalter/jedi)) might require you to `activate` the virtualenv.
The `pyenv-virtualenv` will automatically activate/deactivate the virtualenv if the `eval "$(pyenv virtualenv-init -)"` is properly configured in your shell.
You can also activate and deactivate a pyenv virtualenv this way:
pyenv activate <name>
pyenv deactivate
### Special environment variables ### Special environment variables
You can set certain environment variables to control the pyenv-virtualenv. You can set certain environment variables to control the pyenv-virtualenv.
@@ -123,8 +83,6 @@ You can set certain environment variables to control the pyenv-virtualenv.
* `VIRTUALENV_VERSION`, if set, forces pyenv-virtualenv to install desired * `VIRTUALENV_VERSION`, if set, forces pyenv-virtualenv to install desired
version of virtualenv. If the virtualenv has not been installed, version of virtualenv. If the virtualenv has not been installed,
pyenv-virtualenv will try to install the given version of virtualenv. pyenv-virtualenv will try to install the given version of virtualenv.
* `EZ_SETUP` and `GET_PIP`, if set and pyvenv is preferred than virtualenv,
use `ez_setup.py` and `get_pip.py` at specified location.
* `EZ_SETUP_URL` and `GET_PIP_URL`, if set and pyvenv is preferred * `EZ_SETUP_URL` and `GET_PIP_URL`, if set and pyvenv is preferred
than virtualenv, download `ez_setup.py` and `get_pip.py` from specified URL. than virtualenv, download `ez_setup.py` and `get_pip.py` from specified URL.
* `SETUPTOOLS_VERSION` and `PIP_VERSION`, if set and pyvenv is preferred * `SETUPTOOLS_VERSION` and `PIP_VERSION`, if set and pyvenv is preferred
@@ -133,43 +91,6 @@ You can set certain environment variables to control the pyenv-virtualenv.
## Version History ## Version History
#### 20140615
* Fix incompatibility issue of `pyenv activate` and `pyenv deactivate` (#26)
* Workaround for the issue with pyenv-which-ext (#26)
#### 20140614
* Add `pyenv virtualenv-init` to enable auto-activation feature (#24)
* Create symlinks for executables with version suffix (yyuu/pyenv#182)
#### 20140602
* Use new style GH raw url to avoid redirects (raw.github.com -> raw.githubusercontent.com)
* Repaired virtualenv activation and deactivation for the fish shell (#23)
#### 20140421
* Display error if `pyenv activate` was invoked as a command
* Fix completion of `pyenv activate` (#15)
* Use `virtualenv` instead of `pyvenv` if `-p` has given (yyuu/pyenv#158)
#### 20140123
* Add `activate` and `deactivate` to make `pyenv-virtualenv` work with [jedi](https://github.com/davidhalter/jedi) (#9)
* Use `ensurepip` to install `pip` if it is available
* Unset `PIP_REQUIRE_VENV` to avoid problem on the installation of `virtualenv` (#10)
* Add tests
#### 20140110.1
* Fix install script
#### 20140110
* Support environment variables of `EZ_SETUP` and `GET_PIP`.
* Support a short option `-p` of `virtualenv`.
#### 20131216 #### 20131216
* Use latest release of setuptools and pip if the version not given via environment variables. * Use latest release of setuptools and pip if the version not given via environment variables.

View File

@@ -1,32 +0,0 @@
#!/usr/bin/env bash
#
# Summary: Activate virtual environment
#
# Usage: pyenv activate <virtualenv>
# pyenv activate --unset
#
# Activate a Python virtualenv environment in current shell.
# This acts almost as same as `pyenv shell`, but this invokes the `activate`
# script in your shell.
#
# <virtualenv> should be a string matching a Python version known to pyenv.
set -e
[ -n "$PYENV_DEBUG" ] && set -x
# Provide pyenv completions
if [ "$1" = "--complete" ]; then
echo --unset
exec pyenv-virtualenvs --bare
fi
{ printf "\x1B[31;1m"
echo
echo "Failed to activate virtualenv."
echo
echo "Perhaps pyenv-virtualenv has not been loaded into your shell properly."
echo "Please restart current shell and try again."
echo
printf "\x1B[0m"
} 1>&2
exit 1

View File

@@ -1,21 +0,0 @@
#!/usr/bin/env bash
#
# Summary: Deactivate virtual environment
#
# Usage: pyenv deactivate
#
# Deactivate a Python virtual environment.
set -e
[ -n "$PYENV_DEBUG" ] && set -x
{ printf "\x1B[31;1m"
echo
echo "Failed to deactivate virtualenv."
echo
echo "Perhaps pyenv-virtualenv has not been loaded into your shell properly."
echo "Please restart current shell and try again."
echo
printf "\x1B[0m"
} 1>&2
exit 1

View File

@@ -1,92 +0,0 @@
#!/usr/bin/env bash
#
# Summary: Activate virtual environment
#
# Usage: pyenv activate <virtualenv>
# pyenv activate --unset
#
# Activate a Python virtualenv environment in current shell.
# This acts almost as same as `pyenv shell`, but this invokes the `activate`
# script in your shell.
#
# <virtualenv> should be a string matching a Python version known to pyenv.
set -e
[ -n "$PYENV_DEBUG" ] && set -x
# Provide pyenv completions
if [ "$1" = "--complete" ]; then
echo --unset
exec pyenv-virtualenvs --bare
fi
if [ "$1" = "--unset" ]; then
echo "pyenv deactivate"
exit
fi
versions=("$@")
if [ -z "$versions" ]; then
no_shell=1
OLDIFS="$IFS"
IFS=: versions=($(pyenv-version-name))
IFS="$OLDIFS"
fi
if [ -z "${PYENV_VIRTUALENV_INIT}" ]; then
# Backward compatibility issue
# https://github.com/yyuu/pyenv-virtualenv/issues/26
no_shell=
fi
if [ "${#versions[@]}" -gt 1 ]; then
echo "pyenv-virtualenv: cannot activate multiple versions at once: ${versions[@]}" 1>&2
exit 1
fi
pyenv-virtualenv-prefix "${versions}" 1>/dev/null
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
case "$shell" in
bash )
profile="$HOME/.bash_profile"
;;
zsh )
profile="$HOME/.zshrc"
;;
ksh )
profile="$HOME/.profile"
;;
fish )
profile="$HOME/.config/fish/config.fish"
;;
* )
profile="$HOME/.profile"
;;
esac
# Display setup instruction if 'pyenv virtualenv-init -' is not found in "$profile"
if [ -f "$profile" ] && grep -q 'pyenv init -' "$profile" && ! grep -q 'pyenv virtualenv-init -' "$profile"; then
pyenv-virtualenv-init >&2 || true
fi
if [ -z "$no_shell" ]; then
echo "pyenv shell \"${versions}\";"
fi
case "$shell" in
fish )
cat <<EOS
set -e PYENV_DEACTIVATE;
setenv PYENV_ACTIVATE "$(pyenv-prefix "${versions}")";
. "\${PYENV_ACTIVATE}/bin/activate.fish";
EOS
;;
* )
cat <<EOS
unset PYENV_DEACTIVATE;
export PYENV_ACTIVATE="$(pyenv-prefix "${versions}")";
source "\${PYENV_ACTIVATE}/bin/activate";
EOS
;;
esac

View File

@@ -1,38 +0,0 @@
#!/usr/bin/env bash
#
# Summary: Deactivate virtual environment
#
# Usage: pyenv deactivate
#
# Deactivate a Python virtual environment.
set -e
[ -n "$PYENV_DEBUG" ] && set -x
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
case "$shell" in
fish )
cat <<EOS
if functions -q deactivate
setenv PYENV_DEACTIVATE "\$PYENV_ACTIVATE";
set -e PYENV_ACTIVATE;
deactivate;
end;
EOS
;;
* )
cat <<EOS
if declare -f deactivate 1>/dev/null 2>&1; then
export PYENV_DEACTIVATE="\$PYENV_ACTIVATE";
unset PYENV_ACTIVATE;
deactivate;
fi;
EOS
;;
esac
if [ -z "${PYENV_VIRTUALENV_INIT}" ]; then
# Backward compatibility issue
# https://github.com/yyuu/pyenv-virtualenv/issues/26
echo "pyenv shell --unset;"
fi

View File

@@ -2,14 +2,16 @@
# #
# Summary: Create a Python virtualenv using the pyenv-virtualenv plugin # Summary: Create a Python virtualenv using the pyenv-virtualenv plugin
# #
# Usage: pyenv virtualenv [-f|--force] [VIRTUALENV_OPTIONS] <version> <virtualenv-name> # Usage: pyenv virtualenv [-f|--force] [-u|--upgrade] [VIRTUALENV_OPTIONS] <version> <virtualenv-name>
# pyenv virtualenv --version # pyenv virtualenv --version
# pyenv virtualenv --help # pyenv virtualenv --help
# #
# -u/--upgrade Upgrade existing virtualenv to use new version of Python,
# assuming Python has been upgraded in-place.
# -f/--force Install even if the version appears to be installed already # -f/--force Install even if the version appears to be installed already
# #
PYENV_VIRTUALENV_VERSION="20140615" PYENV_VIRTUALENV_VERSION="20131216"
set -e set -e
[ -n "$PYENV_DEBUG" ] && set -x [ -n "$PYENV_DEBUG" ] && set -x
@@ -23,9 +25,6 @@ if [ -z "$PYENV_ROOT" ]; then
PYENV_ROOT="${HOME}/.pyenv" PYENV_ROOT="${HOME}/.pyenv"
fi fi
unset PIP_REQUIRE_VENV
unset PIP_REQUIRE_VIRTUALENV
# Define library functions # Define library functions
parse_options() { parse_options() {
OPTIONS=() OPTIONS=()
@@ -101,17 +100,8 @@ http_get_wget() {
} }
version() { version() {
detect_venv local version="$(venv --version 2>/dev/null || true)"
local version echo "pyenv-virtualenv ${PYENV_VIRTUALENV_VERSION} (virtualenv ${version:-unknown})"
if [ -n "$USE_PYVENV" ]; then
version="$(pyenv-which pyvenv 2>/dev/null || true)"
version="${version#$(pyenv-root)/versions/}"
version="${version%/bin/pyvenv}"
echo "pyenv-virtualenv ${PYENV_VIRTUALENV_VERSION} (pyvenv ${version:-unknown})"
else
version="$(venv --version 2>/dev/null || true)"
echo "pyenv-virtualenv ${PYENV_VIRTUALENV_VERSION} (virtualenv ${version:-unknown})"
fi
} }
usage() { usage() {
@@ -121,114 +111,20 @@ usage() {
[ -z "$1" ] || exit "$1" [ -z "$1" ] || exit "$1"
} }
detect_venv() { virtualenv_is_pyvenv() {
# Check the existence of executables as a workaround for the issue with pyenv-which-ext # Use pyvenv only if virtualenv is not installed and there is pyvenv
# https://github.com/yyuu/pyenv-virtualenv/issues/26 if pyenv-which "virtualenv" 1>/dev/null 2>&1; then
if [ -x "$(pyenv-prefix)/bin/virtualenv" ]; then return 1
HAS_VIRTUALENV=1 else
fi pyenv-which "pyvenv" 1>/dev/null 2>&1
if [ -x "$(pyenv-prefix)/bin/pyvenv" ]; then
HAS_PYVENV=1
fi
# Use pyvenv only if there is pyvenv, virtualenv is not installed, and `-p` not given
if [ -n "${HAS_PYVENV}" ] && [ -z "${HAS_VIRTUALENV}" ] && [ -z "${VIRTUALENV_PYTHON}" ]; then
USE_PYVENV=1
fi fi
} }
venv() { venv() {
local args=("$@") if virtualenv_is_pyvenv; then
if [ -n "${USE_PYVENV}" ]; then pyenv-exec pyvenv "$@"
pyenv-exec pyvenv "${args[@]}"
else else
pyenv-exec virtualenv "${args[@]}" pyenv-exec virtualenv "$@"
fi
}
build_package_ez_setup() {
local ez_setup="${PYENV_VIRTUALENV_CACHE_PATH}/ez_setup.py"
rm -f "${ez_setup}"
{ if [ "${EZ_SETUP+defined}" ] && [ -f "${EZ_SETUP}" ]; then
echo "Installing setuptools from ${EZ_SETUP}..." 1>&2
cat "${EZ_SETUP}"
else
[ -n "${EZ_SETUP_URL}" ] || EZ_SETUP_URL="https://bootstrap.pypa.io/ez_setup.py"
echo "Installing setuptools from ${EZ_SETUP_URL}..." 1>&2
http get "${EZ_SETUP_URL}"
fi
} 1> "${ez_setup}"
pyenv-exec python "${ez_setup}" ${EZ_SETUP_OPTS} 1>&2 || {
echo "error: failed to install setuptools via ez_setup.py" >&2
return 1
}
}
build_package_get_pip() {
local get_pip="${PYENV_VIRTUALENV_CACHE_PATH}/get-pip.py"
rm -f "${get_pip}"
{ if [ "${GET_PIP+defined}" ] && [ -f "${GET_PIP}" ]; then
echo "Installing pip from ${GET_PIP}..." 1>&2
cat "${GET_PIP}"
else
[ -n "${GET_PIP_URL}" ] || GET_PIP_URL="https://bootstrap.pypa.io/get-pip.py"
echo "Installing pip from ${GET_PIP_URL}..." 1>&2
http get "${GET_PIP_URL}"
fi
} 1> "${get_pip}"
pyenv-exec python "${get_pip}" ${GET_PIP_OPTS} 1>&2 || {
echo "error: failed to install pip via get-pip.py" >&2
return 1
}
}
build_package_ensurepip() {
pyenv-exec python -m ensurepip 2>/dev/null|| {
build_package_ez_setup "$@" && build_package_get_pip "$@"
} || return 1
create_symlinks "$(pyenv-exec python -c 'import sys;v=sys.version_info;sys.stdout.write("python%d.%d"%(v[0],v[1]))')"
}
create_symlinks() {
local suffix="$1"
local file link
shopt -s nullglob
for file in "${VIRTUALENV_PATH}/bin"/*; do
if [[ "${file##*/}" == *"${suffix}" ]]; then
if [[ "${file}" == *"-${suffix}" ]]; then
link="${file%%-${suffix}}"
else
link="${file%%${suffix}}"
fi
if [ ! -e "${link}" ]; then
( cd "${file%/*}" && ln -fs "${file##*/}" "${link##*/}" )
fi
fi
done
shopt -u nullglob
}
prepare_requirements() {
pyenv-exec pip freeze > "${REQUIREMENTS}"
mv -f "${VIRTUALENV_PATH}" "${VIRTUALENV_ORIG}"
}
install_requirements() {
if [ -f "${REQUIREMENTS}" ]; then
## Migrate previously installed packages from requirements.txt
pyenv-exec pip install $QUIET $VERBOSE --requirement "${REQUIREMENTS}" || {
echo
echo "PIP INSTALL FAILED"
echo
echo "Inspect or clean up the original tree at ${VIRTUALENV_ORIG}"
echo
echo "Package list:"
cat "${REQUIREMENTS}" | sed 's/^/ * /'
return 1
} 1>&2
rm -f "${REQUIREMENTS}"
rm -fr "${VIRTUALENV_ORIG}"
fi fi
} }
@@ -239,7 +135,6 @@ fi
VIRTUALENV_OPTIONS=() VIRTUALENV_OPTIONS=()
unset FORCE unset FORCE
unset VIRTUALENV_PYTHON
unset QUIET unset QUIET
unset UPGRADE unset UPGRADE
unset VERBOSE unset VERBOSE
@@ -253,10 +148,6 @@ for option in "${OPTIONS[@]}"; do
"h" | "help" ) "h" | "help" )
usage 0 usage 0
;; ;;
"p" | "python" )
VIRTUALENV_PYTHON="${ARGUMENTS[0]}"
ARGUMENTS=("${ARGUMENTS[@]:1}") # shift 1
;;
"q" | "quiet" ) "q" | "quiet" )
QUIET="--quiet" QUIET="--quiet"
;; ;;
@@ -271,17 +162,13 @@ for option in "${OPTIONS[@]}"; do
exit 0 exit 0
;; ;;
* ) # virtualenv long options * ) # virtualenv long options
if [[ "$option" == "python="* ]]; then VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--$option"
VIRTUALENV_PYTHON="${option#python=}"
else
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--$option"
fi
;; ;;
esac esac
done done
if [[ "${#ARGUMENTS[@]}" == 0 ]]; then if [[ "${#ARGUMENTS[@]}" == 0 ]]; then
echo "pyenv-virtualenv: no virtualenv name given." 1>&2 echo "pyenv: no virtualenv name given." 1>&2
exit 1 exit 1
elif [[ "${#ARGUMENTS[@]}" == 1 ]]; then elif [[ "${#ARGUMENTS[@]}" == 1 ]]; then
# If only one argument given, use current version as source version # If only one argument given, use current version as source version
@@ -309,40 +196,26 @@ else
TMP="${TMPDIR%/}" TMP="${TMPDIR%/}"
fi fi
SEED="$(date "+%Y%m%d%H%M%S").$$"
UPGRADE_PATH="${TMP}/pyenv-virtualenv.${SEED}"
UPGRADE_LIST="${TMP}/pyenv-virtualenv.${SEED}.txt"
VIRTUALENV_PATH="${PYENV_ROOT}/versions/${VIRTUALENV_NAME}" VIRTUALENV_PATH="${PYENV_ROOT}/versions/${VIRTUALENV_NAME}"
unset HAS_VIRTUALENV if virtualenv_is_pyvenv; then
unset HAS_PYVENV
unset USE_PYVENV
detect_venv
SEED="$(date "+%Y%m%d%H%M%S").$$"
VIRTUALENV_ORIG="${VIRTUALENV_PATH}.${SEED}"
REQUIREMENTS="${TMP}/requirements.${SEED}.txt"
# Upgrade existing virtualenv
if [ -n "$UPGRADE" ]; then
FORCE=1
# pyvenv has `--upgrade` by default
if [ -n "${USE_PYVENV}" ]; then
unset UPGRADE
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--upgrade"
fi
fi
if [ -n "${USE_PYVENV}" ]; then
# Unset some arguments not supported by pyvenv # Unset some arguments not supported by pyvenv
unset QUIET unset QUIET
unset VERBOSE unset VERBOSE
else if [ -n "$UPGRADE" ]; then
if [ -n "${VIRTUALENV_PYTHON}" ]; then unset UPGRADE
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--python=${VIRTUALENV_PYTHON}" VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--upgrade"
fi fi
if [ -z "${HAS_VIRTUALENV}" ]; then else
pyenv-which "virtualenv" 1>/dev/null 2>&1 || {
VIRTUALENV_VERSION="==${VIRTUALENV_VERSION}" VIRTUALENV_VERSION="==${VIRTUALENV_VERSION}"
pyenv-exec pip install $QUIET $VERBOSE "virtualenv${VIRTUALENV_VERSION%==}" pyenv-exec pip install $QUIET $VERBOSE "virtualenv${VIRTUALENV_VERSION%==}"
HAS_VIRTUALENV=1 pyenv-rehash
fi }
fi fi
# Unset environment variables which starts with `VIRTUALENV_`. # Unset environment variables which starts with `VIRTUALENV_`.
@@ -350,15 +223,6 @@ fi
unset VIRTUALENV_VERSION unset VIRTUALENV_VERSION
# Download specified version of ez_setup.py/get-pip.py
if [ -n "${SETUPTOOLS_VERSION}" ]; then
EZ_SETUP_URL="https://bitbucket.org/pypa/setuptools/raw/${SETUPTOOLS_VERSION}/ez_setup.py"
fi
if [ -n "${PIP_VERSION}" ]; then
GET_PIP_URL="https://raw.githubusercontent.com/pypa/pip/${PIP_VERSION}/contrib/get-pip.py"
fi
# Define `before_virtualenv` and `after_virtualenv` functions that allow # Define `before_virtualenv` and `after_virtualenv` functions that allow
# plugin hooks to register a string of code for execution before or # plugin hooks to register a string of code for execution before or
# after the installation process. # after the installation process.
@@ -375,10 +239,9 @@ after_virtualenv() {
} }
# Load plugin hooks. # Load plugin hooks.
OLDIFS="$IFS" for script in $(pyenv-hooks virtualenv); do
IFS=$'\n' scripts=(`pyenv-hooks virtualenv`) source "$script"
IFS="$OLDIFS" done
for script in "${scripts[@]}"; do source "$script"; done
[ -d "${VIRTUALENV_PATH}" ] && PREFIX_EXISTS=1 [ -d "${VIRTUALENV_PATH}" ] && PREFIX_EXISTS=1
@@ -387,7 +250,7 @@ for script in "${scripts[@]}"; do source "$script"; done
# the --force option was specified. # the --force option was specified.
if [ -d "${VIRTUALENV_PATH}/bin" ]; then if [ -d "${VIRTUALENV_PATH}/bin" ]; then
if [ -z "$FORCE" ]; then if [ -z "$FORCE" ]; then
echo "pyenv-virtualenv: ${VIRTUALENV_PATH} already exists" 1>&2 echo "pyenv: ${VIRTUALENV_PATH} already exists" 1>&2
read -p "continue with installation? (y/N) " read -p "continue with installation? (y/N) "
case "$REPLY" in case "$REPLY" in
@@ -397,7 +260,8 @@ if [ -d "${VIRTUALENV_PATH}/bin" ]; then
fi fi
if [ -n "$UPGRADE" ]; then if [ -n "$UPGRADE" ]; then
PYENV_VERSION="${VIRTUALENV_NAME}" prepare_requirements PYENV_VERSION="${VIRTUALENV_NAME}" pyenv-exec pip freeze >"${UPGRADE_LIST}"
mv -f "${VIRTUALENV_PATH}" "${UPGRADE_PATH}"
fi fi
fi fi
@@ -417,13 +281,53 @@ STATUS=0
# change to cache directory to reuse them between invocation. # change to cache directory to reuse them between invocation.
mkdir -p "${PYENV_VIRTUALENV_CACHE_PATH}" mkdir -p "${PYENV_VIRTUALENV_CACHE_PATH}"
cd "${PYENV_VIRTUALENV_CACHE_PATH}" cd "${PYENV_VIRTUALENV_CACHE_PATH}"
venv $QUIET $VERBOSE "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}" || STATUS="$?" venv $QUIET $VERBOSE "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}" && {
if virtualenv_is_pyvenv; then
[ -n "${EZ_SETUP_URL}" ] || {
if [ -n "${SETUPTOOLS_VERSION}" ]; then
EZ_SETUP_URL="https://bitbucket.org/pypa/setuptools/raw/${SETUPTOOLS_VERSION}/ez_setup.py"
else
EZ_SETUP_URL="https://bitbucket.org/pypa/setuptools/downloads/ez_setup.py"
fi
}
PYENV_VERSION="${VIRTUALENV_NAME}" pyenv-exec python -c 'import setuptools' 1>/dev/null 2>&1 || {
echo "Installing setuptools from ${EZ_SETUP_URL}..." 1>&2
http get "${EZ_SETUP_URL}" | PYENV_VERSION="${VIRTUALENV_NAME}" pyenv-exec python
}
## Install setuptools and pip [ -n "${GET_PIP_URL}" ] || {
PYENV_VERSION="${VIRTUALENV_NAME}" build_package_ensurepip if [ -n "${PIP_VERSION}" ]; then
GET_PIP_URL="https://raw.github.com/pypa/pip/${PIP_VERSION}/contrib/get-pip.py"
else
GET_PIP_URL="https://raw.github.com/pypa/pip/master/contrib/get-pip.py"
fi
}
PYENV_VERSION="${VIRTUALENV_NAME}" pyenv-which pip 1>/dev/null 2>&1 || {
echo "Installing pip from ${GET_PIP_URL}..." 1>&2
http get "${GET_PIP_URL}" | PYENV_VERSION="${VIRTUALENV_NAME}" pyenv-exec python
}
fi
} || STATUS="$?"
## Migrate previously installed packages from requirements.txt ## Migrate previously installed packages from requirements.txt
PYENV_VERSION="${VIRTUALENV_NAME}" install_requirements || true if [ -n "$UPGRADE" ]; then
UPGRADE_STATUS=0
PYENV_VERSION="${VIRTUALENV_NAME}" pyenv-exec pip install $QUIET $VERBOSE --requirement "${UPGRADE_LIST}" || UPGRADE_STATUS=$?
if [ "$UPGRADE_STATUS" == "0" ]; then
rm -f "${UPGRADE_LIST}"
rm -fr "${UPGRADE_PATH}"
else
{ echo
echo "UPGRADE FAILED"
echo
echo "Inspect or clean up the original tree at ${UPGRADE_PATH}"
echo
echo "Package list:"
cat "${UPGRADE_LIST}"
} 1>&2
STATUS="$UPGRADE_STATUS"
fi
fi
# Execute `after_virtualenv` hooks # Execute `after_virtualenv` hooks
for hook in "${after_hooks[@]}"; do eval "$hook"; done for hook in "${after_hooks[@]}"; do eval "$hook"; done

View File

@@ -1,146 +0,0 @@
#!/usr/bin/env bash
# Summary: Configure the shell environment for pyenv-virtualenv
# Usage: eval "$(pyenv virtualenv-init - [<shell>])"
#
# Automatically activates a Python virtualenv environment based on current
# pyenv version.
#
set -e
[ -n "$PYENV_DEBUG" ] && set -x
print=""
for args in "$@"
do
if [ "$args" = "-" ]; then
print=1
shift
fi
done
shell="$1"
if [ -z "$shell" ]; then
shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)"
shell="${shell##-}"
shell="${shell%% *}"
shell="$(basename "${shell:-$SHELL}")"
fi
if [ -z "$print" ]; then
case "$shell" in
bash )
profile='~/.bash_profile'
;;
zsh )
profile='~/.zshrc'
;;
ksh )
profile='~/.profile'
;;
fish )
profile='~/.config/fish/config.fish'
;;
* )
profile='your profile'
;;
esac
{ echo "# Load pyenv-virtualenv automatically by adding"
echo "# the following to ${profile}:"
echo
case "$shell" in
fish )
echo 'status --is-interactive; and . (pyenv virtualenv-init -|psub)'
;;
* )
echo 'eval "$(pyenv virtualenv-init -)"'
;;
esac
echo
} >&2
exit 1
fi
case "$shell" in
fish )
echo "setenv PYENV_VIRTUALENV_INIT 1;"
;;
* )
echo "export PYENV_VIRTUALENV_INIT=1;"
;;
esac
case "$shell" in
fish )
cat <<EOS
function _pyenv_virtualenv_hook --on-event fish_prompt;
if [ -n "\$PYENV_ACTIVATE" ]
if [ (pyenv version-name) = "system" ]
eval (pyenv sh-deactivate); or true
return 0
end
if [ "\$PYENV_ACTIVATE" != (pyenv prefix) ]
eval (pyenv sh-deactivate); or true
eval (pyenv sh-activate 2>/dev/null); or true
end
else
if [ "\$PYENV_DEACTIVATE" != (pyenv prefix) ]
eval (pyenv sh-activate 2>/dev/null); or true
end
end
end
EOS
;;
ksh )
cat <<EOS
function _pyenv_virtualenv_hook() {
EOS
;;
* )
cat <<EOS
_pyenv_virtualenv_hook() {
EOS
;;
esac
if [[ "$shell" != "fish" ]]; then
cat <<EOS
if [ -n "\$PYENV_ACTIVATE" ]; then
if [ "x\`pyenv version-name\`" = "xsystem" ]; then
pyenv deactivate || true
return 0
fi
if [ "x\$PYENV_ACTIVATE" != "x\`pyenv prefix\`" ]; then
pyenv deactivate || true
pyenv activate 2>/dev/null || true
fi
else
if [ "x\$PYENV_DEACTIVATE" != "x\`pyenv prefix\`" ]; then
pyenv activate 2>/dev/null || true
fi
fi
};
EOS
case "$shell" in
bash )
cat <<EOS
if ! [[ "\$PROMPT_COMMAND" =~ _pyenv_virtualenv_hook ]]; then
PROMPT_COMMAND="_pyenv_virtualenv_hook;\$PROMPT_COMMAND";
fi
EOS
;;
zsh )
cat <<EOS
typeset -a precmd_functions
if [[ -z \$precmd_functions[(r)_pyenv_virtualenv_hook] ]]; then
precmd_functions+=_pyenv_virtualenv_hook;
fi
EOS
;;
* )
# FIXME: what should i do here??
;;
esac
fi

View File

@@ -35,9 +35,11 @@ for version in "${versions[@]}"; do
PREFIX="$(pyenv-prefix "${version}")" PREFIX="$(pyenv-prefix "${version}")"
if [ -f "${PREFIX}/bin/activate" ]; then if [ -f "${PREFIX}/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") if [ -d "${VIRTUALENV_PREFIX_PATH}" ]; then
VIRTUALENV_PREFIX_PATHS=("${VIRTUALENV_PREFIX_PATHS[@]}" "$VIRTUALENV_PREFIX_PATH")
fi
else else
echo "pyenv-virtualenv: version \`${version}' is not a virtualenv" 1>&2 echo "pyenv: version \`${version}' is not a virtualenv" 1>&2
exit 1 exit 1
fi fi
done done

View File

@@ -1,18 +1,17 @@
#!/bin/sh #!/bin/sh
# Usage: PREFIX=/usr/local ./install.sh
#
# Installs pyenv-virtualenv under $PREFIX.
set -e set -e
cd "$(dirname "$0")"
if [ -z "${PREFIX}" ]; then if [ -z "${PREFIX}" ]; then
PREFIX="/usr/local" PREFIX="/usr/local"
fi fi
BIN_PATH="${PREFIX}/bin" BIN_PATH="${PREFIX}/bin"
mkdir -p "$BIN_PATH" mkdir -p "${BIN_PATH}"
install -p bin/* "$BIN_PATH" for file in bin/*; do
cp "${file}" "${BIN_PATH}"
done
echo "Installed pyenv-virtualenv at ${PREFIX}"

View File

@@ -1,168 +0,0 @@
#!/usr/bin/env bats
load test_helper
setup() {
export HOME="${TMP}"
export PYENV_ROOT="${TMP}/pyenv"
}
@test "activate virtualenv from current version" {
export PYENV_VIRTUALENV_INIT=1
stub pyenv-version-name "echo venv"
stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
PYENV_SHELL="bash" PYENV_VERSION="venv" run pyenv-sh-activate
unstub pyenv-version-name
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
assert_success
assert_output <<EOS
unset PYENV_DEACTIVATE;
export PYENV_ACTIVATE="${PYENV_ROOT}/versions/venv";
source "\${PYENV_ACTIVATE}/bin/activate";
EOS
}
@test "activate virtualenv from current version (without pyenv-virtualenv-init)" {
export PYENV_VIRTUALENV_INIT=
stub pyenv-version-name "echo venv"
stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
PYENV_SHELL="bash" PYENV_VERSION="venv" run pyenv-sh-activate
unstub pyenv-version-name
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
assert_success
assert_output <<EOS
pyenv shell "venv";
unset PYENV_DEACTIVATE;
export PYENV_ACTIVATE="${PYENV_ROOT}/versions/venv";
source "\${PYENV_ACTIVATE}/bin/activate";
EOS
}
@test "activate virtualenv from current version (fish)" {
export PYENV_VIRTUALENV_INIT=1
stub pyenv-version-name "echo venv"
stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
PYENV_SHELL="fish" PYENV_VERSION="venv" run pyenv-sh-activate
unstub pyenv-version-name
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
assert_success
assert_output <<EOS
set -e PYENV_DEACTIVATE;
setenv PYENV_ACTIVATE "${PYENV_ROOT}/versions/venv";
. "\${PYENV_ACTIVATE}/bin/activate.fish";
EOS
}
@test "activate virtualenv from current version (fish) (without pyenv-virtualenv-init)" {
export PYENV_VIRTUALENV_INIT=
stub pyenv-version-name "echo venv"
stub pyenv-virtualenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
stub pyenv-prefix "venv : echo \"${PYENV_ROOT}/versions/venv\""
PYENV_SHELL="fish" PYENV_VERSION="venv" run pyenv-sh-activate
unstub pyenv-version-name
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
assert_success
assert_output <<EOS
pyenv shell "venv";
set -e PYENV_DEACTIVATE;
setenv PYENV_ACTIVATE "${PYENV_ROOT}/versions/venv";
. "\${PYENV_ACTIVATE}/bin/activate.fish";
EOS
}
@test "activate virtualenv from command-line argument" {
export PYENV_VIRTUALENV_INIT=1
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
run pyenv-sh-activate "venv27"
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
assert_success
assert_output <<EOS
pyenv shell "venv27";
unset PYENV_DEACTIVATE;
export PYENV_ACTIVATE="${PYENV_ROOT}/versions/venv27";
source "\${PYENV_ACTIVATE}/bin/activate";
EOS
}
@test "activate virtualenv from command-line argument (without pyenv-virtualenv-init)" {
export PYENV_VIRTUALENV_INIT=
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
run pyenv-sh-activate "venv27"
unstub pyenv-virtualenv-prefix
unstub pyenv-prefix
assert_success
assert_output <<EOS
pyenv shell "venv27";
unset PYENV_DEACTIVATE;
export PYENV_ACTIVATE="${PYENV_ROOT}/versions/venv27";
source "\${PYENV_ACTIVATE}/bin/activate";
EOS
}
@test "unset invokes deactivate" {
run pyenv-sh-activate --unset
assert_success
assert_output <<EOS
pyenv deactivate
EOS
}
@test "should fail if the version is not a virtualenv" {
stub pyenv-virtualenv-prefix "3.3.3 : false"
run pyenv-sh-activate "3.3.3"
unstub pyenv-virtualenv-prefix
assert_failure
}
@test "should fail if there are multiple versions" {
run pyenv-sh-activate "venv" "venv27"
assert_failure
assert_output <<EOS
pyenv-virtualenv: cannot activate multiple versions at once: venv venv27
EOS
}
@test "should fail if activate is invoked as a command" {
run pyenv-activate
assert_failure
}

View File

@@ -1,75 +0,0 @@
#!/usr/bin/env bats
load test_helper
setup() {
export PYENV_ROOT="${TMP}/pyenv"
}
@test "deactivate virtualenv" {
export PYENV_VIRTUALENV_INIT=1
PYENV_SHELL="bash" run pyenv-sh-deactivate
assert_success
assert_output <<EOS
if declare -f deactivate 1>/dev/null 2>&1; then
export PYENV_DEACTIVATE="\$PYENV_ACTIVATE";
unset PYENV_ACTIVATE;
deactivate;
fi;
EOS
}
@test "deactivate virtualenv (without pyenv-virtualenv-init)" {
export PYENV_VIRTUALENV_INIT=
PYENV_SHELL="bash" run pyenv-sh-deactivate
assert_success
assert_output <<EOS
if declare -f deactivate 1>/dev/null 2>&1; then
export PYENV_DEACTIVATE="\$PYENV_ACTIVATE";
unset PYENV_ACTIVATE;
deactivate;
fi;
pyenv shell --unset;
EOS
}
@test "deactivate virtualenv (fish)" {
export PYENV_VIRTUALENV_INIT=1
PYENV_SHELL="fish" run pyenv-sh-deactivate
assert_success
assert_output <<EOS
if functions -q deactivate
setenv PYENV_DEACTIVATE "\$PYENV_ACTIVATE";
set -e PYENV_ACTIVATE;
deactivate;
end;
EOS
}
@test "deactivate virtualenv (fish) (without pyenv-virtualenv-init)" {
export PYENV_VIRTUALENV_INIT=
PYENV_SHELL="fish" run pyenv-sh-deactivate
assert_success
assert_output <<EOS
if functions -q deactivate
setenv PYENV_DEACTIVATE "\$PYENV_ACTIVATE";
set -e PYENV_ACTIVATE;
deactivate;
end;
pyenv shell --unset;
EOS
}
@test "should fail if deactivate is invoked as a command" {
run pyenv-deactivate
assert_failure
}

View File

@@ -1,35 +0,0 @@
#!/usr/bin/env bats
load test_helper
setup() {
export PYENV_ROOT="${TMP}/pyenv"
export HOOK_PATH="${TMP}/i has hooks"
mkdir -p "$HOOK_PATH"
}
@test "pyenv-virtualenv hooks" {
cat > "${HOOK_PATH}/virtualenv.bash" <<OUT
before_virtualenv 'echo before: \$VIRTUALENV_PATH'
after_virtualenv 'echo after: \$STATUS'
OUT
stub pyenv-prefix "echo '${PYENV_ROOT}/versions/3.2.1'"
stub pyenv-prefix "echo '${PYENV_ROOT}/versions/3.2.1'"
stub pyenv-prefix "echo '${PYENV_ROOT}/versions/3.2.1'"
stub pyenv-hooks "virtualenv : echo '$HOOK_PATH'/virtualenv.bash"
stub pyenv-exec "echo PYENV_VERSION=3.2.1 \"\$@\""
stub pyenv-rehash "echo rehashed"
create_executable "3.2.1" "virtualenv"
remove_executable "3.2.1" "pyvenv"
run pyenv-virtualenv "3.2.1" venv
assert_success
assert_output <<-OUT
before: ${PYENV_ROOT}/versions/venv
PYENV_VERSION=3.2.1 virtualenv ${PYENV_ROOT}/versions/venv
after: 0
rehashed
OUT
}

View File

@@ -1,105 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "detect parent shell" {
root="$(cd $BATS_TEST_DIRNAME/.. && pwd)"
SHELL=/bin/false run pyenv-virtualenv-init -
assert_success
assert_output_contains ' PROMPT_COMMAND="_pyenv_virtualenv_hook;$PROMPT_COMMAND";'
}
@test "sh-compatible instructions" {
run pyenv-virtualenv-init bash
assert [ "$status" -eq 1 ]
assert_output_contains 'eval "$(pyenv virtualenv-init -)"'
run pyenv-virtualenv-init zsh
assert [ "$status" -eq 1 ]
assert_output_contains 'eval "$(pyenv virtualenv-init -)"'
}
@test "fish instructions" {
run pyenv-virtualenv-init fish
assert [ "$status" -eq 1 ]
assert_output_contains 'status --is-interactive; and . (pyenv virtualenv-init -|psub)'
}
@test "outputs bash-specific syntax" {
run pyenv-virtualenv-init - bash
assert_success
assert_output <<EOS
export PYENV_VIRTUALENV_INIT=1;
_pyenv_virtualenv_hook() {
if [ -n "\$PYENV_ACTIVATE" ]; then
if [ "x\`pyenv version-name\`" = "xsystem" ]; then
pyenv deactivate || true
return 0
fi
if [ "x\$PYENV_ACTIVATE" != "x\`pyenv prefix\`" ]; then
pyenv deactivate || true
pyenv activate 2>/dev/null || true
fi
else
if [ "x\$PYENV_DEACTIVATE" != "x\`pyenv prefix\`" ]; then
pyenv activate 2>/dev/null || true
fi
fi
};
if ! [[ "\$PROMPT_COMMAND" =~ _pyenv_virtualenv_hook ]]; then
PROMPT_COMMAND="_pyenv_virtualenv_hook;\$PROMPT_COMMAND";
fi
EOS
}
@test "outputs fish-specific syntax" {
run pyenv-virtualenv-init - fish
assert_success
assert_output <<EOS
setenv PYENV_VIRTUALENV_INIT 1;
function _pyenv_virtualenv_hook --on-event fish_prompt;
if [ -n "\$PYENV_ACTIVATE" ]
if [ (pyenv version-name) = "system" ]
eval (pyenv sh-deactivate); or true
return 0
end
if [ "\$PYENV_ACTIVATE" != (pyenv prefix) ]
eval (pyenv sh-deactivate); or true
eval (pyenv sh-activate 2>/dev/null); or true
end
else
if [ "\$PYENV_DEACTIVATE" != (pyenv prefix) ]
eval (pyenv sh-activate 2>/dev/null); or true
end
end
end
EOS
}
@test "outputs zsh-specific syntax" {
run pyenv-virtualenv-init - zsh
assert_success
assert_output <<EOS
export PYENV_VIRTUALENV_INIT=1;
_pyenv_virtualenv_hook() {
if [ -n "\$PYENV_ACTIVATE" ]; then
if [ "x\`pyenv version-name\`" = "xsystem" ]; then
pyenv deactivate || true
return 0
fi
if [ "x\$PYENV_ACTIVATE" != "x\`pyenv prefix\`" ]; then
pyenv deactivate || true
pyenv activate 2>/dev/null || true
fi
else
if [ "x\$PYENV_DEACTIVATE" != "x\`pyenv prefix\`" ]; then
pyenv activate 2>/dev/null || true
fi
fi
};
typeset -a precmd_functions
if [[ -z \$precmd_functions[(r)_pyenv_virtualenv_hook] ]]; then
precmd_functions+=_pyenv_virtualenv_hook;
fi
EOS
}

View File

@@ -1,48 +0,0 @@
#!/usr/bin/env bats
load test_helper
@test "installs pyenv-virtualenv into PREFIX" {
cd "$TMP"
PREFIX="${PWD}/usr" run "${BATS_TEST_DIRNAME}/../install.sh"
assert_success ""
cd usr
assert [ -x bin/pyenv-activate ]
assert [ -x bin/pyenv-deactivate ]
assert [ -x bin/pyenv-sh-activate ]
assert [ -x bin/pyenv-sh-deactivate ]
assert [ -x bin/pyenv-virtualenv ]
assert [ -x bin/pyenv-virtualenv-init ]
assert [ -x bin/pyenv-virtualenv-prefix ]
assert [ -x bin/pyenv-virtualenvs ]
}
@test "overwrites old installation" {
cd "$TMP"
mkdir -p bin
touch bin/pyenv-virtualenv
PREFIX="$PWD" run "${BATS_TEST_DIRNAME}/../install.sh"
assert_success ""
assert [ -x bin/pyenv-virtualenv ]
run grep "virtualenv" bin/pyenv-virtualenv
assert_success
}
@test "unrelated files are untouched" {
cd "$TMP"
mkdir -p bin share/bananas
chmod g-w bin
touch bin/bananas
PREFIX="$PWD" run "${BATS_TEST_DIRNAME}/../install.sh"
assert_success ""
assert [ -e bin/bananas ]
run ls -ld bin
assert_equal "r-x" "${output:4:3}"
}

View File

@@ -1,80 +0,0 @@
#!/usr/bin/env bats
load test_helper
setup() {
export PYENV_ROOT="${TMP}/pyenv"
}
stub_pyenv() {
stub pyenv-version-name "echo \${PYENV_VERSION}"
stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'"
stub pyenv-hooks "virtualenv : echo"
stub pyenv-rehash " : echo rehashed"
}
unstub_pyenv() {
unstub pyenv-version-name
unstub pyenv-prefix
unstub pyenv-hooks
unstub pyenv-rehash
}
@test "install pip with ensurepip" {
export PYENV_VERSION="3.4.1"
stub_pyenv "${PYENV_VERSION}"
stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'"
stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'"
stub pyenv-exec "pyvenv ${PYENV_ROOT}/versions/venv : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\";mkdir -p \${PYENV_ROOT}/versions/venv/bin"
stub pyenv-exec "python -m ensurepip : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\";touch \${PYENV_ROOT}/versions/venv/bin/pip3.4"
stub pyenv-exec "python -c * : echo ${PYENV_VERSION%.*}"
remove_executable "3.4.1" "virtualenv"
create_executable "3.4.1" "pyvenv"
run pyenv-virtualenv venv
assert_success
assert_output <<OUT
PYENV_VERSION=3.4.1 pyvenv ${PYENV_ROOT}/versions/venv
PYENV_VERSION=venv python -m ensurepip
rehashed
OUT
assert [ -e "${PYENV_ROOT}/versions/venv/bin/pip" ]
unstub_pyenv
unstub pyenv-exec
}
@test "install pip without using ensurepip" {
export PYENV_VERSION="3.3.5"
stub_pyenv "${PYENV_VERSION}"
stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'"
stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'"
stub pyenv-exec "pyvenv ${PYENV_ROOT}/versions/venv : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\";mkdir -p \${PYENV_ROOT}/versions/venv/bin"
stub pyenv-exec "python -m ensurepip : false"
stub pyenv-exec "python */ez_setup.py : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\";touch \${PYENV_ROOT}/versions/venv/bin/easy_install"
stub pyenv-exec "python */get-pip.py : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\";touch \${PYENV_ROOT}/versions/venv/bin/pip3.3"
stub pyenv-exec "python -c * : echo ${PYENV_VERSION%.*}"
stub curl true
stub curl true
remove_executable "3.3.5" "virtualenv"
create_executable "3.3.5" "pyvenv"
run pyenv-virtualenv venv
assert_success
assert_output <<OUT
PYENV_VERSION=3.3.5 pyvenv ${PYENV_ROOT}/versions/venv
Installing setuptools from https://bootstrap.pypa.io/ez_setup.py...
PYENV_VERSION=venv python ${TMP}/pyenv/cache/ez_setup.py
Installing pip from https://bootstrap.pypa.io/get-pip.py...
PYENV_VERSION=venv python ${TMP}/pyenv/cache/get-pip.py
rehashed
OUT
assert [ -e "${PYENV_ROOT}/versions/venv/bin/pip" ]
unstub_pyenv
unstub pyenv-exec
}

View File

@@ -1,187 +0,0 @@
#!/usr/bin/env bats
load test_helper
setup() {
export PYENV_ROOT="${TMP}/pyenv"
}
stub_pyenv() {
stub pyenv-version-name "echo \${PYENV_VERSION}"
stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'"
stub pyenv-hooks "virtualenv : echo"
stub pyenv-rehash " : echo rehashed"
}
unstub_pyenv() {
unstub pyenv-version-name
unstub pyenv-prefix
unstub pyenv-hooks
unstub pyenv-rehash
}
@test "use pyvenv if virtualenv is not available" {
export PYENV_VERSION="3.4.1"
stub_pyenv "${PYENV_VERSION}"
stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'"
stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'"
stub pyenv-exec "pyvenv ${PYENV_ROOT}/versions/venv : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "python -m ensurepip : true"
stub pyenv-exec "python -c * : echo ${PYENV_VERSION%.*}"
remove_executable "3.4.1" "virtualenv"
create_executable "3.4.1" "pyvenv"
run pyenv-virtualenv venv
assert_success
assert_output <<OUT
PYENV_VERSION=3.4.1 pyvenv ${PYENV_ROOT}/versions/venv
rehashed
OUT
unstub_pyenv
unstub pyenv-exec
}
@test "not use pyvenv if virtualenv is available" {
export PYENV_VERSION="3.4.1"
stub_pyenv "${PYENV_VERSION}"
stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'"
stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'"
stub pyenv-exec "virtualenv ${PYENV_ROOT}/versions/venv : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "python -m ensurepip : true"
stub pyenv-exec "python -c * : echo ${PYENV_VERSION%.*}"
create_executable "3.4.1" "virtualenv"
create_executable "3.4.1" "pyvenv"
run pyenv-virtualenv venv
assert_success
assert_output <<OUT
PYENV_VERSION=3.4.1 virtualenv ${PYENV_ROOT}/versions/venv
rehashed
OUT
unstub_pyenv
unstub pyenv-exec
}
@test "install virtualenv if pyvenv is not avaialble" {
export PYENV_VERSION="3.2.1"
stub_pyenv "${PYENV_VERSION}"
stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'"
stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'"
stub pyenv-exec "pip install virtualenv : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "virtualenv ${PYENV_ROOT}/versions/venv : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "python -m ensurepip : false"
stub pyenv-exec "python */ez_setup.py : true"
stub pyenv-exec "python */get-pip.py : true"
stub pyenv-exec "python -c * : echo ${PYENV_VERSION%.*}"
stub curl true
stub curl true
remove_executable "3.2.1" "virtualenv"
remove_executable "3.2.1" "pyvenv"
run pyenv-virtualenv venv
assert_success
assert_output <<OUT
PYENV_VERSION=3.2.1 pip install virtualenv
PYENV_VERSION=3.2.1 virtualenv ${PYENV_ROOT}/versions/venv
Installing setuptools from https://bootstrap.pypa.io/ez_setup.py...
Installing pip from https://bootstrap.pypa.io/get-pip.py...
rehashed
OUT
unstub_pyenv
unstub pyenv-exec
unstub curl
}
@test "install virtualenv if -p has given" {
export PYENV_VERSION="3.4.1"
stub_pyenv "${PYENV_VERSION}"
stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'"
stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'"
stub pyenv-exec "pip install virtualenv : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "virtualenv --python=python3 ${PYENV_ROOT}/versions/venv : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "python -m ensurepip : true"
stub pyenv-exec "python -c * : echo ${PYENV_VERSION%.*}"
remove_executable "3.4.1" "virtualenv"
create_executable "3.4.1" "pyvenv"
run pyenv-virtualenv -p python3 venv
assert_success
assert_output <<OUT
PYENV_VERSION=3.4.1 pip install virtualenv
PYENV_VERSION=3.4.1 virtualenv --python=python3 ${PYENV_ROOT}/versions/venv
rehashed
OUT
unstub_pyenv
unstub pyenv-exec
}
@test "install virtualenv if --python has given" {
export PYENV_VERSION="3.4.1"
stub_pyenv "${PYENV_VERSION}"
stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'"
stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'"
stub pyenv-exec "pip install virtualenv : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "virtualenv --python=python3 ${PYENV_ROOT}/versions/venv : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "python -m ensurepip : true"
stub pyenv-exec "python -c * : echo ${PYENV_VERSION%.*}"
remove_executable "3.4.1" "virtualenv"
create_executable "3.4.1" "pyvenv"
run pyenv-virtualenv --python=python3 venv
assert_success
assert_output <<OUT
PYENV_VERSION=3.4.1 pip install virtualenv
PYENV_VERSION=3.4.1 virtualenv --python=python3 ${PYENV_ROOT}/versions/venv
rehashed
OUT
unstub_pyenv
unstub pyenv-exec
}
@test "install virtualenv with unsetting troublesome pip options" {
export PYENV_VERSION="3.2.1"
stub_pyenv "${PYENV_VERSION}"
stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'"
stub pyenv-prefix " : echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'"
stub pyenv-exec "pip install virtualenv : echo PIP_REQUIRE_VENV=\${PIP_REQUIRE_VENV} PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "virtualenv ${PYENV_ROOT}/versions/venv : echo PIP_REQUIRE_VENV=\${PIP_REQUIRE_VENV} PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "python -m ensurepip : false"
stub pyenv-exec "python */ez_setup.py : true"
stub pyenv-exec "python */get-pip.py : true"
stub pyenv-exec "python -c * : echo ${PYENV_VERSION%.*}"
stub curl true
stub curl true
remove_executable "3.2.1" "virtualenv"
remove_executable "3.2.1" "pyvenv"
PIP_REQUIRE_VENV="true" run pyenv-virtualenv venv
assert_success
assert_output <<OUT
PIP_REQUIRE_VENV= PYENV_VERSION=3.2.1 pip install virtualenv
PIP_REQUIRE_VENV= PYENV_VERSION=3.2.1 virtualenv ${PYENV_ROOT}/versions/venv
Installing setuptools from https://bootstrap.pypa.io/ez_setup.py...
Installing pip from https://bootstrap.pypa.io/get-pip.py...
rehashed
OUT
unstub_pyenv
unstub pyenv-exec
unstub curl
}

View File

@@ -1,109 +0,0 @@
#!/usr/bin/env bash
set -e
status=0
program="${0##*/}"
PROGRAM="$(echo "$program" | tr a-z- A-Z_)"
[ -n "$TMPDIR" ] || TMPDIR="/tmp"
_STUB_PLAN="${PROGRAM}_STUB_PLAN"
_STUB_RUN="${PROGRAM}_STUB_RUN"
_STUB_INDEX="${PROGRAM}_STUB_INDEX"
_STUB_RESULT="${PROGRAM}_STUB_RESULT"
_STUB_END="${PROGRAM}_STUB_END"
_STUB_DEBUG="${PROGRAM}_STUB_DEBUG"
if [ -n "${!_STUB_DEBUG}" ]; then
echo "$program" "$@" >&${!_STUB_DEBUG}
fi
[ -e "${!_STUB_PLAN}" ] || exit 1
[ -n "${!_STUB_RUN}" ] || eval "${_STUB_RUN}"="${TMPDIR}/${program}-stub-run"
# Initialize or load the stub run information.
eval "${_STUB_INDEX}"=1
eval "${_STUB_RESULT}"=0
[ ! -e "${!_STUB_RUN}" ] || source "${!_STUB_RUN}"
# Loop over each line in the plan.
index=0
while IFS= read -r line; do
index=$(($index + 1))
if [ -z "${!_STUB_END}" ] && [ $index -eq "${!_STUB_INDEX}" ]; then
# We found the plan line we're interested in.
# Start off by assuming success.
result=0
# Split the line into an array of arguments to
# match and a command to run to produce output.
command=" $line"
if [ "$command" != "${command/ : }" ]; then
patterns="${command%% : *}"
command="${command#* : }"
fi
# Naively split patterns by whitespace for now.
# In the future, use a sed script to split while
# respecting quoting.
set -f
patterns=($patterns)
set +f
arguments=("$@")
# Match the expected argument patterns to actual
# arguments.
for (( i=0; i<${#patterns[@]}; i++ )); do
pattern="${patterns[$i]}"
argument="${arguments[$i]}"
case "$argument" in
$pattern ) ;;
* ) result=1 ;;
esac
done
# If the arguments matched, evaluate the command
# in a subshell. Otherwise, log the failure.
if [ $result -eq 0 ] ; then
set +e
( eval "$command" )
status="$?"
set -e
else
eval "${_STUB_RESULT}"=1
fi
fi
done < "${!_STUB_PLAN}"
if [ -n "${!_STUB_END}" ]; then
# Clean up the run file.
rm -f "${!_STUB_RUN}"
# If the number of lines in the plan is larger than
# the requested index, we failed.
if [ $index -ge "${!_STUB_INDEX}" ]; then
eval "${_STUB_RESULT}"=1
fi
# Return the result.
exit "${!_STUB_RESULT}"
else
# If the requested index is larger than the number
# of lines in the plan file, we failed.
if [ "${!_STUB_INDEX}" -gt $index ]; then
eval "${_STUB_RESULT}"=1
fi
# Write out the run information.
{ echo "${_STUB_INDEX}=$((${!_STUB_INDEX} + 1))"
echo "${_STUB_RESULT}=${!_STUB_RESULT}"
} > "${!_STUB_RUN}"
exit "$status"
fi

View File

@@ -1,108 +0,0 @@
export TMP="$BATS_TEST_DIRNAME/tmp"
PATH=/usr/bin:/usr/sbin:/bin/:/sbin
PATH="$BATS_TEST_DIRNAME/../bin:$PATH"
PATH="$TMP/bin:$PATH"
export PATH
teardown() {
rm -fr "$TMP"/*
}
stub() {
local program="$1"
local prefix="$(echo "$program" | tr a-z- A-Z_)"
shift
export "${prefix}_STUB_PLAN"="${TMP}/${program}-stub-plan"
export "${prefix}_STUB_RUN"="${TMP}/${program}-stub-run"
export "${prefix}_STUB_END"=
mkdir -p "${TMP}/bin"
ln -sf "${BATS_TEST_DIRNAME}/stubs/stub" "${TMP}/bin/${program}"
touch "${TMP}/${program}-stub-plan"
for arg in "$@"; do printf "%s\n" "$arg" >> "${TMP}/${program}-stub-plan"; done
}
unstub() {
local program="$1"
local prefix="$(echo "$program" | tr a-z- A-Z_)"
local path="${TMP}/bin/${program}"
export "${prefix}_STUB_END"=1
local STATUS=0
"$path" || STATUS="$?"
rm -f "$path"
rm -f "${TMP}/${program}-stub-plan" "${TMP}/${program}-stub-run"
return "$STATUS"
}
assert() {
if ! "$@"; then
flunk "failed: $@"
fi
}
flunk() {
{ if [ "$#" -eq 0 ]; then cat -
else echo "$@"
fi
} | sed "s:${TMP}:\${TMP}:g" >&2
return 1
}
assert_success() {
if [ "$status" -ne 0 ]; then
{ echo "command failed with exit status $status"
echo "output: $output"
} | flunk
elif [ "$#" -gt 0 ]; then
assert_output "$1"
fi
}
assert_failure() {
if [ "$status" -eq 0 ]; then
flunk "expected failed exit status"
elif [ "$#" -gt 0 ]; then
assert_output "$1"
fi
}
assert_equal() {
if [ "$1" != "$2" ]; then
{ echo "expected: $1"
echo "actual: $2"
} | flunk
fi
}
assert_output() {
local expected
if [ $# -eq 0 ]; then expected="$(cat -)"
else expected="$1"
fi
assert_equal "$expected" "$output"
}
assert_output_contains() {
local expected="$1"
echo "$output" | grep -F "$expected" >/dev/null || {
{ echo "expected output to contain $expected"
echo "actual: $output"
} | flunk
}
}
create_executable() {
mkdir -p "${PYENV_ROOT}/versions/$1/bin"
touch "${PYENV_ROOT}/versions/$1/bin/$2"
chmod +x "${PYENV_ROOT}/versions/$1/bin/$2"
}
remove_executable() {
rm -f "${PYENV_ROOT}/versions/$1/bin/$2"
}

1
test/tmp/.gitignore vendored
View File

@@ -1 +0,0 @@
*

View File

@@ -1,43 +0,0 @@
#!/usr/bin/env bats
load test_helper
setup() {
export PYENV_ROOT="${TMP}/pyenv"
export PYENV_VIRTUALENV_VERSION="20140615"
}
@test "display virtualenv version" {
stub pyenv-prefix "echo '${PYENV_ROOT}/versions/2.7.7'"
stub pyenv-prefix "echo '${PYENV_ROOT}/versions/2.7.7'"
stub pyenv-exec "virtualenv --version : echo \"1.11\""
create_executable "2.7.7" "virtualenv"
remove_executable "2.7.7" "pyvenv"
run pyenv-virtualenv --version
assert_success
assert_output "pyenv-virtualenv ${PYENV_VIRTUALENV_VERSION} (virtualenv 1.11)"
unstub pyenv-prefix
unstub pyenv-exec
}
@test "display pyvenv version" {
stub pyenv-prefix "echo '${PYENV_ROOT}/versions/3.4.1'"
stub pyenv-prefix "echo '${PYENV_ROOT}/versions/3.4.1'"
stub pyenv-which "pyvenv : echo \"${PYENV_ROOT}/versions/3.4.1/bin/pyvenv\""
stub pyenv-root "echo \"${PYENV_ROOT}\""
remove_executable "3.4.1" "virtualenv"
create_executable "3.4.1" "pyvenv"
run pyenv-virtualenv --version
assert_success
assert_output "pyenv-virtualenv ${PYENV_VIRTUALENV_VERSION} (pyvenv 3.4.1)"
unstub pyenv-prefix
unstub pyenv-root
}

View File

@@ -1,145 +0,0 @@
#!/usr/bin/env bats
load test_helper
setup() {
export PYENV_ROOT="${TMP}/pyenv"
}
create_virtualenv() {
mkdir -p "${PYENV_ROOT}/versions/$1/bin"
touch "${PYENV_ROOT}/versions/$1/bin/activate"
}
remove_virtualenv() {
rm -fr "${PYENV_ROOT}/versions/$1"
}
@test "display prefix with using sys.real_prefix" {
stub pyenv-version-name "echo venv27"
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\""
stub pyenv-exec "echo \"${PYENV_ROOT}/versions/2.7.6\""
create_virtualenv "venv27"
PYENV_VERSION="venv27" run pyenv-virtualenv-prefix
unstub pyenv-version-name
unstub pyenv-prefix
unstub pyenv-exec
remove_virtualenv "venv27"
assert_success
assert_output <<OUT
${PYENV_ROOT}/versions/2.7.6
OUT
}
@test "display prefixes with using sys.real_prefix" {
stub pyenv-version-name "echo venv27:venv32"
stub pyenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/venv27\"" \
"venv32 : echo \"${PYENV_ROOT}/versions/venv32\""
stub pyenv-exec "echo \"${PYENV_ROOT}/versions/2.7.6\"" \
"echo \"${PYENV_ROOT}/versions/3.2.1\""
create_virtualenv "venv27"
create_virtualenv "venv32"
PYENV_VERSION="venv27:venv32" run pyenv-virtualenv-prefix
unstub pyenv-version-name
unstub pyenv-prefix
unstub pyenv-exec
remove_virtualenv "venv27"
remove_virtualenv "venv32"
assert_success
assert_output <<OUT
${PYENV_ROOT}/versions/2.7.6:${PYENV_ROOT}/versions/3.2.1
OUT
}
@test "display prefix with using sys.base_prefix" {
stub pyenv-version-name "echo venv33"
stub pyenv-prefix "venv33 : echo \"${PYENV_ROOT}/versions/venv33\""
stub pyenv-exec "false" \
"echo \"${PYENV_ROOT}/versions/3.3.3\""
create_virtualenv "venv33"
PYENV_VERSION="venv33" run pyenv-virtualenv-prefix
unstub pyenv-version-name
unstub pyenv-prefix
unstub pyenv-exec
remove_virtualenv "venv33"
assert_success
assert_output <<OUT
${PYENV_ROOT}/versions/3.3.3
OUT
}
@test "display prefixes with using sys.base_prefix" {
stub pyenv-version-name "echo venv33:venv34"
stub pyenv-prefix "venv33 : echo \"${PYENV_ROOT}/versions/venv33\"" \
"venv34 : echo \"${PYENV_ROOT}/versions/venv34\""
stub pyenv-exec "false" \
"echo \"${PYENV_ROOT}/versions/3.3.3\"" \
"false" \
"echo \"${PYENV_ROOT}/versions/3.4.0\""
create_virtualenv "venv33"
create_virtualenv "venv34"
PYENV_VERSION="venv33:venv34" run pyenv-virtualenv-prefix
unstub pyenv-version-name
unstub pyenv-prefix
unstub pyenv-exec
remove_virtualenv "venv33"
remove_virtualenv "venv34"
assert_success
assert_output <<OUT
${PYENV_ROOT}/versions/3.3.3:${PYENV_ROOT}/versions/3.4.0
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"
PYENV_VERSION="3.4.0" run pyenv-virtualenv-prefix
unstub pyenv-version-name
unstub pyenv-prefix
rmdir "${PYENV_ROOT}/versions/3.4.0"
assert_failure
assert_output <<OUT
pyenv-virtualenv: version \`3.4.0' is not a virtualenv
OUT
}
@test "should fail if one of the versions is not a virtualenv" {
stub pyenv-version-name "echo venv33:3.4.0"
stub pyenv-prefix "venv33 : echo \"${PYENV_ROOT}/versions/venv33\"" \
"3.4.0 : echo \"${PYENV_ROOT}/versions/3.4.0\""
stub pyenv-exec "false" \
"echo \"${PYENV_ROOT}/versions/3.3.3\""
create_virtualenv "venv33"
mkdir -p "${PYENV_ROOT}/versions/3.4.0"
PYENV_VERSION="venv33:3.4.0" run pyenv-virtualenv-prefix
unstub pyenv-version-name
unstub pyenv-prefix
unstub pyenv-exec
remove_virtualenv "venv33"
rmdir "${PYENV_ROOT}/versions/3.4.0"
assert_failure
assert_output <<OUT
pyenv-virtualenv: version \`3.4.0' is not a virtualenv
OUT
}

View File

@@ -1,134 +0,0 @@
#!/usr/bin/env bats
load test_helper
setup() {
export PYENV_ROOT="${TMP}/pyenv"
}
stub_pyenv() {
create_executable "${PYENV_VERSION}" "virtualenv"
remove_executable "${PYENV_VERSION}" "pyvenv"
stub pyenv-prefix "echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'"
stub pyenv-prefix "echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'"
stub pyenv-prefix "echo '${PYENV_ROOT}/versions/${PYENV_VERSION}'"
stub pyenv-hooks "virtualenv : echo"
stub pyenv-rehash " : echo rehashed"
}
unstub_pyenv() {
unstub pyenv-prefix
unstub pyenv-hooks
unstub pyenv-rehash
}
@test "create virtualenv from given version" {
export PYENV_VERSION="3.2.1"
stub_pyenv "${PYENV_VERSION}"
stub pyenv-exec "virtualenv ${PYENV_ROOT}/versions/venv : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "python -m ensurepip : false"
stub pyenv-exec "python */ez_setup.py : true"
stub pyenv-exec "python */get-pip.py : true"
stub pyenv-exec "python -c * : echo ${PYENV_VERSION%.*}"
stub curl true
stub curl true
run pyenv-virtualenv "3.2.1" "venv"
assert_success
assert_output <<OUT
PYENV_VERSION=3.2.1 virtualenv ${PYENV_ROOT}/versions/venv
Installing setuptools from https://bootstrap.pypa.io/ez_setup.py...
Installing pip from https://bootstrap.pypa.io/get-pip.py...
rehashed
OUT
unstub_pyenv
unstub pyenv-exec
unstub curl
}
@test "create virtualenv from current version" {
export PYENV_VERSION="3.2.1"
stub_pyenv "${PYENV_VERSION}"
stub pyenv-version-name "echo \${PYENV_VERSION}"
stub pyenv-exec "virtualenv ${PYENV_ROOT}/versions/venv : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "python -m ensurepip : false"
stub pyenv-exec "python */ez_setup.py : true"
stub pyenv-exec "python */get-pip.py : true"
stub pyenv-exec "python -c * : echo ${PYENV_VERSION%.*}"
stub curl true
stub curl true
run pyenv-virtualenv venv
assert_success
assert_output <<OUT
PYENV_VERSION=3.2.1 virtualenv ${PYENV_ROOT}/versions/venv
Installing setuptools from https://bootstrap.pypa.io/ez_setup.py...
Installing pip from https://bootstrap.pypa.io/get-pip.py...
rehashed
OUT
unstub_pyenv
unstub pyenv-version-name
unstub pyenv-exec
unstub curl
}
@test "create virtualenv with short options" {
export PYENV_VERSION="3.2.1"
stub_pyenv "${PYENV_VERSION}"
stub pyenv-version-name "echo \${PYENV_VERSION}"
stub pyenv-exec "virtualenv --verbose --python=python ${PYENV_ROOT}/versions/venv : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "python -m ensurepip : false"
stub pyenv-exec "python */ez_setup.py : true"
stub pyenv-exec "python */get-pip.py : true"
stub pyenv-exec "python -c * : echo ${PYENV_VERSION%.*}"
stub curl true
stub curl true
run pyenv-virtualenv -v -p python venv
assert_success
assert_output <<OUT
PYENV_VERSION=3.2.1 virtualenv --verbose --python=python ${PYENV_ROOT}/versions/venv
Installing setuptools from https://bootstrap.pypa.io/ez_setup.py...
Installing pip from https://bootstrap.pypa.io/get-pip.py...
rehashed
OUT
unstub_pyenv
unstub pyenv-version-name
unstub pyenv-exec
unstub curl
}
@test "create virtualenv with long options" {
export PYENV_VERSION="3.2.1"
stub_pyenv "${PYENV_VERSION}"
stub pyenv-version-name "echo \${PYENV_VERSION}"
stub pyenv-exec "virtualenv --verbose --python=python ${PYENV_ROOT}/versions/venv : echo PYENV_VERSION=\${PYENV_VERSION} \"\$@\""
stub pyenv-exec "python -m ensurepip : false"
stub pyenv-exec "python */ez_setup.py : true"
stub pyenv-exec "python */get-pip.py : true"
stub pyenv-exec "python -c * : echo ${PYENV_VERSION%.*}"
stub curl true
stub curl true
run pyenv-virtualenv --verbose --python=python venv
assert_success
assert_output <<OUT
PYENV_VERSION=3.2.1 virtualenv --verbose --python=python ${PYENV_ROOT}/versions/venv
Installing setuptools from https://bootstrap.pypa.io/ez_setup.py...
Installing pip from https://bootstrap.pypa.io/get-pip.py...
rehashed
OUT
unstub_pyenv
unstub pyenv-version-name
unstub pyenv-exec
unstub curl
}

View File

@@ -1,68 +0,0 @@
#!/usr/bin/env bats
load test_helper
setup() {
export PYENV_ROOT="${TMP}/pyenv"
mkdir -p "${PYENV_ROOT}/versions/2.7.6"
mkdir -p "${PYENV_ROOT}/versions/3.3.3"
mkdir -p "${PYENV_ROOT}/versions/venv27"
mkdir -p "${PYENV_ROOT}/versions/venv33"
}
@test "list virtual environments only" {
stub pyenv-version-name ": echo system"
stub pyenv-versions "--bare : echo \"system\";echo \"2.7.6\";echo \"3.3.3\";echo \"venv27\";echo \"venv33\""
stub pyenv-virtualenv-prefix "2.7.6 : false"
stub pyenv-virtualenv-prefix "3.3.3 : false"
stub pyenv-virtualenv-prefix "venv27 : echo \"${PYENV_ROOT}/versions/2.7.6\""
stub pyenv-virtualenv-prefix "venv33 : echo \"${PYENV_ROOT}/versions/3.3.3\""
run pyenv-virtualenvs
unstub pyenv-version-name
unstub pyenv-versions
unstub pyenv-virtualenv-prefix
assert_success
assert_output <<OUT
venv27 (created from ${PYENV_ROOT}/versions/2.7.6)
venv33 (created from ${PYENV_ROOT}/versions/3.3.3)
OUT
}
@test "list virtual environments with hit prefix" {
stub pyenv-version-name ": echo venv33"
stub pyenv-versions "--bare : echo \"system\";echo \"venv27\";echo \"venv33\""
stub pyenv-virtualenv-prefix "venv27 : echo \"/usr\""
stub pyenv-virtualenv-prefix "venv33 : echo \"/usr\""
run pyenv-virtualenvs
unstub pyenv-version-name
unstub pyenv-versions
unstub pyenv-virtualenv-prefix
assert_success
assert_output <<OUT
venv27 (created from /usr)
* venv33 (created from /usr)
OUT
}
@test "list virtual environments with --bare" {
stub pyenv-versions "--bare : echo \"system\";echo \"venv27\";echo \"venv33\""
stub pyenv-virtualenv-prefix "venv27 : echo \"/usr\""
stub pyenv-virtualenv-prefix "venv33 : echo \"/usr\""
run pyenv-virtualenvs --bare
unstub pyenv-versions
unstub pyenv-virtualenv-prefix
assert_success
assert_output <<OUT
venv27
venv33
OUT
}