(rb|py)env.rake: check for default version separately

This commit is contained in:
Henrik Lissner 2014-09-08 12:10:17 -04:00
parent 4dbf8e592c
commit 319886a11a
2 changed files with 25 additions and 10 deletions

View file

@ -13,6 +13,10 @@ def pyenv_plugins
Dir.glob("#{PYENV_ROOT}/plugins/*") Dir.glob("#{PYENV_ROOT}/plugins/*")
end end
def pyenv_version_installed?(version)
pyenv_versions.include?(version)
end
### ###
desc "Install/update pyenv & all pythons" desc "Install/update pyenv & all pythons"
@ -31,21 +35,23 @@ namespace :pyenv do
"yyuu/pyenv-virtualenv", "yyuu/pyenv-virtualenv",
"yyuu/pyenv-which-ext" "yyuu/pyenv-which-ext"
].each do |pkg| ].each do |pkg|
echo "Installing #{pkg}", 2 ech "Installing #{pkg}", 2
github pkg, "#{PYENV_ROOT}/plugins/#{pkg.split("/")[1]}" github pkg, "#{PYENV_ROOT}/plugins/#{pkg.split("/")[1]}"
end end
echo "Initializing pyenv", 2 echo "Initializing pyenv", 2
sh_safe "eval \"$(#{PYENV_ROOT}/bin/pyenv init -)\"" sh_safe "eval \"$(#{PYENV_ROOT}/bin/pyenv init -)\""
sh_safe "eval \"$(#{PYENV_ROOT}/bin/pyenv virtualenv-init -)\"" sh_safe "eval \"$(#{PYENV_ROOT}/bin/pyenv virtualenv-init -)\""
end
# Install global python + packages
py_version = ENV["PYTHON_VERSION"] py_version = ENV["PYTHON_VERSION"]
unless pyenv_version_installed? py_version
# Install global python + packages
echo "Setting up default python (#{py_version})", 2 echo "Setting up default python (#{py_version})", 2
sh_safe "pyenv install #{py_version}" sh_safe "pyenv install #{py_version}"
sh_safe "pyenv global #{py_version}" sh_safe "pyenv global #{py_version}"
sh_safe "PYENV_VERSION=#{py_version} #{PYENV_ROOT}/shims/pip install cython" sh_safe "PYENV_VERSION=#{py_version} #{PYENV_ROOT}/shims/pip install cython"
sh_safe "PYENV_VERSION=#{py_version} #{PYENV_ROOT}/shims/pip install nose virtualenv pyyaml" sh_safe "PYENV_VERSION=#{py_version} #{PYENV_ROOT}/shims/pip install nose virtualenv pyyaml ipython"
end end
end end

View file

@ -12,9 +12,14 @@ def rbenv_plugins
Dir.glob("#{RBENV_ROOT}/plugins/*") Dir.glob("#{RBENV_ROOT}/plugins/*")
end end
def rbenv_set_default_gems(gems) def rbenv_set_default_gems(*gems)
return if !gems.is_a?(Array) or gems.length == 0 default_gems_file = "#{RBENV_ROOT}/default-gems"
File.write("#{RBENV_ROOT}/default-gems", gems.join("\n")) return if !gems.is_a?(Array) or gems.length == 0 or File.exists?(default_gems_file)
File.write(default_gems_file, gems.join("\n"))
end
def rbenv_version_installed?(version)
rbenv_versions.include?(version)
end end
### ###
@ -45,12 +50,14 @@ namespace :rbenv do
echo "Initializing rbenv", 2 echo "Initializing rbenv", 2
sh_safe "eval \"$(#{RBENV_ROOT}/bin/rbenv init -)\"" sh_safe "eval \"$(#{RBENV_ROOT}/bin/rbenv init -)\""
end
# Set default gems # Set default gems
rbenv_set_default_gems(:bundler, :rspec, :pry, :factory_girl) rbenv_set_default_gems(:bundler, :rspec, :pry, :factory_girl)
# Install global ruby + gems # Install global ruby + gems
ruby_version = "2.1.2" ruby_version = "2.1.2"
unless rbenv_version_installed? ruby_version
echo "Setting up default ruby (#{ruby_version})", 2 echo "Setting up default ruby (#{ruby_version})", 2
sh_safe "rbenv install #{ruby_version}" sh_safe "rbenv install #{ruby_version}"
sh_safe "rbenv global #{ruby_version}" sh_safe "rbenv global #{ruby_version}"
@ -72,6 +79,8 @@ namespace :rbenv do
sh_safe "RBENV_VERSION=#{version} #{cmd} update -f" sh_safe "RBENV_VERSION=#{version} #{cmd} update -f"
sh_safe "RBENV_VERSION=#{version} #{cmd} clean" sh_safe "RBENV_VERSION=#{version} #{cmd} clean"
end end
sh_safe "rbenv rehash"
end end
if rbenv_installed? if rbenv_installed?