8 Commits

Author SHA1 Message Date
Yamashita Yuu
2e418ee563 release 20121023 2012-10-23 15:50:39 +09:00
Yamashita Yuu
7121fe04b0 add install.sh 2012-10-23 15:44:59 +09:00
Yamashita Yuu
908334a8e5 update help messages 2012-10-18 12:01:04 +09:00
Yamashita Yuu
50403a674e update README 2012-10-18 11:37:42 +09:00
Yamashita Yuu
83a85e0193 enable creating virtualenv based on "system" python.
*NOTE*
change first argument of python-virtualenv to path to the python
executable, not a prefix of python installation.
2012-10-16 00:05:34 +09:00
Yamashita Yuu
67fc864252 python 2.6 and older don't have "bin/python" as symlink.
so we must traverse files like "bin/python*" to obtain canonical name..
2012-09-28 20:11:06 +09:00
Yamashita Yuu
bd38d39ea4 create virtualenv by actual executable name such as python2.7 or pypy. 2012-09-28 12:58:06 +09:00
Yamashita Yuu
ed5f3eef77 ignore cache files generated by python3 and jython. 2012-09-28 12:33:31 +09:00
5 changed files with 117 additions and 33 deletions

6
.gitignore vendored
View File

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

View File

@@ -21,6 +21,24 @@ the `~/.pyenv/plugins/python-virtualenv` directory. From that directory, you
can check out a specific release tag. To update python-virtualenv, run `git
pull` to download the latest changes.
### Installing as a standalone program (advanced)
Installing python-virtualenv as a standalone program will give you access to
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
$ cd python-virtualenv
$ ./install.sh
This will install python-virtualenv into `/usr/local`. If you do not have
write permission to `/usr/local`, you will need to run `sudo
./install.sh` instead. You can install to a different prefix by
setting the `PREFIX` environment variable.
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
@@ -30,7 +48,7 @@ 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 2.7.3 venv27
$ pyenv virtualenv --distribute 2.7.3 venv27
virtualenvs will be created into a directory of the same name
under `~/.pyenv/versions`.
@@ -38,6 +56,13 @@ under `~/.pyenv/versions`.
## Version History
#### 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
* Initial public release.

View File

@@ -15,7 +15,7 @@ fi
eval "$(python-virtualenv --lib)"
usage() {
{ echo "usage: pyenv virtualenv [-v|--verbose] [VIRTUALENV_OPTIONS] PYTHON_VERSION NAME"
{ echo "usage: pyenv virtualenv [-v|--verbose] [VIRTUALENV_OPTIONS] VERSION VIRTUALENV_NAME"
echo
echo " -v/--verbose Verbose mode: print compilation status to stdout"
echo
@@ -53,9 +53,31 @@ for script in $(pyenv-hooks virtualenv); do
source "$script"
done
PYTHON_PREFIX="${PYENV_ROOT}/versions/${VERSION_NAME}"
PYTHON_BIN=$(PYENV_VERSION="${VERSION_NAME}" pyenv-which python)
if [ ! -x "${PYTHON_BIN}" ]; then
echo "pyenv-virtualenv: could not obtain python executable: ${PYTHON_BIN}" >&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}"
python-virtualenv $VERBOSE "${VIRTUALENV_OPTIONS[@]}" "$PYTHON_PREFIX" "$VIRTUALENV_PATH"
python-virtualenv $VERBOSE "${VIRTUALENV_OPTIONS[@]}" "$PYTHON_BIN" "$VIRTUALENV_PATH"
pyenv rehash

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env bash
PYTHON_VIRTUALENV_VERSION="20120927"
PYTHON_VIRTUALENV_VERSION="20121023"
set -E
exec 3<&2 # preserve original stderr at fd 3
@@ -30,14 +30,6 @@ lib() {
done
}
if [ "$1" == "--$FUNCNAME" ]; then
declare -f "$FUNCNAME"
echo "$FUNCNAME \"\$1\";"
exit
fi
}
lib "$1"
resolve_link() {
$(type -p greadlink readlink | head -1) "$1"
}
@@ -56,13 +48,21 @@ abs_dirname() {
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_prefix virtualenv_path"
echo "usage: python-virtualenv [-v|--verbose] [VIRTUALENV_OPTIONS] python_bin virtualenv_path"
} >&2
if [ -z "$1" ]; then
@@ -99,11 +99,11 @@ for option in "${OPTIONS[@]}"; do
esac
done
PYTHON_PREFIX="${ARGUMENTS[0]}"
if [ -z "$PYTHON_PREFIX" ]; then
PYTHON_BIN="${ARGUMENTS[0]}"
if [ -z "${PYTHON_BIN}" ]; then
usage
elif [ ! -x "${PYTHON_PREFIX}/bin/python" ]; then
echo "python-virtualenv: python not found: ${PYTHON_PREFIX}" >&2
elif [ ! -x "${PYTHON_BIN}" ]; then
echo "python-virtualenv: given python is not an executable: ${PYTHON_BIN}" >&2
exit 1
fi
@@ -112,7 +112,19 @@ if [ -z "$VIRTUALENV_PATH" ]; then
usage
fi
PYTHON_BIN="${PYTHON_PREFIX}/bin/python"
CWD="$(pwd)"
VIRTUALENV_PYTHON_BIN="${VIRTUALENV_PATH}/bin/python"
"${PYTHON_BIN}" "${PYTHON_VIRTUALENV_ROOT}/libexec/virtualenv.py" --python="${PYTHON_BIN}" "${VIRTUALENV_OPTIONS[@]}" "${VIRTUALENV_PATH}"
# 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

23
install.sh Executable file
View 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/python-virtualenv"
mkdir -p "${BIN_PATH}"
mkdir -p "${LIBEXEC_PATH}"
for file in bin/*; do
cp "${file}" "${BIN_PATH}"
done
for file in libexec/*; do
cp "${file}" "${LIBEXEC_PATH}"
done
echo "Installed python-virtualenv at ${PREFIX}"