From 319886a11a160b077737af3af0f52bb2c6f19803 Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Mon, 8 Sep 2014 12:10:17 -0400 Subject: [PATCH] (rb|py)env.rake: check for default version separately --- rake/pkg/pyenv.rake | 12 +++++++++--- rake/pkg/rbenv.rake | 23 ++++++++++++++++------- 2 files changed, 25 insertions(+), 10 deletions(-) diff --git a/rake/pkg/pyenv.rake b/rake/pkg/pyenv.rake index dd4cfe26..2bc608dc 100644 --- a/rake/pkg/pyenv.rake +++ b/rake/pkg/pyenv.rake @@ -13,6 +13,10 @@ def pyenv_plugins Dir.glob("#{PYENV_ROOT}/plugins/*") end +def pyenv_version_installed?(version) + pyenv_versions.include?(version) +end + ### desc "Install/update pyenv & all pythons" @@ -31,21 +35,23 @@ namespace :pyenv do "yyuu/pyenv-virtualenv", "yyuu/pyenv-which-ext" ].each do |pkg| - echo "Installing #{pkg}", 2 + ech "Installing #{pkg}", 2 github pkg, "#{PYENV_ROOT}/plugins/#{pkg.split("/")[1]}" end echo "Initializing pyenv", 2 sh_safe "eval \"$(#{PYENV_ROOT}/bin/pyenv init -)\"" sh_safe "eval \"$(#{PYENV_ROOT}/bin/pyenv virtualenv-init -)\"" + end + py_version = ENV["PYTHON_VERSION"] + unless pyenv_version_installed? py_version # Install global python + packages - py_version = ENV["PYTHON_VERSION"] echo "Setting up default python (#{py_version})", 2 sh_safe "pyenv install #{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 nose virtualenv pyyaml" + sh_safe "PYENV_VERSION=#{py_version} #{PYENV_ROOT}/shims/pip install nose virtualenv pyyaml ipython" end end diff --git a/rake/pkg/rbenv.rake b/rake/pkg/rbenv.rake index f424e18e..ae27200c 100644 --- a/rake/pkg/rbenv.rake +++ b/rake/pkg/rbenv.rake @@ -12,9 +12,14 @@ def rbenv_plugins Dir.glob("#{RBENV_ROOT}/plugins/*") end -def rbenv_set_default_gems(gems) - return if !gems.is_a?(Array) or gems.length == 0 - File.write("#{RBENV_ROOT}/default-gems", gems.join("\n")) +def rbenv_set_default_gems(*gems) + default_gems_file = "#{RBENV_ROOT}/default-gems" + 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 ### @@ -45,12 +50,14 @@ namespace :rbenv do echo "Initializing rbenv", 2 sh_safe "eval \"$(#{RBENV_ROOT}/bin/rbenv init -)\"" + end - # Set default gems - rbenv_set_default_gems(:bundler, :rspec, :pry, :factory_girl) + # Set default gems + rbenv_set_default_gems(:bundler, :rspec, :pry, :factory_girl) - # Install global ruby + gems - ruby_version = "2.1.2" + # Install global ruby + gems + ruby_version = "2.1.2" + unless rbenv_version_installed? ruby_version echo "Setting up default ruby (#{ruby_version})", 2 sh_safe "rbenv install #{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} clean" end + + sh_safe "rbenv rehash" end if rbenv_installed?