Parcourir la source

Merge branch 'activate' (fixes #9)

check-usage-before-uninstall
Yamashita Yuu il y a 10 ans
Parent
révision
88c9633415
5 fichiers modifiés avec 85 ajouts et 3 suppressions
  1. +17
    -0
      README.md
  2. +48
    -0
      bin/pyenv-sh-activate
  3. +17
    -0
      bin/pyenv-sh-deactivate
  4. +2
    -2
      bin/pyenv-virtualenv
  5. +1
    -1
      bin/pyenv-virtualenv-prefix

+ 17
- 0
README.md Voir le fichier

@ -78,6 +78,23 @@ version.
venv33 (created from /home/yyuu/.pyenv/versions/3.3.3)
### Activate virtualenv
Some external tools (e.g. [jedi](https://github.com/davidhalter/jedi)) might require you to `activate` the virtualenv.
`pyenv activate` lets you to activate the virtualenv into your shell.
$ pyenv activate venv27
`pyenv activate` acts almost like following commands.
$ pyenv shell venv27
$ source "$(pyenv prefix venv27)/bin/activate"
You can deactivate the activate'd virtualenv by `pyenv deactivate`.
$ pyenv deactivate
### Special environment variables
You can set certain environment variables to control the pyenv-virtualenv.

+ 48
- 0
bin/pyenv-sh-activate Voir le fichier

@ -0,0 +1,48 @@
#!/usr/bin/env bash
#
# Summary: Activate virtual environment
#
# Usage: pyenv activate <virtualenv>
# pyenv activate --unset
#
# Activate a Python virtualenv environment in current shell.
# This acts almost as same as `pyenv shell`, but this invokes the `activate`
# script in your shell.
#
# <virtualenv> should be a string matching a Python version known to pyenv.
set -e
[ -n "$PYENV_DEBUG" ] && set -x
# Provide pyenv completions
if [ "$1" = "--complete" ]; then
echo --unset
exec pyenv-virtualenvs --bare
fi
versions=("$@")
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
if [ -z "$versions" ]; then
OLDIFS="$IFS"
IFS=: versions=($(pyenv-version-name))
IFS="$OLDIFS"
fi
if [ "$1" = "--unset" ]; then
echo "pyenv deactivate"
exit
fi
if [ "${#versions[@]}" -gt 1 ]; then
echo "pyenv-virtualenv: cannot activate multiple versions at once: ${versions[@]}" 1>&2
exit 1
fi
pyenv-virtualenv-prefix "${versions}" 1>/dev/null
echo "pyenv shell \"${versions}\""
case "$shell" in
fish ) echo ". \"$(pyenv-prefix "${versions}")/bin/activate.fish\"" ;;
* ) echo "source \"$(pyenv-prefix "${versions}")/bin/activate\"" ;;
esac

+ 17
- 0
bin/pyenv-sh-deactivate Voir le fichier

@ -0,0 +1,17 @@
#!/usr/bin/env bash
#
# Summary: Deactivate virtual environment
#
# Usage: pyenv deactivate
#
# Deactivate a Python virtual environment.
set -e
[ -n "$PYENV_DEBUG" ] && set -x
shell="$(basename "${PYENV_SHELL:-$SHELL}")"
case "$shell" in
fish ) echo "functions -q deactivate; and deactivate";;
* ) echo "declare -f deactivate 1>/dev/null 2>&1 && deactivate";;
esac
echo "pyenv shell --unset"

+ 2
- 2
bin/pyenv-virtualenv Voir le fichier

@ -230,7 +230,7 @@ for option in "${OPTIONS[@]}"; do
done
if [[ "${#ARGUMENTS[@]}" == 0 ]]; then
echo "pyenv: no virtualenv name given." 1>&2
echo "pyenv-virtualenv: no virtualenv name given." 1>&2
exit 1
elif [[ "${#ARGUMENTS[@]}" == 1 ]]; then
# If only one argument given, use current version as source version
@ -312,7 +312,7 @@ done
# the --force option was specified.
if [ -d "${VIRTUALENV_PATH}/bin" ]; then
if [ -z "$FORCE" ]; then
echo "pyenv: ${VIRTUALENV_PATH} already exists" 1>&2
echo "pyenv-virtualenv: ${VIRTUALENV_PATH} already exists" 1>&2
read -p "continue with installation? (y/N) "
case "$REPLY" in

+ 1
- 1
bin/pyenv-virtualenv-prefix Voir le fichier

@ -39,7 +39,7 @@ for version in "${versions[@]}"; do
VIRTUALENV_PREFIX_PATHS=("${VIRTUALENV_PREFIX_PATHS[@]}" "$VIRTUALENV_PREFIX_PATH")
fi
else
echo "pyenv: version \`${version}' is not a virtualenv" 1>&2
echo "pyenv-virtualenv: version \`${version}' is not a virtualenv" 1>&2
exit 1
fi
done

Chargement…
Annuler
Enregistrer