Start using pyenv

This required a significant refactor to shellenv.sh. Some strange, and
not yet fully understood behavior of add_to_path was uncovered in doing
this refactoring. More investigation is needed.
This commit is contained in:
Ivan Malison 2016-07-26 17:51:21 -07:00
parent 3f0bf2f966
commit 8934fec5ba
No known key found for this signature in database
GPG Key ID: 62530EFBE99DC2F8
3 changed files with 95 additions and 36 deletions

View File

@ -135,6 +135,7 @@
"plantuml",
"pstree",
"pv",
"pyenv",
"pypy",
"python",
"python3",

View File

@ -31,6 +31,17 @@ class PathList(object):
)
def add(self, new_paths, after=False, target=None):
# Remove the path if it already exists in self.paths to ensure
# that the new placement takes precedence
for path in new_paths:
done = False
while not done:
try:
self.paths.remove(path)
except:
done = True
if target:
target_index = self.paths.index(target)
else:

View File

@ -19,18 +19,72 @@ function get_python_scripts_path {
function _setup_env {
_path_helper
hash brew 2>/dev/null && add_to_path "$(brew --prefix coreutils)/libexec/gnubin"
add_to_path /usr/local/lib/python2.7/site-packages --after
add_to_path "$HOME/bin"
hash brew 2>/dev/null && add_to_path --before "$(brew --prefix coreutils)/libexec/gnubin"
add_to_path "/usr/local/bin"
add_to_path "$(get_python_scripts_path)" --before
is_osx && _osx_path_setup
_java_setup
_go_setup
_rust_setup
_tex_setup
if is_osx; then
add_to_path "/usr/local/sbin" --after
add_to_path "$HOME/.local/bin"
add_to_path "$HOME/.lib/bin"
# Travis completion
[ -f "$HOME/.travis/travis.sh" ] && source "$HOME/.travis/travis.sh"
export ENVIRONMENT_SETUP_DONE="$(date)"
}
function _osx_path_setup {
# What is going on here? Why does /libexec/gnubin get added twice
hash brew 2>/dev/null && add_to_path "$(brew --prefix coreutils)/libexec/gnubin"
add_to_path "$HOME/bin"
hash brew 2>/dev/null && add_to_path --before "$(brew --prefix coreutils)/libexec/gnubin"
# Adds airport utility
add_to_path "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources" --after
# I believe that this is here because of some issue with
# python builds in OSX
export CFLAGS=-Qunused-arguments
export CPPFLAGS=-Qunused-arguments
add_to_path "/System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources" --after
}
function _python_setup {
add_to_path "$HOME/.lib/python" --after
export PYENV_ROOT="/usr/local/var/pyenv"
if which pyenv > /dev/null; then
local PYENV_INIT_COMMANDS="$(pyenv init -)"
echo "$PYENV_INIT_COMMANDS"
eval "$PYENV_INIT_COMMANDS"
else
echo "WARNING: pyenv is installed on this machine and python will likely not function correctly"
fi
# The following line is no longer necessary since the pyenv shim
# should handle directing to the appropriate install.
# add_to_path "$(get_python_scripts_path)" --before
add_to_path "$HOME/.lib/python" --path-var 'PYTHONPATH'
# This should no longer be needed now that pyenv is used
# add_to_path /usr/local/lib/python2.7/site-packages --after
}
function _node_setup {
# node/nvm
export NVM_DIR="/Users/imalison/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
export NODE_PATH="/usr/local/lib/node_modules/"
}
function _java_setup {
if is_osx; then
local JDK_LOCATION="$(find /Library/Java/JavaVirtualMachines -depth 1 | head -n 1)"
export JAVA_HOME="$JDK_LOCATION/Contents/Home"
export STUDIO_JDK=$JDK_LOCATION
@ -41,50 +95,34 @@ function _setup_env {
# Access gnu man pages.
hash brew 2> /dev/null && export MANPATH="$(brew --prefix)/opt/coreutils/libexec/gnuman:$MANPATH"
else
# This may be ubuntu/debian specific
export JAVA_HOME="$(update-alternatives --config java | get_cols ' -1' | head -n 1)"
is_osx && export VISUAL="which emacsclient -c -n"
fi
add_to_path "$JAVA_HOME/bin"
add_to_path "$HOME/.lib/python" --after
add_to_path "/usr/local/sbin" --after
function with_shellrc {
zsh -c "source ~/.zshrc && ""$@"
}
# node/nvm
export NVM_DIR="/Users/imalison/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh" # This loads nvm
export NODE_PATH="/usr/local/lib/node_modules/"
add_to_path "$HOME/.local/bin"
add_to_path "$HOME/.lib/python" --path-var 'PYTHONPATH'
# golang
function _go_setup {
add_to_path "$HOME/go" --path-var 'GOPATH'
add_to_path "${GOPATH//://bin:}/bin"
}
# ruby
function _rust_setup {
add_to_path "$HOME/.cargo/bin"
}
function _ruby_setup {
# Load RVM into a shell session *as a function*
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
export RBENV_ROOT=/usr/local/var/rbenv
add_to_path "$HOME/.rbenv/bin"
add_to_path "$HOME/.rvm/bin" --after
hash rbenv 2> /dev/null && eval "$(rbenv init -)"
}
# rust
add_to_path "$HOME/.cargo/bin"
# tex
function _tex_setup {
is_osx && add_to_path "/Library/TeX/texbin/"
# Travis completion
[ -f "$HOME/.travis/travis.sh" ] && source "$HOME/.travis/travis.sh"
add_to_path "$HOME/.lib/bin"
export ENVIRONMENT_SETUP_DONE="$(date)"
}
function _path_helper {
@ -97,4 +135,13 @@ function _path_helper {
environment_variable_exists PATH_HELPER_RAN || _path_helper
environment_variable_exists ENVIRONMENT_SETUP_DONE || _setup_env
# TODO(imalison): These need to run every time because of how their
# version managers work. This could cause problems with the situation
# where we want to intentionally override the python/ruby/node
# versions in use in a given shell.
_node_setup
_ruby_setup
_python_setup
_source_shellenv_files