2012-08-31 06:23:41 +00:00
|
|
|
#!/usr/bin/env bash
|
2013-01-18 08:41:41 +00:00
|
|
|
#
|
|
|
|
# Summary: Set or show the local application-specific Python version
|
|
|
|
#
|
|
|
|
# Usage: pyenv local <version>
|
|
|
|
# pyenv local --unset
|
|
|
|
#
|
|
|
|
# Sets the local application-specific Python version by writing the
|
|
|
|
# version name to a file named `.python-version'.
|
|
|
|
#
|
|
|
|
# When you run a Python command, pyenv will look for a `.python-version'
|
|
|
|
# file in the current directory and each parent directory. If no such
|
|
|
|
# file is found in the tree, pyenv will use the global Python version
|
|
|
|
# specified with `pyenv global'. A version specified with the
|
|
|
|
# `PYENV_VERSION' environment variable takes precedence over local
|
|
|
|
# and global versions.
|
|
|
|
#
|
|
|
|
# <version> should be a string matching a Python version known to pyenv.
|
|
|
|
# The special version string `system' will use your default system Python.
|
|
|
|
# Run `pyenv versions' for a list of available Python versions.
|
|
|
|
|
2012-08-31 06:23:41 +00:00
|
|
|
set -e
|
|
|
|
[ -n "$PYENV_DEBUG" ] && set -x
|
|
|
|
|
|
|
|
# Provide pyenv completions
|
|
|
|
if [ "$1" = "--complete" ]; then
|
|
|
|
echo --unset
|
|
|
|
echo system
|
|
|
|
exec pyenv-versions --bare
|
|
|
|
fi
|
|
|
|
|
2014-09-11 10:59:40 +00:00
|
|
|
versions=("$@")
|
2012-08-31 06:23:41 +00:00
|
|
|
|
2012-09-07 10:16:42 +00:00
|
|
|
if [ "$versions" = "--unset" ]; then
|
2013-01-18 08:55:46 +00:00
|
|
|
rm -f .python-version .pyenv-version
|
2012-09-07 10:16:42 +00:00
|
|
|
elif [ -n "$versions" ]; then
|
2014-01-02 17:05:40 +00:00
|
|
|
previous_file="$(PYENV_VERSION= pyenv-version-origin || true)"
|
|
|
|
pyenv-version-file-write .python-version "${versions[@]}"
|
|
|
|
if [ "$previous_file" -ef .pyenv-version ]; then
|
2013-01-18 08:55:46 +00:00
|
|
|
rm -f .pyenv-version
|
|
|
|
{ echo "pyenv: removed existing \`.pyenv-version' file and migrated"
|
|
|
|
echo " local version specification to \`.python-version' file"
|
|
|
|
} >&2
|
|
|
|
fi
|
2012-08-31 06:23:41 +00:00
|
|
|
else
|
2013-08-15 13:29:14 +00:00
|
|
|
OLDIFS="$IFS"
|
2012-09-07 10:16:42 +00:00
|
|
|
IFS=: versions=($(
|
2013-01-18 08:55:46 +00:00
|
|
|
pyenv-version-file-read .python-version ||
|
|
|
|
pyenv-version-file-read .pyenv-version ||
|
2012-08-31 07:09:46 +00:00
|
|
|
{ echo "pyenv: no local version configured for this directory"
|
|
|
|
exit 1
|
|
|
|
} >&2
|
|
|
|
))
|
2013-08-15 13:29:14 +00:00
|
|
|
IFS="$OLDIFS"
|
2012-09-07 10:16:42 +00:00
|
|
|
for version in "${versions[@]}"; do
|
2012-08-31 10:39:29 +00:00
|
|
|
echo "$version"
|
2012-08-31 07:09:46 +00:00
|
|
|
done
|
2012-08-31 06:23:41 +00:00
|
|
|
fi
|