0

I recently updated my global pyenv to use a newer version of python and enable some other features. The problem is this breaks my powerline (a statusline plugin I use on bash) setup. Previously I followed their instructions where they mention using that repository-root is sourced from pip show powerline-status.

The problem is that command provides a lot of other information beyond just the path itself. Is there a way to have my .bash_profile reference the site package path instead of having just a hardcoded absolute path?

Vivek Gani
  • 1,283
  • 14
  • 28

1 Answers1

0

One method is to use the output of a command like python -c "import powerline as _; print(_.__path__[0])" which will print out the package directory. using that as a base path you can then invoke powerline.sh. Here's what I have in my .bash_profile for this:

#Powerline shell invoke
## Note: if you've upgrade pyenv and have with old powerline installed, 
##       make sure you 'pyenv shell' to the older release and 
##       uninstall powerline first. Otherwise you'll get 'command not found' errors.
## 1. start daemon - done in 'quiet' mode for speed optimization
powerline-daemon -q
## 2. start powerline shell
export POWERLINE_SITE_PACKAGE_PATH=`python -c "import powerline as _; print(_.__path__[0])"`
. $POWERLINE_SITE_PACKAGE_PATH/bindings/bash/powerline.sh

Warning: you might need something more sophisticated than this if you regularly use pyenv local environments.

Note: Could you cache this value so I don't have to invoke python every time? Theoretically yes, but then it gets complicated in terms of checking when a change happens. You may as well just paste the absolute path in. You need to either save the path to a file and clear it. Keeping it simple for now. Merely testing for the variable (by doing something like if [ -z ${POWERLINE_SITE_PACKAGE_PATH+x} ] ; then .....; fi won't persist across bash sessions.

answer inspired by How do I find the location of my Python site-packages directory?

Vivek Gani
  • 1,283
  • 14
  • 28