mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-09 12:03:55 -05:00
Compare commits
51 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2a5a483c5d | ||
|
|
a2c878f284 | ||
|
|
b7c498ce03 | ||
|
|
6915cd0320 | ||
|
|
4263783195 | ||
|
|
65b58770a7 | ||
|
|
66546cea12 | ||
|
|
7562795c42 | ||
|
|
72592fde6b | ||
|
|
8ac27a7a77 | ||
|
|
f9532f6c4e | ||
|
|
67d6cfc0d2 | ||
|
|
695c2fd618 | ||
|
|
bc433be75c | ||
|
|
16470ec39c | ||
|
|
c8b9969619 | ||
|
|
3b7be75458 | ||
|
|
404918c7d9 | ||
|
|
20e78d8ffa | ||
|
|
db37bb9643 | ||
|
|
a9903fab6e | ||
|
|
b594b99a18 | ||
|
|
9e438ee3e2 | ||
|
|
1389d840d1 | ||
|
|
78af7ec9d4 | ||
|
|
5b357d2862 | ||
|
|
5baa5084dc | ||
|
|
0f8477fcf5 | ||
|
|
aec759a0e0 | ||
|
|
15608701ae | ||
|
|
d927b2e137 | ||
|
|
ebeb3dcb71 | ||
|
|
8b1ae9f19a | ||
|
|
003ea01b97 | ||
|
|
1a2d06bc05 | ||
|
|
5ed1988b34 | ||
|
|
c65e8b266b | ||
|
|
6ee4bf1e5c | ||
|
|
2910f87cb6 | ||
|
|
9651cfe63d | ||
|
|
317fcdbfe7 | ||
|
|
fce66ebba7 | ||
|
|
2551913d75 | ||
|
|
2e418ee563 | ||
|
|
7121fe04b0 | ||
|
|
908334a8e5 | ||
|
|
50403a674e | ||
|
|
83a85e0193 | ||
|
|
67fc864252 | ||
|
|
bd38d39ea4 | ||
|
|
ed5f3eef77 |
6
.gitignore
vendored
6
.gitignore
vendored
@@ -1,4 +1,6 @@
|
|||||||
*.pyc
|
/libexec/pyenv-virtualenv/*/*.class
|
||||||
*.pyo
|
/libexec/pyenv-virtualenv/*/*.pyc
|
||||||
|
/libexec/pyenv-virtualenv/*/*.pyo
|
||||||
|
/libexec/pyenv-virtualenv/*/__pycache__
|
||||||
*.swo
|
*.swo
|
||||||
*.swp
|
*.swp
|
||||||
|
|||||||
3
LICENSE
3
LICENSE
@@ -1,5 +1,4 @@
|
|||||||
Copyright (c) 2012 Yamashita, Yuu
|
Copyright (c) 2013 Yamashita, Yuu
|
||||||
Copyright (c) 2011 Sam Stephenson
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
|
|||||||
73
README.md
73
README.md
@@ -1,27 +1,27 @@
|
|||||||
# python-virtualenv
|
# pyenv-virtualenv (a.k.a. [python-virtualenv](https://github.com/yyuu/python-virtualenv))
|
||||||
|
|
||||||
python-virtualenv is an [pyenv](https://github.com/yyuu/pyenv) plugin
|
pyenv-virtualenv is a [pyenv](https://github.com/yyuu/pyenv) plugin
|
||||||
that provides an `pyenv virtualenv` command to create virtualenv for Python
|
that provides a `pyenv virtualenv` command to create virtualenv for Python
|
||||||
on UNIX-like systems.
|
on UNIX-like systems.
|
||||||
|
|
||||||
|
(NOTICE: If you are an existing user of [virtualenvwrapper](http://pypi.python.org/pypi/virtualenvwrapper)
|
||||||
|
and you love it, [pyenv-virtualenvwrapper](https://github.com/yyuu/pyenv-virtualenvwrapper) may help you
|
||||||
|
to manage your virtualenvs.)
|
||||||
|
|
||||||
## Installation
|
## Installation
|
||||||
|
|
||||||
### Installing as an pyenv plugin (recommended)
|
### Installing as a pyenv plugin
|
||||||
|
|
||||||
Installing python-virtualenv as an pyenv plugin will give you access to the
|
Installing pyenv-virtualenv as a pyenv plugin will give you access to the
|
||||||
`pyenv virtualenv` command.
|
`pyenv virtualenv` command.
|
||||||
|
|
||||||
$ mkdir -p ~/.pyenv/plugins
|
$ git clone git://github.com/yyuu/pyenv-virtualenv.git ~/.pyenv/plugins/pyenv-virtualenv
|
||||||
$ cd ~/.pyenv/plugins
|
|
||||||
$ git clone git://github.com/yyuu/python-virtualenv.git
|
|
||||||
|
|
||||||
This will install the latest development version of python-virtualenv into
|
This will install the latest development version of pyenv-virtualenv into
|
||||||
the `~/.pyenv/plugins/python-virtualenv` directory. From that directory, you
|
the `~/.pyenv/plugins/pyenv-virtualenv` directory. From that directory, you
|
||||||
can check out a specific release tag. To update python-virtualenv, run `git
|
can check out a specific release tag. To update pyenv-virtualenv, run `git
|
||||||
pull` to download the latest changes.
|
pull` to download the latest changes.
|
||||||
|
|
||||||
|
|
||||||
## Usage
|
## Usage
|
||||||
|
|
||||||
### Using `pyenv virtualenv` with pyenv
|
### Using `pyenv virtualenv` with pyenv
|
||||||
@@ -35,9 +35,55 @@ virtualenv. For example,
|
|||||||
virtualenvs will be created into a directory of the same name
|
virtualenvs will be created into a directory of the same name
|
||||||
under `~/.pyenv/versions`.
|
under `~/.pyenv/versions`.
|
||||||
|
|
||||||
|
### Special environment variables
|
||||||
|
|
||||||
|
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.
|
||||||
|
|
||||||
|
|
||||||
## Version History
|
## Version History
|
||||||
|
|
||||||
|
#### 20130614
|
||||||
|
|
||||||
|
* Add `pyenv virtualenvs` to list all virtualenv versions.
|
||||||
|
* *EXPERIMENTAL* Add `--upgrade` option to re-create virtualenv with migrating packages
|
||||||
|
|
||||||
|
#### 20130527
|
||||||
|
|
||||||
|
* Remove `python-virtualenv` which was no longer used.
|
||||||
|
* Change the installation path of the `virtualenv.py` script. (`./libexec` -> `./libexec/pyenv-virtualenv/${VIRTUALENV_VERSION}`)
|
||||||
|
* Download `virtualenv.py` if desired version has not been installed.
|
||||||
|
|
||||||
|
#### 20130507
|
||||||
|
|
||||||
|
* Display virtualenv information in `--help` and `--version`
|
||||||
|
* Update virtualenv version; 1.8.4 -> 1.9.1
|
||||||
|
|
||||||
|
#### 20130307
|
||||||
|
|
||||||
|
* Rename the project; `s/python-virtualenv/pyenv-virtualenv/g`
|
||||||
|
* The `pyenv-virtualenv` script is not depending on `python-virtualenv` now.
|
||||||
|
`python-virtualenv` will left for compatibility and will not continue for future releases.
|
||||||
|
* Update virtualenv version; 1.8.2 -> 1.8.4
|
||||||
|
|
||||||
|
#### 20130218
|
||||||
|
|
||||||
|
* Add pyenv 0.2.x (rbenv 0.4.x) style help messages.
|
||||||
|
|
||||||
|
#### 20121023
|
||||||
|
|
||||||
|
* Create virtualenv with exact name of python executables.
|
||||||
|
* Changed command-line options of python-virtualenv.
|
||||||
|
First argument should be a path to the python executable.
|
||||||
|
* Add install script.
|
||||||
|
|
||||||
#### 20120927
|
#### 20120927
|
||||||
|
|
||||||
* Initial public release.
|
* Initial public release.
|
||||||
@@ -46,8 +92,7 @@ under `~/.pyenv/versions`.
|
|||||||
|
|
||||||
(The MIT License)
|
(The MIT License)
|
||||||
|
|
||||||
Copyright (c) 2012 Yamashita, Yuu
|
* Copyright (c) 2013 Yamashita, Yuu
|
||||||
Copyright (c) 2011 Sam Stephenson
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining
|
Permission is hereby granted, free of charge, to any person obtaining
|
||||||
a copy of this software and associated documentation files (the
|
a copy of this software and associated documentation files (the
|
||||||
|
|||||||
@@ -1,44 +1,162 @@
|
|||||||
#!/usr/bin/env bash
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Summary: Create a Python virtualenv using the pyenv-virtualenv plugin
|
||||||
|
#
|
||||||
|
# Usage: pyenv virtualenv [-f|--force] [-u|--upgrade] [VIRTUALENV_OPTIONS] <version> <virtualenv-name>
|
||||||
|
# pyenv virtualenv --version
|
||||||
|
# pyenv virtualenv --help
|
||||||
|
#
|
||||||
|
# -u/--upgrade Upgrade existing virtualenv with migrating installed packages
|
||||||
|
# -f/--force Install even if the version appears to be installed already
|
||||||
|
#
|
||||||
|
|
||||||
|
PYENV_VIRTUALENV_VERSION="20130614"
|
||||||
|
VIRTUALENV_VERSION="${VIRTUALENV_VERSION:-1.9.1}"
|
||||||
|
|
||||||
set -e
|
set -e
|
||||||
[ -n "$PYENV_DEBUG" ] && set -x
|
[ -n "$PYENV_DEBUG" ] && set -x
|
||||||
|
|
||||||
# Provide pyenv completions
|
# Provide pyenv completions
|
||||||
if [ "$1" = "--complete" ]; then
|
if [ "$1" = "--complete" ]; then
|
||||||
exec pyenv versions --bare
|
exec pyenv-versions --bare
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -z "$PYENV_ROOT" ]; then
|
if [ -z "$PYENV_ROOT" ]; then
|
||||||
PYENV_ROOT="${HOME}/.pyenv"
|
PYENV_ROOT="${HOME}/.pyenv"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Load shared library functions
|
# Define library functions
|
||||||
eval "$(python-virtualenv --lib)"
|
parse_options() {
|
||||||
|
OPTIONS=()
|
||||||
|
ARGUMENTS=()
|
||||||
|
local arg option index
|
||||||
|
|
||||||
|
for arg in "$@"; do
|
||||||
|
if [ "${arg:0:1}" = "-" ]; then
|
||||||
|
if [ "${arg:1:1}" = "-" ]; then
|
||||||
|
OPTIONS[${#OPTIONS[*]}]="${arg:2}"
|
||||||
|
else
|
||||||
|
index=1
|
||||||
|
while option="${arg:$index:1}"; do
|
||||||
|
[ -n "$option" ] || break
|
||||||
|
OPTIONS[${#OPTIONS[*]}]="$option"
|
||||||
|
index=$(($index+1))
|
||||||
|
done
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
ARGUMENTS[${#ARGUMENTS[*]}]="$arg"
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve_link() {
|
||||||
|
$(type -p greadlink readlink | head -1) "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
abs_dirname() {
|
||||||
|
local cwd="$(pwd)"
|
||||||
|
local path="$1"
|
||||||
|
|
||||||
|
while [ -n "$path" ]; do
|
||||||
|
cd "${path%/*}"
|
||||||
|
local name="${path##*/}"
|
||||||
|
path="$(resolve_link "$name" || true)"
|
||||||
|
done
|
||||||
|
|
||||||
|
pwd
|
||||||
|
cd "$cwd"
|
||||||
|
}
|
||||||
|
|
||||||
|
http() {
|
||||||
|
local method="$1"
|
||||||
|
local url="$2"
|
||||||
|
local file="$3"
|
||||||
|
[ -n "$url" ] || return 1
|
||||||
|
|
||||||
|
if type curl &>/dev/null; then
|
||||||
|
"http_${method}_curl" "$url" "$file"
|
||||||
|
elif type wget &>/dev/null; then
|
||||||
|
"http_${method}_wget" "$url" "$file"
|
||||||
|
else
|
||||||
|
echo "error: please install \`curl\` or \`wget\` and try again" >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
http_head_curl() {
|
||||||
|
curl -qsILf "$1" >&4 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
http_get_curl() {
|
||||||
|
curl -C - -o "${2:--}" -qsSLf "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
http_head_wget() {
|
||||||
|
wget -q --spider "$1" >&4 2>&1
|
||||||
|
}
|
||||||
|
|
||||||
|
http_get_wget() {
|
||||||
|
wget -nv -c -O "${2:--}" "$1"
|
||||||
|
}
|
||||||
|
|
||||||
|
version() {
|
||||||
|
local version="$(pyenv-exec python "${VIRTUALENV}" --version 2>/dev/null || true)"
|
||||||
|
echo "pyenv-virtualenv ${PYENV_VIRTUALENV_VERSION} (virtualenv ${version:-unknown})"
|
||||||
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
{ echo "usage: pyenv virtualenv [-v|--verbose] [VIRTUALENV_OPTIONS] PYTHON_VERSION NAME"
|
# We can remove the sed fallback once pyenv 0.2.0 is widely available.
|
||||||
echo
|
pyenv-help virtualenv 2>/dev/null || sed -ne '/^#/!q;s/.//;s/.//;1,4d;p' < "$0"
|
||||||
echo " -v/--verbose Verbose mode: print compilation status to stdout"
|
pyenv-exec python "${VIRTUALENV}" --help 2>/dev/null || true
|
||||||
echo
|
|
||||||
} >&2
|
|
||||||
|
|
||||||
[ -z "$1" ] || exit "$1"
|
[ -z "$1" ] || exit "$1"
|
||||||
}
|
}
|
||||||
|
|
||||||
unset VERBOSE
|
ensure_virtualenv() {
|
||||||
|
local file="$1"
|
||||||
|
local url="$2"
|
||||||
|
[ -f "${file}" ] || {
|
||||||
|
mkdir -p "$(dirname "${file}")"
|
||||||
|
http get "${url}" "${file}"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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=()
|
VIRTUALENV_OPTIONS=()
|
||||||
|
|
||||||
|
ensure_virtualenv "${VIRTUALENV}" "${VIRTUALENV_URL}" || {
|
||||||
|
echo "pyenv-virtualenv: could not find virtualenv script: ${VIRTUALENV}" 1>&2
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
unset FORCE
|
||||||
|
unset UPGRADE
|
||||||
|
# Unset environment variables which starts with `VIRTUALENV_`.
|
||||||
|
# These variables are reserved for virtualenv.
|
||||||
|
unset VIRTUALENV_VERSION
|
||||||
|
|
||||||
parse_options "$@"
|
parse_options "$@"
|
||||||
for option in "${OPTIONS[@]}"; do
|
for option in "${OPTIONS[@]}"; do
|
||||||
case "$option" in
|
case "$option" in
|
||||||
|
"f" | "force" )
|
||||||
|
FORCE=true
|
||||||
|
;;
|
||||||
"h" | "help" )
|
"h" | "help" )
|
||||||
usage 0
|
usage 0
|
||||||
;;
|
;;
|
||||||
"v" | "verbose" )
|
"u" | "upgrade" )
|
||||||
VERBOSE="-v"
|
UPGRADE=true
|
||||||
;;
|
;;
|
||||||
"version" )
|
"version" )
|
||||||
exec python-virtualenv --version
|
version
|
||||||
|
exit 0
|
||||||
;;
|
;;
|
||||||
* )
|
* )
|
||||||
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--$option"
|
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--$option"
|
||||||
@@ -46,16 +164,156 @@ for option in "${OPTIONS[@]}"; do
|
|||||||
esac
|
esac
|
||||||
done
|
done
|
||||||
|
|
||||||
|
# The first argument contains the source version to create virtualenv.
|
||||||
VERSION_NAME="${ARGUMENTS[0]}"
|
VERSION_NAME="${ARGUMENTS[0]}"
|
||||||
[ -n "$VERSION_NAME" ] || usage 1
|
[ -n "$VERSION_NAME" ] || usage 1
|
||||||
|
|
||||||
|
if [ -z "$TMPDIR" ]; then
|
||||||
|
TMP="/tmp"
|
||||||
|
else
|
||||||
|
TMP="${TMPDIR%/}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
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"
|
||||||
|
|
||||||
|
|
||||||
|
# Define `before_virtualenv` and `after_virtualenv` functions that allow
|
||||||
|
# plugin hooks to register a string of code for execution before or
|
||||||
|
# after the installation process.
|
||||||
|
declare -a before_hooks after_hooks
|
||||||
|
|
||||||
|
before_virtualenv() {
|
||||||
|
local hook="$1"
|
||||||
|
before_hooks["${#before_hooks[@]}"]="$hook"
|
||||||
|
}
|
||||||
|
|
||||||
|
after_virtualenv() {
|
||||||
|
local hook="$1"
|
||||||
|
after_hooks["${#after_hooks[@]}"]="$hook"
|
||||||
|
}
|
||||||
|
|
||||||
|
# Load plugin hooks.
|
||||||
for script in $(pyenv-hooks virtualenv); do
|
for script in $(pyenv-hooks virtualenv); do
|
||||||
source "$script"
|
source "$script"
|
||||||
done
|
done
|
||||||
|
|
||||||
PYTHON_PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}"
|
|
||||||
VIRTUALENV_NAME="${ARGUMENTS[1]##*/}"
|
|
||||||
VIRTUALENV_PATH="${PYENV_ROOT}/versions/${VIRTUALENV_NAME}"
|
|
||||||
|
|
||||||
python-virtualenv $VERBOSE "${VIRTUALENV_OPTIONS[@]}" "$PYTHON_PREFIX" "$VIRTUALENV_PATH"
|
[ -d "${VIRTUALENV_PATH}" ] && PREFIX_EXISTS=1
|
||||||
pyenv rehash
|
|
||||||
|
# If the virtualenv exists, prompt for confirmation unless
|
||||||
|
# the --force option was specified.
|
||||||
|
if [ -d "${VIRTUALENV_PATH}/bin" ]; then
|
||||||
|
if [ -z "$FORCE" ]; then
|
||||||
|
echo "pyenv: ${VIRTUALENV_PATH} already exists" 1>&2
|
||||||
|
read -p "continue with installation? (y/N) "
|
||||||
|
|
||||||
|
case "$REPLY" in
|
||||||
|
y* | Y* ) ;;
|
||||||
|
* ) exit 1 ;;
|
||||||
|
esac
|
||||||
|
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
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Execute `before_virtualenv` hooks.
|
||||||
|
for hook in "${before_hooks[@]}"; do eval "$hook"; done
|
||||||
|
|
||||||
|
# Plan cleanup on unsuccessful installation.
|
||||||
|
cleanup() {
|
||||||
|
[ -z "${PREFIX_EXISTS}" ] && rm -rf "$VIRTUALENV_PATH"
|
||||||
|
}
|
||||||
|
|
||||||
|
trap cleanup SIGINT
|
||||||
|
|
||||||
|
# Invoke virtualenv and record exit status in $STATUS.
|
||||||
|
STATUS=0
|
||||||
|
# virtualenv may download distribute/setuptools in current directory.
|
||||||
|
# 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=$?
|
||||||
|
|
||||||
|
# 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 )
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
## 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
|
||||||
|
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
|
||||||
|
for hook in "${after_hooks[@]}"; do eval "$hook"; done
|
||||||
|
|
||||||
|
# Run `pyenv-rehash` after a successful installation.
|
||||||
|
if [ "$STATUS" == "0" ]; then
|
||||||
|
pyenv-rehash
|
||||||
|
else
|
||||||
|
cleanup
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit "$STATUS"
|
||||||
|
|||||||
19
bin/pyenv-virtualenv-prefix
Executable file
19
bin/pyenv-virtualenv-prefix
Executable file
@@ -0,0 +1,19 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Summary: Display real_prefix for a Python virtualenv version
|
||||||
|
# Usage: pyenv virtualenv-prefix [<virtualenv>]
|
||||||
|
#
|
||||||
|
|
||||||
|
set -e
|
||||||
|
[ -n "$PYENV_DEBUG" ] && set -x
|
||||||
|
|
||||||
|
if [ -z "$PYENV_ROOT" ]; then
|
||||||
|
PYENV_ROOT="${HOME}/.pyenv"
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ -n "$1" ]; then
|
||||||
|
export PYENV_VERSION="$1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
PYTHON_BIN="$(pyenv-which python)"
|
||||||
|
"${PYTHON_BIN}" -c 'import sys;print(sys.real_prefix)' 2>/dev/null
|
||||||
42
bin/pyenv-virtualenvs
Executable file
42
bin/pyenv-virtualenvs
Executable file
@@ -0,0 +1,42 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
#
|
||||||
|
# Summary: List all Python virtualenvs found in `$PYENV_ROOT/versions/*'.
|
||||||
|
#
|
||||||
|
# Usage: pyenv virtualenvs [--bare]
|
||||||
|
#
|
||||||
|
|
||||||
|
set -e
|
||||||
|
[ -n "$PYENV_DEBUG" ] && set -x
|
||||||
|
|
||||||
|
if [ -z "$PYENV_ROOT" ]; then
|
||||||
|
PYENV_ROOT="${HOME}/.pyenv"
|
||||||
|
fi
|
||||||
|
|
||||||
|
unset BARE
|
||||||
|
|
||||||
|
if [ "$1" = "--bare" ]; then
|
||||||
|
BARE=true
|
||||||
|
fi
|
||||||
|
|
||||||
|
print_version() {
|
||||||
|
local version="$1"
|
||||||
|
if [ -n "${BARE}" ]; then
|
||||||
|
echo "${version}"
|
||||||
|
else
|
||||||
|
echo "${version} (created from $(pyenv-virtualenv-prefix "${version}"))"
|
||||||
|
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}"
|
||||||
|
fi
|
||||||
|
done
|
||||||
@@ -1,118 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
|
|
||||||
PYTHON_VIRTUALENV_VERSION="20120927"
|
|
||||||
|
|
||||||
set -E
|
|
||||||
exec 3<&2 # preserve original stderr at fd 3
|
|
||||||
|
|
||||||
|
|
||||||
lib() {
|
|
||||||
parse_options() {
|
|
||||||
OPTIONS=()
|
|
||||||
ARGUMENTS=()
|
|
||||||
local arg option index
|
|
||||||
|
|
||||||
for arg in "$@"; do
|
|
||||||
if [ "${arg:0:1}" = "-" ]; then
|
|
||||||
if [ "${arg:1:1}" = "-" ]; then
|
|
||||||
OPTIONS[${#OPTIONS[*]}]="${arg:2}"
|
|
||||||
else
|
|
||||||
index=1
|
|
||||||
while option="${arg:$index:1}"; do
|
|
||||||
[ -n "$option" ] || break
|
|
||||||
OPTIONS[${#OPTIONS[*]}]="$option"
|
|
||||||
index=$(($index+1))
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
else
|
|
||||||
ARGUMENTS[${#ARGUMENTS[*]}]="$arg"
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
if [ "$1" == "--$FUNCNAME" ]; then
|
|
||||||
declare -f "$FUNCNAME"
|
|
||||||
echo "$FUNCNAME \"\$1\";"
|
|
||||||
exit
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
lib "$1"
|
|
||||||
|
|
||||||
resolve_link() {
|
|
||||||
$(type -p greadlink readlink | head -1) "$1"
|
|
||||||
}
|
|
||||||
|
|
||||||
abs_dirname() {
|
|
||||||
local cwd="$(pwd)"
|
|
||||||
local path="$1"
|
|
||||||
|
|
||||||
while [ -n "$path" ]; do
|
|
||||||
cd "${path%/*}"
|
|
||||||
local name="${path##*/}"
|
|
||||||
path="$(resolve_link "$name" || true)"
|
|
||||||
done
|
|
||||||
|
|
||||||
pwd
|
|
||||||
cd "$cwd"
|
|
||||||
}
|
|
||||||
|
|
||||||
version() {
|
|
||||||
echo "python-virtualenv ${PYTHON_VIRTUALENV_VERSION}"
|
|
||||||
}
|
|
||||||
|
|
||||||
usage() {
|
|
||||||
{ version
|
|
||||||
echo "usage: python-virtualenv [-v|--verbose] [VIRTUALENV_OPTIONS] python_prefix virtualenv_path"
|
|
||||||
} >&2
|
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
}
|
|
||||||
|
|
||||||
unset VERBOSE
|
|
||||||
PYTHON_VIRTUALENV_ROOT="$(abs_dirname "$0")/.."
|
|
||||||
VIRTUALENV_OPTIONS=()
|
|
||||||
|
|
||||||
parse_options "$@"
|
|
||||||
|
|
||||||
for option in "${OPTIONS[@]}"; do
|
|
||||||
case "$option" in
|
|
||||||
"h" | "help" )
|
|
||||||
usage without_exiting
|
|
||||||
{ echo
|
|
||||||
echo " -v/--verbose Verbose mode: print compilation status to stdout"
|
|
||||||
echo
|
|
||||||
} >&2
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
"v" | "verbose" )
|
|
||||||
VERBOSE=true
|
|
||||||
;;
|
|
||||||
"version" )
|
|
||||||
version
|
|
||||||
exit 0
|
|
||||||
;;
|
|
||||||
* )
|
|
||||||
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--$option"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
|
||||||
|
|
||||||
PYTHON_PREFIX="${ARGUMENTS[0]}"
|
|
||||||
if [ -z "$PYTHON_PREFIX" ]; then
|
|
||||||
usage
|
|
||||||
elif [ ! -x "${PYTHON_PREFIX}/bin/python" ]; then
|
|
||||||
echo "python-virtualenv: python not found: ${PYTHON_PREFIX}" >&2
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
VIRTUALENV_PATH="${ARGUMENTS[1]}"
|
|
||||||
if [ -z "$VIRTUALENV_PATH" ]; then
|
|
||||||
usage
|
|
||||||
fi
|
|
||||||
|
|
||||||
PYTHON_BIN="${PYTHON_PREFIX}/bin/python"
|
|
||||||
CWD="$(pwd)"
|
|
||||||
|
|
||||||
"${PYTHON_BIN}" "${PYTHON_VIRTUALENV_ROOT}/libexec/virtualenv.py" --python="${PYTHON_BIN}" "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}"
|
|
||||||
23
install.sh
Executable file
23
install.sh
Executable file
@@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
if [ -z "${PREFIX}" ]; then
|
||||||
|
PREFIX="/usr/local"
|
||||||
|
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