77 Commits

Author SHA1 Message Date
Yamashita Yuu
fa9950aa5b v20140110 2014-01-10 11:35:19 +09:00
Yamashita Yuu
124645e84c Use ez_setup.py and get_pip.py on filesystem if exist 2014-01-09 18:46:44 +09:00
Yamashita Yuu
ec60d5dfcb Support a short option of virtualenv: -p 2014-01-09 11:19:39 +09:00
Yamashita Yuu
d96a00ece3 v20131216 2013-12-16 13:58:10 +09:00
Yamashita, Yuu
20e31ed587 Merge pull request #3 from eikonomega/patch-1
Update README.md
2013-09-03 19:22:37 -07:00
Michael Dunn
32bfce2e41 Update 'Using pyenv virtualenv with pyenv' section.
Explicitly define the parameters that you pass into 'pyenv virtualenv' and what they stand for.
2013-09-03 17:15:53 -04:00
Michael Dunn
99de2882e3 Update README.md
Make it explicit that the 'installing as a plugin' section is assuming that you've installed pyenv in the standard location and what to do if you've done something else.  Clarify the language a little bit about checking out a specific release vs. pulling the current development version.
2013-09-03 17:10:23 -04:00
Yamashita Yuu
39bac37090 Add new installation method. pyenv-virtualenv is now a part of Homebrew! 2013-08-06 22:58:18 +09:00
Yamashita Yuu
a4ce544798 Remove embeded version string of setuptools/pip. 2013-07-17 16:03:31 +09:00
Yamashita Yuu
16a4a8d37e Update setuptools (0.8 -> 0.9.5) 2013-07-17 15:52:32 +09:00
Yamashita Yuu
8d4b901250 update setuptools (0.7.7 -> 0.8) 2013-07-08 16:30:07 +09:00
Yamashita Yuu
8363a4f0e0 update setuptools (0.7.4 -> 0.7.7) 2013-07-05 11:16:02 +09:00
Yamashita Yuu
79c4e62886 v20130622 2013-06-22 10:30:00 +09:00
Yamashita Yuu
eee0e2bea8 update README 2013-06-21 19:49:36 +09:00
Yamashita Yuu
2f20c56b1d remove redundant checks for pyenv-prefix 2013-06-21 19:42:46 +09:00
Yamashita Yuu
77f9c1502d like pyenv versions, show "*" on the start of line if the environment
is enabled
2013-06-21 19:40:59 +09:00
Yamashita Yuu
327b8b7615 do not create python executable in pyenv-virtualenv
it will be created by `virtualenv` or `pyvenv`
2013-06-20 17:53:45 +09:00
Yamashita Yuu
8eecec0d7d Merge branch 'pyvenv' 2013-06-20 17:47:52 +09:00
Yamashita Yuu
23a115c12a set STATUS as non-zero even if the setuptools or pip have failed to
install into pyvenv
2013-06-20 16:25:54 +09:00
Yamashita Yuu
f3c5a64281 renamed virtualenv() to venv() 2013-06-20 14:56:24 +09:00
Yamashita Yuu
384fab86ef add EZ_SETUP_URL and GET_PIP_URL 2013-06-20 14:50:20 +09:00
Yamashita Yuu
f0ca1b27d0 add SETUPTOOLS_VERSION and PIP_VERSION 2013-06-20 13:48:01 +09:00
Yamashita Yuu
2e5db090a9 install setuptools and pip into pyvenv 2013-06-20 12:23:46 +09:00
Yamashita Yuu
11792cbaf9 Remove --pyvenv option.
Use pyvenv only if virtualenv is not installed and there is pyvenv.
2013-06-20 11:59:54 +09:00
Yamashita Yuu
6e7945a626 prefer pyvenv rather than virtualenv if --pyvenv is given 2013-06-19 23:57:45 +09:00
Yamashita Yuu
1db9840620 check existence of ./bin/activate to detect virtualenvs to support pyvenv 2013-06-19 23:39:26 +09:00
Yamashita Yuu
212021c322 update README 2013-06-18 23:55:48 +09:00
Yamashita Yuu
7507cb1e41 apply $QUIET and $VERBOSE both pip and virtualenv 2013-06-18 23:39:43 +09:00
Yamashita Yuu
7a54a83392 fix --help option 2013-06-18 23:34:04 +09:00
Yamashita Yuu
551956f017 improve arguments handling 2013-06-18 23:26:30 +09:00
Yamashita Yuu
1ad6788e84 Merge branch 'remove-bundled-virtualenv.py' 2013-06-18 19:34:27 +09:00
Yamashita Yuu
f78a393864 fixed broken reference for "${PYTHON_BIN}" 2013-06-18 14:54:11 +09:00
Yamashita Yuu
a4de1d7e89 Removed bundled virtualenv.py script. Now pyenv-virtualenv installs
`virtualenv` package into source version and then use it.
2013-06-18 12:21:16 +09:00
Yamashita Yuu
f2bd87fc3e support virtualenv's short option of "-q" 2013-06-15 12:42:30 +09:00
Yamashita Yuu
2a5a483c5d v20130614 2013-06-14 21:31:24 +09:00
Yamashita Yuu
a2c878f284 remove --distribute from example.
it will be replaced by new setuptools in near future.
2013-06-04 20:32:22 +09:00
Yamashita Yuu
b7c498ce03 add pyenv-virtualenv-prefix 2013-06-04 18:56:58 +09:00
Yamashita Yuu
6915cd0320 no need to import print_function in this case 2013-06-04 17:52:10 +09:00
Yamashita Yuu
4263783195 add pyenv virtualenvs command 2013-06-04 17:07:48 +09:00
Yamashita Yuu
65b58770a7 display package list on unsuccessful upgrade 2013-05-28 21:07:35 +09:00
Yamashita Yuu
66546cea12 ignore stderr from pyenv-exec 2013-05-28 16:54:25 +09:00
Yamashita Yuu
7562795c42 test the existence of ${VIRTUALENV_PIP_BIN} before invoking it 2013-05-28 16:30:39 +09:00
Yamashita Yuu
72592fde6b Merge branch 'upgrade-virtualenv' 2013-05-28 13:44:37 +09:00
Yamashita Yuu
8ac27a7a77 add --upgrade option to upgrade existing virtualenv 2013-05-28 13:43:17 +09:00
Yamashita Yuu
f9532f6c4e load hooks just before creating virtualenv 2013-05-28 13:37:32 +09:00
Yamashita Yuu
67d6cfc0d2 handle --force option expectedly 2013-05-27 23:50:13 +09:00
Yamashita Yuu
695c2fd618 v20130527 2013-05-27 20:26:42 +09:00
Yamashita Yuu
bc433be75c update README 2013-05-27 20:25:57 +09:00
Yamashita Yuu
16470ec39c Unset environment variables which starts with VIRTUALENV_. These variables are reserved for virtualenv. 2013-05-08 15:51:09 +09:00
Yamashita Yuu
c8b9969619 (1) fix handling of hooks
(2) remove $VIRTUALENV_PATH after failed creation
2013-05-08 14:28:56 +09:00
Yamashita Yuu
3b7be75458 restore missing VIRTUALENV_PYTHON_BIN 2013-05-08 14:08:26 +09:00
Yamashita Yuu
404918c7d9 Merge branch 'virtualenv-install' 2013-05-07 22:56:32 +09:00
Yamashita Yuu
20e78d8ffa update README 2013-05-07 22:54:43 +09:00
Yamashita Yuu
db37bb9643 Download virtualenv.py if specified version has not been installed. 2013-05-07 22:31:12 +09:00
Yamashita Yuu
a9903fab6e make installation path of virtualenv.py configurable 2013-05-07 21:51:12 +09:00
Yamashita Yuu
b594b99a18 s/VIRTUALENV_CACHE_PATH/PYENV_&/g 2013-05-07 21:26:28 +09:00
Yamashita Yuu
9e438ee3e2 Change the installation path of the virtualenv.py script. 2013-05-07 21:22:51 +09:00
Yamashita Yuu
1389d840d1 Remove python-virtualenv which was no longer used. 2013-05-07 21:15:07 +09:00
Yamashita Yuu
78af7ec9d4 release v20130507 2013-05-07 19:55:31 +09:00
Yamashita Yuu
5b357d2862 display virtualenv's help message on '--help' 2013-05-01 13:07:49 +09:00
Yamashita Yuu
5baa5084dc don't capture '-v' option in $VERBOSE to pass it to virtualenv 2013-05-01 13:05:32 +09:00
Yamashita Yuu
0f8477fcf5 store distribute/setuptools archive in $PYTHON_BUILD_CACHE_PATH to reuse
them between invocations.
2013-04-30 19:55:49 +09:00
Yamashita Yuu
aec759a0e0 ignore error on checking virtualenv version 2013-04-26 13:03:35 +09:00
Yamashita Yuu
15608701ae show virtualenv version in pyenv virtualenv --version 2013-04-25 22:10:29 +09:00
Yamashita Yuu
d927b2e137 update virtualenv version (1.8.4 -> 1.9.1) 2013-04-25 21:45:44 +09:00
Yamashita Yuu
ebeb3dcb71 fix wrong path for libexec 2013-03-27 15:15:44 +09:00
Yamashita Yuu
8b1ae9f19a update README. add note about pyenv-virtualenvwrapper. 2013-03-22 15:38:08 +09:00
Yamashita Yuu
003ea01b97 release v20130307 2013-03-07 13:12:17 +09:00
Yamashita Yuu
1a2d06bc05 update copyright 2013-02-23 19:09:49 +09:00
Yamashita Yuu
5ed1988b34 update README 2013-02-23 16:46:09 +09:00
Yamashita Yuu
c65e8b266b update README 2013-02-20 18:43:07 +09:00
Yamashita Yuu
6ee4bf1e5c Update virtualenv version; 1.8.2 -> 1.8.4 2013-02-18 13:16:10 +09:00
Yamashita Yuu
2910f87cb6 Preparing for renaming project; s/python-virtualenv/pyenv-virtualenv/g 2013-02-18 13:14:42 +09:00
Yamashita Yuu
9651cfe63d release 20130218 2013-02-18 12:42:21 +09:00
Yamashita Yuu
317fcdbfe7 add rbenv 0.4.x style documentation 2013-01-31 12:23:17 +09:00
Yamashita Yuu
fce66ebba7 s/an/a/g 2012-11-06 13:21:21 +09:00
Yamashita Yuu
2551913d75 fix broken markup in README 2012-11-02 22:03:01 +09:00
9 changed files with 547 additions and 2689 deletions

