mirror of
https://github.com/pyenv/pyenv-virtualenv.git
synced 2025-11-12 05:23:53 -05:00
Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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
|
||||
*.pyo
|
||||
/libexec/*.class
|
||||
/libexec/*.pyc
|
||||
/libexec/*.pyo
|
||||
/libexec/__pycache__
|
||||
*.swo
|
||||
*.swp
|
||||
|
||||
3
LICENSE
3
LICENSE
@@ -1,5 +1,4 @@
|
||||
Copyright (c) 2012 Yamashita, Yuu
|
||||
Copyright (c) 2011 Sam Stephenson
|
||||
Copyright (c) 2013 Yamashita, Yuu
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
||||
48
README.md
48
README.md
@@ -1,27 +1,29 @@
|
||||
# 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
|
||||
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
|
||||
|
||||
### 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.
|
||||
|
||||
$ mkdir -p ~/.pyenv/plugins
|
||||
$ cd ~/.pyenv/plugins
|
||||
$ git clone git://github.com/yyuu/python-virtualenv.git
|
||||
$ git clone git://github.com/yyuu/pyenv-virtualenv.git
|
||||
|
||||
This will install the latest development version of python-virtualenv into
|
||||
the `~/.pyenv/plugins/python-virtualenv` directory. From that directory, you
|
||||
can check out a specific release tag. To update python-virtualenv, run `git
|
||||
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.
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
### Using `pyenv virtualenv` with pyenv
|
||||
@@ -30,7 +32,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 +40,29 @@ under `~/.pyenv/versions`.
|
||||
|
||||
## Version History
|
||||
|
||||
#### 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
|
||||
|
||||
* Initial public release.
|
||||
@@ -46,8 +71,7 @@ under `~/.pyenv/versions`.
|
||||
|
||||
(The MIT License)
|
||||
|
||||
Copyright (c) 2012 Yamashita, Yuu
|
||||
Copyright (c) 2011 Sam Stephenson
|
||||
* Copyright (c) 2013 Yamashita, Yuu
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
|
||||
@@ -1,31 +1,84 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Summary: Create a Python virtualenv using the pyenv-virtualenv plugin
|
||||
#
|
||||
# Usage: pyenv virtualenv [VIRTUALENV_OPTIONS] <version> <virtualenv-name>
|
||||
# pyenv virtualenv --version
|
||||
# pyenv virtualenv --help
|
||||
#
|
||||
|
||||
PYENV_VIRTUALENV_VERSION="20130507"
|
||||
|
||||
set -e
|
||||
[ -n "$PYENV_DEBUG" ] && set -x
|
||||
|
||||
# Provide pyenv completions
|
||||
if [ "$1" = "--complete" ]; then
|
||||
exec pyenv versions --bare
|
||||
exec pyenv-versions --bare
|
||||
fi
|
||||
|
||||
if [ -z "$PYENV_ROOT" ]; then
|
||||
PYENV_ROOT="${HOME}/.pyenv"
|
||||
fi
|
||||
|
||||
# Load shared library functions
|
||||
eval "$(python-virtualenv --lib)"
|
||||
# Define library functions
|
||||
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"
|
||||
}
|
||||
|
||||
version() {
|
||||
local VIRTUALENV_VERSION="$(pyenv-exec python "${VIRTUALENV}" --version || true)"
|
||||
echo "pyenv-virtualenv ${PYENV_VIRTUALENV_VERSION} (virtualenv ${VIRTUALENV_VERSION:-unknown})"
|
||||
}
|
||||
|
||||
usage() {
|
||||
{ echo "usage: pyenv virtualenv [-v|--verbose] [VIRTUALENV_OPTIONS] PYTHON_VERSION NAME"
|
||||
echo
|
||||
echo " -v/--verbose Verbose mode: print compilation status to stdout"
|
||||
echo
|
||||
} >&2
|
||||
|
||||
# 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
|
||||
[ -z "$1" ] || exit "$1"
|
||||
}
|
||||
|
||||
unset VERBOSE
|
||||
|
||||
PYENV_VIRTUALENV_ROOT="$(abs_dirname "$0")/.."
|
||||
VIRTUALENV="${PYENV_VIRTUALENV_ROOT}/libexec/pyenv-virtualenv/virtualenv.py"
|
||||
[ -f "${VIRTUALENV}" ] || VIRTUALENV="${PYENV_VIRTUALENV_ROOT}/libexec/python-virtualenv/virtualenv.py" # backward compatibility before v20130307
|
||||
[ -f "${VIRTUALENV}" ] || VIRTUALENV="${PYENV_VIRTUALENV_ROOT}/libexec/virtualenv.py"
|
||||
VIRTUALENV_OPTIONS=()
|
||||
|
||||
parse_options "$@"
|
||||
@@ -34,11 +87,9 @@ for option in "${OPTIONS[@]}"; do
|
||||
"h" | "help" )
|
||||
usage 0
|
||||
;;
|
||||
"v" | "verbose" )
|
||||
VERBOSE="-v"
|
||||
;;
|
||||
"version" )
|
||||
exec python-virtualenv --version
|
||||
version
|
||||
exit 0
|
||||
;;
|
||||
* )
|
||||
VIRTUALENV_OPTIONS[${#VIRTUALENV_OPTIONS[*]}]="--$option"
|
||||
@@ -53,9 +104,49 @@ 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"
|
||||
pyenv rehash
|
||||
# virtualenv may download distribute/setuptools in current directory.
|
||||
# change to cache directory to reuse them between invocation.
|
||||
VIRTUALENV_CACHE_PATH="${PYTHON_BUILD_CACHE_PATH:-${PYENV_ROOT}/cache}"
|
||||
mkdir -p "${VIRTUALENV_CACHE_PATH}"
|
||||
{
|
||||
cd "${VIRTUALENV_CACHE_PATH}"
|
||||
"${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
|
||||
|
||||
pyenv-rehash
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
PYTHON_VIRTUALENV_VERSION="20120927"
|
||||
PYTHON_VIRTUALENV_VERSION="20130507"
|
||||
|
||||
set -E
|
||||
exec 3<&2 # preserve original stderr at fd 3
|
||||
@@ -30,6 +30,24 @@ lib() {
|
||||
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\";"
|
||||
@@ -38,31 +56,13 @@ lib() {
|
||||
}
|
||||
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"
|
||||
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
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/*; do
|
||||
cp "${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