helm/rake/pkg/pyenv.rake

84 lines
2.2 KiB
Ruby
Raw Normal View History

2014-09-05 14:03:26 -07:00
PYENV_ROOT = File.expand_path("~/.pyenv")
def pyenv_installed?
Dir.exists?(PYENV_ROOT)
end
def pyenv_versions
`ls -1 #{PYENV_ROOT}/versions`.split("\n") if Dir.exists? "#{PYENV_ROOT}/versions"
end
def pyenv_plugins
Dir.glob("#{PYENV_ROOT}/plugins/*")
end
def pyenv_version_installed?(version)
versions = pyenv_versions
versions.include?(version) if versions
end
2014-09-05 14:03:26 -07:00
###
2014-08-30 23:50:03 -07:00
desc "Install/update pyenv & all pythons"
task :pyenv => 'pyenv:update'
namespace :pyenv do
task :install do
unless pyenv_installed?
echo "Installing pyenv"
github "yyuu/pyenv", PYENV_ROOT
2014-09-05 14:03:26 -07:00
[ "yyuu/pyenv-doctor",
"yyuu/pyenv-installer",
"yyuu/pyenv-pip-rehash",
"yyuu/pyenv-update",
"yyuu/pyenv-virtualenv",
"yyuu/pyenv-which-ext"
2014-09-05 14:03:26 -07:00
].each do |pkg|
echo "Installing #{pkg}", 2
2014-09-05 14:03:26 -07:00
github pkg, "#{PYENV_ROOT}/plugins/#{pkg.split("/")[1]}"
end
2014-09-01 08:31:24 -07:00
2014-09-05 14:03:26 -07:00
echo "Initializing pyenv", 2
sh_safe "eval \"$(#{PYENV_ROOT}/bin/pyenv init -)\""
sh_safe "eval \"$(#{PYENV_ROOT}/bin/pyenv virtualenv-init -)\""
end
2014-09-05 14:03:26 -07:00
2015-07-24 19:25:35 -07:00
['3.4.3', '2.7.10'].each do |version|
2015-01-12 20:23:09 -08:00
unless pyenv_version_installed? version
# Install global python + packages
echo "Setting up default python (#{version})", 2
sh_safe "pyenv install #{version}"
sh_safe "pyenv global #{version}"
2015-07-24 19:25:35 -07:00
sh_safe "PYENV_VERSION=#{version} #{PYENV_ROOT}/shims/pip install flake8"
2015-01-12 20:23:09 -08:00
sh_safe "PYENV_VERSION=#{version} #{PYENV_ROOT}/shims/pip install nose virtualenv pyyaml ipython"
end
2014-08-30 23:50:03 -07:00
end
end
task :update => "pyenv:install" do
echo "Updating pyenv & plugins"
sh_safe "cd #{PYENV_ROOT} && git pull"
2014-09-05 14:03:26 -07:00
pyenv_plugins.each do |dir|
echo "Updating #{File.basename(dir)}", 2
sh_safe "cd #{dir} && git pull"
end
2014-09-05 14:03:26 -07:00
pyenv_versions.each do |version|
echo "Updating python #{version}", 2
2014-08-30 23:50:03 -07:00
2014-09-05 14:03:26 -07:00
cmd = "#{PYENV_ROOT}/shims/pip"
cmd = "sudo #{version}" if version == "system"
2014-08-30 23:50:03 -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?
task :remove do
2014-08-30 23:50:03 -07:00
echo "Deleting pyenv"
sh_safe "rm -rf #{PYENV_ROOT}"
2014-08-30 23:50:03 -07:00
end
end
end