8
.gitignore vendored
View File

@@ -1,6 +1,6 @@
/libexec/*.class /libexec/pyenv-virtualenv/*/*.class
/libexec/*.pyc /libexec/pyenv-virtualenv/*/*.pyc
/libexec/*.pyo /libexec/pyenv-virtualenv/*/*.pyo
/libexec/__pycache__ /libexec/pyenv-virtualenv/*/__pycache__
*.swo *.swo
*.swp *.swp

View File

@@ -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

148
README.md
View File

@@ -1,61 +1,144 @@
# 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.
can check out a specific release tag. To update python-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.
### Installing as a standalone program (advanced) 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 python-virtualenv as a standalone program will give you access to ### Installing with Homebrew (for OS X users)
the `python-virtualenv` command for precise control over Python version
installation. If you have rbenv installed, you will also be able to
use the `rbenv install` command.
$ git clone git://github.com/yyuu/python-virtualenv.git Mac OS X users can install pyenv-virtualenv with the
$ cd python-virtualenv [Homebrew](http://brew.sh) package manager. This
$ ./install.sh 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 will install python-virtualenv into `/usr/local`. If you do not have *This is recommended method of installation if you installed pyenv
write permission to `/usr/local`, you will need to run `sudo with Homebrew.*
./install.sh` instead. You can install to a different prefix by
setting the `PREFIX` environment variable. brew install pyenv-virtualenv
Or, if you would like to install the latest development release:
brew install --HEAD pyenv-virtualenv
To update python-virtualenv after it has been installed, run `git pull` in
your cloned copy of the repository, then re-run the install script.
## Usage ## Usage
### 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` with tha exact name of the version you want to create `pyenv virtualenv`, specifying the Python version you want and the name
virtualenv. For example, of the virtualenv directory. For example,
$ pyenv virtualenv --distribute 2.7.3 venv27 $ pyenv virtualenv 2.7.6 my-virtual-env-2.7.6
virtualenvs will be created into a directory of the same name will create a virtualenv based on Python 2.7.6
under `~/.pyenv/versions`. 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)
### 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.
* `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 ## 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
#### 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 #### 20121023
* Create virtualenv with exact name of python executables. * Create virtualenv with exact name of python executables.
@@ -71,8 +154,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

View File

@@ -1,83 +1,368 @@
#!/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 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="20140110"
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="$(venv --version 2>/dev/null || true)"
echo "pyenv-virtualenv ${PYENV_VIRTUALENV_VERSION} (virtualenv ${version:-unknown})"
}
usage() { usage() {
{ echo "usage: pyenv virtualenv [-v|--verbose] [VIRTUALENV_OPTIONS] VERSION VIRTUALENV_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" venv --help 2>/dev/null || true
echo
} >&2
[ -z "$1" ] || exit "$1" [ -z "$1" ] || exit "$1"
} }
unset VERBOSE 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
VIRTUALENV_OPTIONS=() VIRTUALENV_OPTIONS=()
unset FORCE
unset QUIET
unset UPGRADE
unset VERBOSE
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
;; ;;
"p" )
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--python=${ARGUMENTS[0]}"
ARGUMENTS=("${ARGUMENTS[@]:1}") # shift 1
;;
"q" | "quiet" )
QUIET="--quiet"
;;
"u" | "upgrade" )
UPGRADE=true
;;
"v" | "verbose" ) "v" | "verbose" )
VERBOSE="-v" VERBOSE="--verbose"
;; ;;
"version" ) "version" )
exec python-virtualenv --version version
exit 0
;; ;;
* ) * ) # virtualenv long options
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--$option" VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--$option"
;; ;;
esac esac
done done
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]}" VERSION_NAME="${ARGUMENTS[0]}"
[ -n "$VERSION_NAME" ] || usage 1 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"
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"
VIRTUALENV_PATH="${PYENV_ROOT}/versions/${VIRTUALENV_NAME}"
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
# 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_BIN=$(PYENV_VERSION="${VERSION_NAME}" pyenv-which python)
if [ ! -x "${PYTHON_BIN}" ]; then [ -d "${VIRTUALENV_PATH}" ] && PREFIX_EXISTS=1
echo "pyenv-virtualenv: could not obtain python executable: ${PYTHON_BIN}" >&2
exit 1 # 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 fi
# find canonical name of python executable. if [ -n "$UPGRADE" ]; then
# virtualenv will create "bin/python" executable as same name as its bootstraped python. PYENV_VERSION="${VIRTUALENV_NAME}" pyenv-exec pip freeze >"${UPGRADE_LIST}"
if [ -L "${PYTHON_BIN}" ]; then mv -f "${VIRTUALENV_PATH}" "${UPGRADE_PATH}"
while [ -L "${PYTHON_BIN}" ]; do # retrieve symlinks fi
PYTHON_BIN="$(dirname "${PYTHON_BIN}")/$(resolve_link "${PYTHON_BIN}")" fi
done
# 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}"
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
}
PYENV_VERSION="${VIRTUALENV_NAME}" pyenv-which pip 1>/dev/null 2>&1 || {
install_pip "${VIRTUALENV_NAME}" 1>&2
}
fi
} || STATUS="$?"
## Migrate previously installed packages from requirements.txt
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 else
# python 2.6 and older don't have "bin/python" as symlink. { echo
# so we must traverse files like "bin/python*" to obtain canonical name. echo "UPGRADE FAILED"
for python in ${PYENV_ROOT}/versions/${VERSION_NAME}/bin/python*; do echo
if ( basename "$python" | grep '^python[0-9][0-9]*\.[0-9][0-9]*$' && cmp "$PYTHON_BIN" "$python" ) >/dev/null; then echo "Inspect or clean up the original tree at ${UPGRADE_PATH}"
PYTHON_BIN="${python}" echo
break echo "Package list:"
cat "${UPGRADE_LIST}"
} 1>&2
STATUS="$UPGRADE_STATUS"
fi fi
done
fi fi
VIRTUALENV_NAME="${ARGUMENTS[1]##*/}" # Execute `after_virtualenv` hooks
VIRTUALENV_PATH="${PYENV_ROOT}/versions/${VIRTUALENV_NAME}" for hook in "${after_hooks[@]}"; do eval "$hook"; done
python-virtualenv $VERBOSE "${VIRTUALENV_OPTIONS[@]}" "$PYTHON_BIN" "$VIRTUALENV_PATH" # Run `pyenv-rehash` after a successful installation.
pyenv rehash if [ "$STATUS" == "0" ]; then
pyenv-rehash
else
cleanup
fi
exit "$STATUS"

