mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-08 11:33:55 -05:00
Compare commits
34 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fa9950aa5b | ||
|
|
124645e84c | ||
|
|
ec60d5dfcb | ||
|
|
d96a00ece3 | ||
|
|
20e31ed587 | ||
|
|
32bfce2e41 | ||
|
|
99de2882e3 | ||
|
|
39bac37090 | ||
|
|
a4ce544798 | ||
|
|
16a4a8d37e | ||
|
|
8d4b901250 | ||
|
|
8363a4f0e0 | ||
|
|
79c4e62886 | ||
|
|
eee0e2bea8 | ||
|
|
2f20c56b1d | ||
|
|
77f9c1502d | ||
|
|
327b8b7615 | ||
|
|
8eecec0d7d | ||
|
|
23a115c12a | ||
|
|
f3c5a64281 | ||
|
|
384fab86ef | ||
|
|
f0ca1b27d0 | ||
|
|
2e5db090a9 | ||
|
|
11792cbaf9 | ||
|
|
6e7945a626 | ||
|
|
1db9840620 | ||
|
|
212021c322 | ||
|
|
7507cb1e41 | ||
|
|
7a54a83392 | ||
|
|
551956f017 | ||
|
|
1ad6788e84 | ||
|
|
f78a393864 | ||
|
|
a4de1d7e89 | ||
|
|
f2bd87fc3e |
90
README.md
90
README.md
@@ -18,22 +18,65 @@ Installing pyenv-virtualenv as a pyenv plugin will give you access to the
|
||||
$ git clone git://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
|
||||
|
||||
This will install the latest development version of pyenv-virtualenv into
|
||||
the `~/.pyenv/plugins/pyenv-virtualenv` directory. From that directory, you
|
||||
can check out a specific release tag. To update pyenv-virtualenv, run `git
|
||||
pull` to download the latest changes.
|
||||
the `~/.pyenv/plugins/pyenv-virtualenv` directory.
|
||||
**Important note:** If you installed pyenv into a non-standard directory, make sure that you clone this
|
||||
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.
|
||||
|
||||
### Installing with Homebrew (for OS X users)
|
||||
|
||||
Mac OS X users can install pyenv-virtualenv with the
|
||||
[Homebrew](http://brew.sh) package manager. This
|
||||
will give you access to the `pyenv-virtualenv` command. If you have pyenv
|
||||
installed, you will also be able to use the `pyenv virtualenv` command.
|
||||
|
||||
*This is recommended method of installation if you installed pyenv
|
||||
with Homebrew.*
|
||||
|
||||
brew install pyenv-virtualenv
|
||||
|
||||
Or, if you would like to install the latest development release:
|
||||
|
||||
brew install --HEAD pyenv-virtualenv
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
### Using `pyenv virtualenv` with pyenv
|
||||
|
||||
To create a virtualenv for the Python version use with pyenv, run
|
||||
`pyenv virtualenv` with tha exact name of the version you want to create
|
||||
virtualenv. For example,
|
||||
`pyenv virtualenv`, specifying the Python version you want and the name
|
||||
of the virtualenv directory. For example,
|
||||
|
||||
$ pyenv virtualenv 2.7.3 venv27
|
||||
$ pyenv virtualenv 2.7.6 my-virtual-env-2.7.6
|
||||
|
||||
will create a virtualenv based on Python 2.7.6
|
||||
under `~/.pyenv/versions` in a folder called `my-virtual-env-2.7.6`.
|
||||
|
||||
|
||||
### Create virtualenv from current version
|
||||
|
||||
If there is only one argument is given to `pyenv virtualenv`,
|
||||
virtualenv will be created with given name based on current
|
||||
version.
|
||||
|
||||
$ pyenv version
|
||||
3.3.3 (set by /home/yyuu/.pyenv/version)
|
||||
$ pyenv virtualenv venv33
|
||||
|
||||
|
||||
### List existing virtualenvs
|
||||
|
||||
`pyenv virtualenvs` shows you the list of existing virtualenvs.
|
||||
|
||||
$ pyenv shell venv27
|
||||
$ pyenv virtualenvs
|
||||
* venv27 (created from /home/yyuu/.pyenv/versions/2.7.6)
|
||||
venv33 (created from /home/yyuu/.pyenv/versions/3.3.3)
|
||||
|
||||
virtualenvs will be created into a directory of the same name
|
||||
under `~/.pyenv/versions`.
|
||||
|
||||
### Special environment variables
|
||||
|
||||
@@ -41,19 +84,38 @@ You can set certain environment variables to control the pyenv-virtualenv.
|
||||
|
||||
* `PYENV_VIRTUALENV_CACHE_PATH`, if set, specifies a directory to use for
|
||||
caching downloaded package files.
|
||||
* `PYENV_VIRTUALENV_SCRIPT_PATH`, if set, specified a directory to use for
|
||||
storing virtualenv scripts.
|
||||
* `VIRTUALENV_VERSION`, if set, forces pyenv-virtualenv to use desired
|
||||
version of virtualenv. If the version has not been installed,
|
||||
pyenv-virtualenv will try to download it.
|
||||
* `VIRTUALENV_VERSION`, if set, forces pyenv-virtualenv to install desired
|
||||
version of virtualenv. If the virtualenv has not been installed,
|
||||
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
|
||||
than virtualenv, download `ez_setup.py` and `get_pip.py` from specified URL.
|
||||
* `SETUPTOOLS_VERSION` and `PIP_VERSION`, if set and pyvenv is preferred
|
||||
than virtualenv, install specified version of setuptools and pip.
|
||||
|
||||
|
||||
## Version History
|
||||
|
||||
#### 20140110
|
||||
|
||||
* Support environment variables of `EZ_SETUP` and `GET_PIP`.
|
||||
* Support a short option `-p` of `virtualenv`.
|
||||
|
||||
#### 20131216
|
||||
|
||||
* Use latest release of setuptools and pip if the version not given via environment variables.
|
||||
|
||||
#### 20130622
|
||||
|
||||
* Removed bundled `virtualenv.py` script. Now pyenv-virtualenv installs `virtualenv` package into source version and then use it.
|
||||
* On Python 3.3+, use `pyvenv` as virtualenv command if `virtualenv` is not available.
|
||||
* Install setuptools and pip into environments created by `pyvenv`.
|
||||
|
||||
#### 20130614
|
||||
|
||||
* Add `pyenv virtualenvs` to list all virtualenv versions.
|
||||
* *EXPERIMENTAL* Add `--upgrade` option to re-create virtualenv with migrating packages
|
||||
* *EXPERIMENTAL*: Add `--upgrade` option to re-create virtualenv with migrating packages
|
||||
|
||||
#### 20130527
|
||||
|
||||
|
||||
@@ -6,12 +6,12 @@
|
||||
# pyenv virtualenv --version
|
||||
# pyenv virtualenv --help
|
||||
#
|
||||
# -u/--upgrade Upgrade existing virtualenv with migrating installed packages
|
||||
# -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
|
||||
#
|
||||
|
||||
PYENV_VIRTUALENV_VERSION="20130614"
|
||||
VIRTUALENV_VERSION="${VIRTUALENV_VERSION:-1.9.1}"
|
||||
PYENV_VIRTUALENV_VERSION="20140110"
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
@@ -100,47 +100,82 @@ http_get_wget() {
|
||||
}
|
||||
|
||||
version() {
|
||||
local version="$(pyenv-exec python "${VIRTUALENV}" --version 2>/dev/null || true)"
|
||||
local version="$(venv --version 2>/dev/null || true)"
|
||||
echo "pyenv-virtualenv ${PYENV_VIRTUALENV_VERSION} (virtualenv ${version:-unknown})"
|
||||
}
|
||||
|
||||
usage() {
|
||||
# We can remove the sed fallback once pyenv 0.2.0 is widely available.
|
||||
pyenv-help virtualenv 2>/dev/null || sed -ne '/^#/!q;s/.//;s/.//;1,4d;p' < "$0"
|
||||
pyenv-exec python "${VIRTUALENV}" --help 2>/dev/null || true
|
||||
venv --help 2>/dev/null || true
|
||||
[ -z "$1" ] || exit "$1"
|
||||
}
|
||||
|
||||
ensure_virtualenv() {
|
||||
local file="$1"
|
||||
local url="$2"
|
||||
[ -f "${file}" ] || {
|
||||
mkdir -p "$(dirname "${file}")"
|
||||
http get "${url}" "${file}"
|
||||
}
|
||||
virtualenv_is_pyvenv() {
|
||||
# Use pyvenv only if virtualenv is not installed and there is pyvenv
|
||||
if pyenv-which "virtualenv" 1>/dev/null 2>&1; then
|
||||
return 1
|
||||
else
|
||||
pyenv-which "pyvenv" 1>/dev/null 2>&1
|
||||
fi
|
||||
}
|
||||
|
||||
venv() {
|
||||
if virtualenv_is_pyvenv; then
|
||||
pyenv-exec pyvenv "$@"
|
||||
else
|
||||
pyenv-exec virtualenv "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
install_setuptools() {
|
||||
local version="$1"
|
||||
{ if [ "${EZ_SETUP+defined}" ] && [ -f "${EZ_SETUP}" ]; then
|
||||
echo "Installing setuptools from ${EZ_SETUP}..." 1>&2
|
||||
cat "${EZ_SETUP}"
|
||||
else
|
||||
[ -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
|
||||
}
|
||||
echo "Installing setuptools from ${EZ_SETUP_URL}..." 1>&2
|
||||
http get "${EZ_SETUP_URL}"
|
||||
fi
|
||||
} | PYENV_VERSION="${version}" pyenv-exec python
|
||||
}
|
||||
|
||||
install_pip() {
|
||||
local version="$1"
|
||||
{ if [ "${GET_PIP+defined}" ] && [ -f "${GET_PIP}" ]; then
|
||||
echo "Installing pip from ${GET_PIP}..." 1>&2
|
||||
cat "${GET_PIP}"
|
||||
else
|
||||
[ -n "${GET_PIP_URL}" ] || {
|
||||
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
|
||||
}
|
||||
echo "Installing pip from ${GET_PIP_URL}..." 1>&2
|
||||
http get "${GET_PIP_URL}"
|
||||
fi
|
||||
} | PYENV_VERSION="${version}" pyenv-exec python
|
||||
}
|
||||
|
||||
PYENV_VIRTUALENV_ROOT="$(abs_dirname "$0")/.."
|
||||
if [ -z "${PYENV_VIRTUALENV_CACHE_PATH}" ]; then
|
||||
PYENV_VIRTUALENV_CACHE_PATH="${PYTHON_BUILD_CACHE_PATH:-${PYENV_ROOT}/cache}"
|
||||
fi
|
||||
if [ -z "${PYENV_VIRTUALENV_SCRIPT_PATH}" ]; then
|
||||
PYENV_VIRTUALENV_SCRIPT_PATH="${PYENV_VIRTUALENV_ROOT}/libexec/pyenv-virtualenv"
|
||||
fi
|
||||
VIRTUALENV="${PYENV_VIRTUALENV_SCRIPT_PATH}/${VIRTUALENV_VERSION}/virtualenv.py"
|
||||
VIRTUALENV_URL="https://raw.github.com/pypa/virtualenv/${VIRTUALENV_VERSION}/virtualenv.py"
|
||||
VIRTUALENV_OPTIONS=()
|
||||
|
||||
ensure_virtualenv "${VIRTUALENV}" "${VIRTUALENV_URL}" || {
|
||||
echo "pyenv-virtualenv: could not find virtualenv script: ${VIRTUALENV}" 1>&2
|
||||
exit 1
|
||||
}
|
||||
|
||||
unset FORCE
|
||||
unset QUIET
|
||||
unset UPGRADE
|
||||
# Unset environment variables which starts with `VIRTUALENV_`.
|
||||
# These variables are reserved for virtualenv.
|
||||
unset VIRTUALENV_VERSION
|
||||
unset VERBOSE
|
||||
|
||||
parse_options "$@"
|
||||
for option in "${OPTIONS[@]}"; do
|
||||
@@ -151,22 +186,51 @@ for option in "${OPTIONS[@]}"; do
|
||||
"h" | "help" )
|
||||
usage 0
|
||||
;;
|
||||
"p" )
|
||||
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--python=${ARGUMENTS[0]}"
|
||||
ARGUMENTS=("${ARGUMENTS[@]:1}") # shift 1
|
||||
;;
|
||||
"q" | "quiet" )
|
||||
QUIET="--quiet"
|
||||
;;
|
||||
"u" | "upgrade" )
|
||||
UPGRADE=true
|
||||
;;
|
||||
"v" | "verbose" )
|
||||
VERBOSE="--verbose"
|
||||
;;
|
||||
"version" )
|
||||
version
|
||||
exit 0
|
||||
;;
|
||||
* )
|
||||
* ) # virtualenv long options
|
||||
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--$option"
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
# The first argument contains the source version to create virtualenv.
|
||||
VERSION_NAME="${ARGUMENTS[0]}"
|
||||
[ -n "$VERSION_NAME" ] || usage 1
|
||||
if [[ "${#ARGUMENTS[@]}" == 0 ]]; then
|
||||
echo "pyenv: no virtualenv name given." 1>&2
|
||||
exit 1
|
||||
elif [[ "${#ARGUMENTS[@]}" == 1 ]]; then
|
||||
# If only one argument given, use current version as source version
|
||||
VERSION_NAME="$(pyenv-version-name)"
|
||||
VIRTUALENV_NAME="${ARGUMENTS[0]}"
|
||||
else
|
||||
# Otherwise, use former as source version, and latter as virtualenv version
|
||||
VERSION_NAME="${ARGUMENTS[0]}"
|
||||
VIRTUALENV_NAME="${ARGUMENTS[1]##*/}"
|
||||
fi
|
||||
|
||||
if [ -z "${VERSION_NAME}" ] || [ -z "${VIRTUALENV_NAME}" ]; then
|
||||
usage 1
|
||||
fi
|
||||
|
||||
# Set VERSION_NAME as default version in this script
|
||||
export PYENV_VERSION="${VERSION_NAME}"
|
||||
|
||||
# Source version must exists before creating virtualenv
|
||||
pyenv-prefix 1>/dev/null 2>&1 || usage 1
|
||||
|
||||
if [ -z "$TMPDIR" ]; then
|
||||
TMP="/tmp"
|
||||
@@ -178,35 +242,27 @@ SEED="$(date "+%Y%m%d%H%M%S").$$"
|
||||
UPGRADE_PATH="${TMP}/pyenv-virtualenv.${SEED}"
|
||||
UPGRADE_LIST="${TMP}/pyenv-virtualenv.${SEED}.txt"
|
||||
|
||||
|
||||
|
||||
PYTHON_BIN="$(PYENV_VERSION="${VERSION_NAME}" pyenv-which python)"
|
||||
if [ ! -x "${PYTHON_BIN}" ]; then
|
||||
echo "pyenv-virtualenv: could not find python executable: ${PYTHON_BIN}" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# find canonical name of python executable.
|
||||
# virtualenv will create "bin/python" executable as same name as its bootstraped python.
|
||||
if [ -L "${PYTHON_BIN}" ]; then
|
||||
while [ -L "${PYTHON_BIN}" ]; do # retrieve symlinks
|
||||
PYTHON_BIN="$(dirname "${PYTHON_BIN}")/$(resolve_link "${PYTHON_BIN}")"
|
||||
done
|
||||
else
|
||||
# python 2.6 and older don't have "bin/python" as symlink.
|
||||
# so we must traverse files like "bin/python*" to obtain canonical name.
|
||||
for python in ${PYENV_ROOT}/versions/${VERSION_NAME}/bin/python*; do
|
||||
if ( basename "$python" | grep '^python[0-9][0-9]*\.[0-9][0-9]*$' && cmp "$PYTHON_BIN" "$python" ) >/dev/null; then
|
||||
PYTHON_BIN="${python}"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
VIRTUALENV_NAME="${ARGUMENTS[1]##*/}"
|
||||
VIRTUALENV_PATH="${PYENV_ROOT}/versions/${VIRTUALENV_NAME}"
|
||||
VIRTUALENV_PYTHON_BIN="${VIRTUALENV_PATH}/bin/python"
|
||||
VIRTUALENV_PIP_BIN="${VIRTUALENV_PATH}/bin/pip"
|
||||
|
||||
if virtualenv_is_pyvenv; then
|
||||
# Unset some arguments not supported by pyvenv
|
||||
unset QUIET
|
||||
unset VERBOSE
|
||||
if [ -n "$UPGRADE" ]; then
|
||||
unset UPGRADE
|
||||
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--upgrade"
|
||||
fi
|
||||
else
|
||||
pyenv-which "virtualenv" 1>/dev/null 2>&1 || {
|
||||
VIRTUALENV_VERSION="==${VIRTUALENV_VERSION}"
|
||||
pyenv-exec pip install $QUIET $VERBOSE "virtualenv${VIRTUALENV_VERSION%==}"
|
||||
pyenv-rehash
|
||||
}
|
||||
fi
|
||||
|
||||
# Unset environment variables which starts with `VIRTUALENV_`.
|
||||
# These variables are reserved for virtualenv.
|
||||
unset VIRTUALENV_VERSION
|
||||
|
||||
|
||||
# Define `before_virtualenv` and `after_virtualenv` functions that allow
|
||||
@@ -246,13 +302,8 @@ if [ -d "${VIRTUALENV_PATH}/bin" ]; then
|
||||
fi
|
||||
|
||||
if [ -n "$UPGRADE" ]; then
|
||||
if [ -x "${VIRTUALENV_PIP_BIN}" ]; then
|
||||
"${VIRTUALENV_PIP_BIN}" freeze > "${UPGRADE_LIST}"
|
||||
mv -f "${VIRTUALENV_PATH}" "${UPGRADE_PATH}"
|
||||
else
|
||||
echo "pyenv: pip is not installed in ${VIRTUALENV_PATH}" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
PYENV_VERSION="${VIRTUALENV_NAME}" pyenv-exec pip freeze >"${UPGRADE_LIST}"
|
||||
mv -f "${VIRTUALENV_PATH}" "${UPGRADE_PATH}"
|
||||
fi
|
||||
fi
|
||||
|
||||
@@ -272,24 +323,22 @@ STATUS=0
|
||||
# change to cache directory to reuse them between invocation.
|
||||
mkdir -p "${PYENV_VIRTUALENV_CACHE_PATH}"
|
||||
cd "${PYENV_VIRTUALENV_CACHE_PATH}"
|
||||
"${PYTHON_BIN}" "${VIRTUALENV}" "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}" || STATUS=$?
|
||||
venv $QUIET $VERBOSE "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}" && {
|
||||
if virtualenv_is_pyvenv; then
|
||||
PYENV_VERSION="${VIRTUALENV_NAME}" pyenv-exec python -c 'import setuptools' 1>/dev/null 2>&1 || {
|
||||
install_setuptools "${VIRTUALENV_NAME}" 1>&2
|
||||
}
|
||||
|
||||
# create symlink of `python' bound for actual executable
|
||||
if [ ! -f "$VIRTUALENV_PYTHON_BIN" ]; then
|
||||
if [ -f "${VIRTUALENV_PATH}/bin/$(basename "${PYTHON_BIN}")" ]; then
|
||||
( cd "${VIRTUALENV_PATH}/bin" && ln -fs "$(basename "${PYTHON_BIN}")" python )
|
||||
PYENV_VERSION="${VIRTUALENV_NAME}" pyenv-which pip 1>/dev/null 2>&1 || {
|
||||
install_pip "${VIRTUALENV_NAME}" 1>&2
|
||||
}
|
||||
fi
|
||||
fi
|
||||
} || STATUS="$?"
|
||||
|
||||
## Migrate previously installed packages from requirements.txt
|
||||
if [ -n "$UPGRADE" ]; then
|
||||
UPGRADE_STATUS=0
|
||||
if [ -x "${VIRTUALENV_PIP_BIN}" ]; then
|
||||
"${VIRTUALENV_PIP_BIN}" install --requirement "${UPGRADE_LIST}" || UPGRADE_STATUS=$?
|
||||
else
|
||||
echo "pyenv: pip is not installed in ${VIRTUALENV_PATH}" 1>&2
|
||||
UPGRADE_STATUS=1
|
||||
fi
|
||||
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}"
|
||||
|
||||
@@ -12,8 +12,36 @@ if [ -z "$PYENV_ROOT" ]; then
|
||||
fi
|
||||
|
||||
if [ -n "$1" ]; then
|
||||
export PYENV_VERSION="$1"
|
||||
versions=($@)
|
||||
IFS=: PYENV_VERSION="${versions[*]}"
|
||||
export PYENV_VERSION
|
||||
else
|
||||
IFS=: versions=($(pyenv-version-name))
|
||||
fi
|
||||
|
||||
PYTHON_BIN="$(pyenv-which python)"
|
||||
"${PYTHON_BIN}" -c 'import sys;print(sys.real_prefix)' 2>/dev/null
|
||||
real_prefix() { # virtualenv
|
||||
local version="$1"
|
||||
PYENV_VERSION="${version}" pyenv-exec python -c 'import sys;print(sys.real_prefix)' 2>/dev/null
|
||||
}
|
||||
|
||||
base_prefix() { # pyvenv
|
||||
# FIXME: non-pyvenv versions also have sys.base_prefix
|
||||
local version="$1"
|
||||
PYENV_VERSION="${version}" pyenv-exec python -c 'import sys;print(sys.base_prefix)' 2>/dev/null
|
||||
}
|
||||
|
||||
VIRTUALENV_PREFIX_PATHS=()
|
||||
for version in "${versions[@]}"; do
|
||||
PREFIX="$(pyenv-prefix "${version}")"
|
||||
if [ -f "${PREFIX}/bin/activate" ]; then
|
||||
VIRTUALENV_PREFIX_PATH="$(real_prefix "${version}" || base_prefix "${version}" || true)"
|
||||
if [ -d "${VIRTUALENV_PREFIX_PATH}" ]; then
|
||||
VIRTUALENV_PREFIX_PATHS=("${VIRTUALENV_PREFIX_PATHS[@]}" "$VIRTUALENV_PREFIX_PATH")
|
||||
fi
|
||||
else
|
||||
echo "pyenv: version \`${version}' is not a virtualenv" 1>&2
|
||||
exit 1
|
||||
fi
|
||||
done
|
||||
|
||||
IFS=: echo "${VIRTUALENV_PREFIX_PATHS[*]}"
|
||||
|
||||
@@ -12,31 +12,45 @@ if [ -z "$PYENV_ROOT" ]; then
|
||||
PYENV_ROOT="${HOME}/.pyenv"
|
||||
fi
|
||||
|
||||
unset BARE
|
||||
|
||||
if [ "$1" = "--bare" ]; then
|
||||
BARE=true
|
||||
hit_prefix=""
|
||||
miss_prefix=""
|
||||
current_versions=()
|
||||
print_origin=""
|
||||
else
|
||||
hit_prefix="* "
|
||||
miss_prefix=" "
|
||||
current_versions=($(IFS=:; for version in $(pyenv-version-name); do echo "$version"; done))
|
||||
print_origin="1"
|
||||
fi
|
||||
|
||||
array_exists() {
|
||||
local x car="$1"
|
||||
shift
|
||||
for x in "$@"; do
|
||||
[ "${x}" = "${car}" ] && return 0
|
||||
done
|
||||
return 1
|
||||
}
|
||||
|
||||
print_version() {
|
||||
local version="$1"
|
||||
if [ -n "${BARE}" ]; then
|
||||
echo "${version}"
|
||||
if [ -n "${print_origin}" ]; then
|
||||
local version_origin="$2"
|
||||
else
|
||||
echo "${version} (created from $(pyenv-virtualenv-prefix "${version}"))"
|
||||
local version_origin=""
|
||||
fi
|
||||
if array_exists "$1" "${current_versions[@]}"; then
|
||||
echo "${hit_prefix}${1}${version_origin}"
|
||||
else
|
||||
echo "${miss_prefix}${1}${version_origin}"
|
||||
fi
|
||||
}
|
||||
|
||||
virtualenv_version() {
|
||||
local version="$1"
|
||||
local prefix="$(pyenv-prefix "${version}")"
|
||||
[ -f "${prefix}/bin/activate" ] && "${prefix}/bin/python" -c 'import sys;sys.real_prefix' 1>/dev/null 2>&1
|
||||
}
|
||||
|
||||
versions=($(pyenv-versions --bare))
|
||||
|
||||
for version in "${versions[@]}"; do
|
||||
if virtualenv_version "${version}"; then
|
||||
print_version "${version}"
|
||||
for version in $(pyenv-versions --bare); do
|
||||
if [[ "${version}" != "system" ]]; then
|
||||
virtualenv_prefix="$(pyenv-virtualenv-prefix "${version}" 2>/dev/null || true)"
|
||||
if [ -d "${virtualenv_prefix}" ]; then
|
||||
print_version "${version}" " (created from ${virtualenv_prefix})"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
@@ -7,17 +7,11 @@ if [ -z "${PREFIX}" ]; then
|
||||
fi
|
||||
|
||||
BIN_PATH="${PREFIX}/bin"
|
||||
LIBEXEC_PATH="${PREFIX}/libexec/pyenv-virtualenv"
|
||||
|
||||
mkdir -p "${BIN_PATH}"
|
||||
mkdir -p "${LIBEXEC_PATH}"
|
||||
|
||||
for file in bin/*; do
|
||||
cp "${file}" "${BIN_PATH}"
|
||||
done
|
||||
|
||||
for file in libexec/pyenv-virtualenv/*; do
|
||||
cp -Rp "${file}" "${LIBEXEC_PATH}"
|
||||
done
|
||||
|
||||
echo "Installed pyenv-virtualenv at ${PREFIX}"
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user