2012-09-03 14:34:41 +00:00
|
|
|
#
|
2012-09-07 03:17:38 +00:00
|
|
|
# Exposes information about the Python environment via the $python_info
|
|
|
|
# associative array.
|
2012-09-03 14:34:41 +00:00
|
|
|
#
|
|
|
|
# Authors:
|
|
|
|
# Sorin Ionescu <sorin.ionescu@gmail.com>
|
2017-11-13 00:20:52 +00:00
|
|
|
# Patrick Bos <egpbos@gmail.com>
|
2012-09-03 14:34:41 +00:00
|
|
|
#
|
|
|
|
|
2017-07-06 23:01:26 +00:00
|
|
|
# function python-info {
|
|
|
|
|
2012-09-03 14:34:41 +00:00
|
|
|
local virtualenv_format
|
|
|
|
local virtualenv_formatted
|
2017-12-04 20:01:07 +00:00
|
|
|
local version_format
|
|
|
|
local version_formatted
|
2017-12-04 23:08:58 +00:00
|
|
|
local version
|
2012-09-03 14:34:41 +00:00
|
|
|
|
|
|
|
# Clean up previous $python_info.
|
|
|
|
unset python_info
|
|
|
|
typeset -gA python_info
|
|
|
|
|
2017-12-04 23:08:58 +00:00
|
|
|
# Grab the styling we might have to do
|
|
|
|
zstyle -s ':prezto:module:python:info:virtualenv' format 'virtualenv_format'
|
|
|
|
zstyle -s ':prezto:module:python:info:version' format 'version_format'
|
|
|
|
|
2012-09-03 14:34:41 +00:00
|
|
|
# Format virtualenv.
|
2017-12-04 23:08:58 +00:00
|
|
|
if [[ -n "$virtualenv_format" ]]; then
|
|
|
|
if [[ -n "$VIRTUAL_ENV" ]]; then
|
|
|
|
zformat -f virtualenv_formatted "$virtualenv_format" "v:${VIRTUAL_ENV:t}"
|
|
|
|
python_info[virtualenv]="$virtualenv_formatted"
|
|
|
|
fi
|
2017-07-06 23:01:26 +00:00
|
|
|
|
2017-12-04 23:08:58 +00:00
|
|
|
# Do the same for Conda virtual environments
|
|
|
|
if [[ -n "$CONDA_DEFAULT_ENV" ]]; then
|
|
|
|
zformat -f virtualenv_formatted "$virtualenv_format" "v:${CONDA_DEFAULT_ENV:t}"
|
|
|
|
python_info[virtualenv]="$virtualenv_formatted"
|
|
|
|
fi
|
2017-11-13 00:20:52 +00:00
|
|
|
fi
|
|
|
|
|
2017-12-04 23:08:58 +00:00
|
|
|
if [[ -n "$version_format" ]]; then
|
|
|
|
if (( $+commands[pyenv] )); then
|
|
|
|
version="${"$(pyenv version)"%% *}"
|
|
|
|
elif (( $+commands[python] )); then
|
|
|
|
version="${$(python3 --version)#Python }"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ -n "$version" && "$version" != "system" ]]; then
|
|
|
|
zformat -f version_formatted "$version_format" "v:$version"
|
2017-12-04 20:08:45 +00:00
|
|
|
python_info[version]="$version_formatted"
|
|
|
|
fi
|
2017-12-04 20:01:07 +00:00
|
|
|
fi
|
|
|
|
|
2017-07-06 23:01:26 +00:00
|
|
|
# }
|