From 96bbb31cc814d415d974bf0229aa88f3215ce481 Mon Sep 17 00:00:00 2001 From: ickc Date: Sun, 12 Nov 2017 16:20:52 -0800 Subject: [PATCH] Added conda virtualenv support to python module. (#1505) * Added conda virtualenv support to python module * Added instructions for Python module options to README Thanks to @egpbos for the original feature and @ickc for fixing the merge conflicts. --- modules/python/README.md | 13 +++++++++++++ modules/python/functions/python-info | 8 ++++++++ modules/python/init.zsh | 14 ++++++++++++++ 3 files changed, 35 insertions(+) diff --git a/modules/python/README.md b/modules/python/README.md index 27d18e6..900158d 100644 --- a/modules/python/README.md +++ b/modules/python/README.md @@ -3,6 +3,19 @@ Python Enables local Python and local Python package installation. +Settings +-------- + +This module supports virtual environments from conda and virtualenvwrapper. By default, only virtualenvwrapper is enabled. To disable virtualenvwrapper, add the following to *zpreztorc*. + + zstyle ':prezto:module:python' skip-virtualenvwrapper-init 'on' + +Conda support is enabled by adding the following to *zpreztorc*. + + zstyle ':prezto:module:python' conda-init 'on' + +Caution: using conda and virtualenvwrapper at the same time may cause conflicts. + Local Python Installation ------------------------- diff --git a/modules/python/functions/python-info b/modules/python/functions/python-info index a616814..ccca994 100644 --- a/modules/python/functions/python-info +++ b/modules/python/functions/python-info @@ -4,6 +4,7 @@ # # Authors: # Sorin Ionescu +# Patrick Bos # # function python-info { @@ -22,4 +23,11 @@ if [[ -n "$VIRTUAL_ENV" ]]; then python_info[virtualenv]="$virtualenv_formatted" fi +# Do the same for Conda virtual environments +if [[ -n "$CONDA_DEFAULT_ENV" ]]; then + zstyle -s ':prezto:module:python:info:virtualenv' format 'virtualenv_format' + zformat -f virtualenv_formatted "$virtualenv_format" "v:${CONDA_DEFAULT_ENV:t}" + python_info[virtualenv]="$virtualenv_formatted" +fi + # } diff --git a/modules/python/init.zsh b/modules/python/init.zsh index 7aad597..0d15fc0 100644 --- a/modules/python/init.zsh +++ b/modules/python/init.zsh @@ -4,6 +4,7 @@ # Authors: # Sorin Ionescu # Sebastian Wiesner +# Patrick Bos # # Load manually installed pyenv into the shell session. @@ -144,6 +145,19 @@ if (( $#commands[(i)pip(|[23])] )); then unset cache_file pip_command fi +# Load conda into the shell session, if requested +zstyle -T ':prezto:module:python' conda-init +if (( $? && $+commands[conda] )); then + if (( $(conda ..changeps1) )); then + echo "To make sure Conda doesn't change your prompt (should do that in the prompt module) run:\n conda config --set changeps1 false" + # TODO: + # We could just run this ourselves. In an exit hook + # (add zsh-hook zshexit [(anonymous) function]) we could then set it back + # to the way it was before we changed it. However, I'm not sure if this is + # exception safe, so left it like this for now. + fi +fi + # # Aliases #