2014-08-30 23:50:03 -07:00
|
|
|
desc "Install/update pyenv & all pythons"
|
|
|
|
task :pyenv => 'pyenv:update'
|
|
|
|
|
2014-09-01 07:57:11 -07:00
|
|
|
PYENV_ROOT = File.expand_path("~/.pyenv")
|
|
|
|
|
2014-08-30 23:50:03 -07:00
|
|
|
namespace :pyenv do
|
|
|
|
task :install do
|
|
|
|
unless pyenv_installed?
|
|
|
|
echo "Installing pyenv"
|
2014-09-01 07:57:11 -07:00
|
|
|
|
|
|
|
github "yyuu/pyenv", PYENV_ROOT
|
|
|
|
mkdir_p "#{PYENV_ROOT}/plugins"
|
|
|
|
[ "yyuu/pyenv-doctor",
|
|
|
|
"yyuu/pyenv-installer",
|
|
|
|
"yyuu/pyenv-pip-rehash",
|
|
|
|
"yyuu/pyenv-update",
|
|
|
|
"yyuu/pyenv-virtualenv",
|
|
|
|
"yyuu/pyenv-which-ext"
|
|
|
|
].each { |pkg| github pkg, "#{PYENV_ROOT}/plugins/" }
|
2014-09-01 08:31:24 -07:00
|
|
|
|
|
|
|
sh_safe "eval $(~/.pyenv/bin/pyenv init -)"
|
|
|
|
sh_safe "eval $(~/.pyenv/bin/pyenv virtualenv-init -)"
|
2014-08-30 23:50:03 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
task :update => "pyenv:install" do
|
2014-09-01 07:57:11 -07:00
|
|
|
echo "Updating pyenv & plugins"
|
|
|
|
sh_safe "cd #{PYENV_ROOT} && git pull"
|
|
|
|
pyenv_plugins do |dir|
|
|
|
|
sh_safe "cd #{dir} && git pull"
|
|
|
|
end
|
|
|
|
|
|
|
|
pyenv_versions do |version|
|
|
|
|
echo "Updating python #{version}"
|
2014-08-30 23:50:03 -07:00
|
|
|
|
|
|
|
cmd = "pip"
|
2014-09-01 07:57:11 -07:00
|
|
|
cmd = "sudo #{version}" if v == "system"
|
2014-08-30 23:50:03 -07:00
|
|
|
|
2014-09-01 07:57:11 -07:00
|
|
|
sh_safe "PYENV_VERSION=#{version} #{cmd} freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs #{cmd} install -U"
|
2014-08-30 23:50:03 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-09-01 08:31:24 -07:00
|
|
|
if pyenv_installed?
|
|
|
|
desc "Remove pyenv & installed pythons"
|
|
|
|
task :remove do
|
2014-08-30 23:50:03 -07:00
|
|
|
echo "Deleting pyenv"
|
2014-09-01 07:57:11 -07:00
|
|
|
sh_safe "rm -rf #{PYENV_ROOT}"
|
2014-08-30 23:50:03 -07:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
####
|
|
|
|
|
|
|
|
def pyenv_installed?
|
|
|
|
system("which pyenv")
|
|
|
|
end
|
|
|
|
|
|
|
|
def pyenv_versions
|
2014-09-01 07:57:11 -07:00
|
|
|
`ls -1 #{PYENV_ROOT}/versions`.split("\n") if Dir.exists? "#{PYENV_ROOT}/versions"
|
2014-08-30 23:50:03 -07:00
|
|
|
end
|
|
|
|
|
2014-09-01 07:57:11 -07:00
|
|
|
def pyenv_plugins
|
|
|
|
Dir.glob("#{PYENV_ROOT}/plugins/*")
|
2014-08-30 23:50:03 -07:00
|
|
|
end
|