47
bin/pyenv-virtualenv-prefix Executable file
View File

@@ -0,0 +1,47 @@
#!/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
versions=($@)
IFS=: PYENV_VERSION="${versions[*]}"
export PYENV_VERSION
else
IFS=: versions=($(pyenv-version-name))
fi
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[*]}"

56
bin/pyenv-virtualenvs Executable file
View File

@@ -0,0 +1,56 @@
#!/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
if [ "$1" = "--bare" ]; then
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() {
if [ -n "${print_origin}" ]; then
local version_origin="$2"
else
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
}
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

View File

@@ -1,130 +0,0 @@
#!/usr/bin/env bash
PYTHON_VIRTUALENV_VERSION="20121023"
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
}
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"
}
if [ "$1" == "--$FUNCNAME" ]; then
declare -f "$FUNCNAME"
echo "$FUNCNAME \"\$1\";"
exit
fi
}
lib "$1"
version() {
echo "python-virtualenv ${PYTHON_VIRTUALENV_VERSION}"
}
usage() {
{ version
echo "usage: python-virtualenv [-v|--verbose] [VIRTUALENV_OPTIONS] python_bin 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_BIN="${ARGUMENTS[0]}"
if [ -z "${PYTHON_BIN}" ]; then
usage
elif [ ! -x "${PYTHON_BIN}" ]; then
echo "python-virtualenv: given python is not an executable: ${PYTHON_BIN}" >&2
exit 1
fi
VIRTUALENV_PATH="${ARGUMENTS[1]}"
if [ -z "$VIRTUALENV_PATH" ]; then
usage
fi
VIRTUALENV_PYTHON_BIN="${VIRTUALENV_PATH}/bin/python"
# create virtualenv
VIRTUALENV="${PYTHON_VIRTUALENV_ROOT}/libexec/python-virtualenv/virtualenv.py"
[ -f "${VIRTUALENV}" ] || VIRTUALENV="${PYTHON_VIRTUALENV_ROOT}/libexec/virtualenv.py"
"${PYTHON_BIN}" "${VIRTUALENV}" "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}"
# 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

View File

@@ -7,17 +7,11 @@ if [ -z "${PREFIX}" ]; then
fi fi
BIN_PATH="${PREFIX}/bin" BIN_PATH="${PREFIX}/bin"
LIBEXEC_PATH="${PREFIX}/libexec/python-virtualenv"
mkdir -p "${BIN_PATH}" mkdir -p "${BIN_PATH}"
mkdir -p "${LIBEXEC_PATH}"
for file in bin/*; do for file in bin/*; do
cp "${file}" "${BIN_PATH}" cp "${file}" "${BIN_PATH}"
done done
for file in libexec/*; do echo "Installed pyenv-virtualenv at ${PREFIX}"
cp "${file}" "${LIBEXEC_PATH}"
done
echo "Installed python-virtualenv at ${PREFIX}"

File diff suppressed because it is too large Load Diff