Last active
August 29, 2015 14:02
-
-
Save matinfo/4ebb926a64b03d8d12d2 to your computer and use it in GitHub Desktop.
Virtualenv Ruby install gems script from requirement_gems.txt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# add first to your virtualenv (postactivate or autoenv, etc) | |
export GEM_HOME="$VIRTUAL_ENV/gems" | |
export GEM_PATH="" | |
export PATH=$PATH:"$GEM_HOME/bin" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sass >=3.3.0alpha --pre | |
compass >=1.0.0alpha --pre | |
bootstrap-sass |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
def parse_require_gem(input) | |
# match, i.e. : 'compass >=1.0.0alpha --pre' or 'compass' without version | |
matches = input.scan(/([a-z0-9_\-]+)(\s([>=]{2}[0-9a-z_\-\.]+))?(\s([a-z-]+))?/) | |
matches.map do |match| | |
{:name => match[0], :version => match[2], :options => match[4]} | |
end | |
end | |
def get_requirements | |
requirements = [] | |
# require requirement_gems.txt file | |
IO.foreach('requirements_gems.txt') do |line| | |
requirements << (parse_require_gem line) | |
end | |
return requirements | |
end | |
def install_gem!(gemspec) | |
if gemspec | |
if not gemspec[:version].nil? | |
if Gem::Specification::find_all_by_name("#{gemspec[:name]}", "#{gemspec[:version]}").any? | |
puts ">>> gem #{gemspec[:name]} (#{gemspec[:version]}) already installed, skipped!" | |
else | |
puts ">>> gem install #{gemspec[:name]} --version '#{gemspec[:version]}' #{gemspec[:options]} --no-rdoc --no-ri" | |
puts `gem install #{gemspec[:name]} --version '#{gemspec[:version]}' #{gemspec[:options]} --no-rdoc --no-ri` | |
end | |
else | |
if Gem::Specification::find_all_by_name("#{gemspec[:name]}").any? | |
puts ">>> gem #{gemspec[:name]} already installed, skipped!" | |
else | |
puts ">>> gem install #{gemspec[:name]} --no-rdoc --no-ri" | |
puts `gem install #{gemspec[:name]} --no-rdoc --no-ri` | |
end | |
end | |
end | |
end | |
def install_all! | |
requirements = get_requirements | |
if not requirements.empty? | |
puts ">>> installing gems requirements on virtualenv:" + ENV['VIRTUAL_ENV'] | |
requirements.each do |gemspec| | |
install_gem! gemspec[0] | |
end | |
end | |
end | |
if ENV['GEM_HOME'] | |
install_all! | |
else | |
puts ">>> GEM_HOME not defined!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This setup permit to have your specific gems packages version by virtualenv :-)