Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Using :path with an explicit number causes exception #1034

Closed
mrchucho opened this Issue Feb 11, 2011 · 5 comments

Comments

Projects
None yet
5 participants

According to bundler docs :path can be used with either a gemspec in the gem's root directory or by providing an explicit version number. However, this causes an exception when running things like the Rails console.

gem "some-gem", "=1.0.0", :path => "#{File.expand_path(__FILE__)}/../vendor/gems/some-gem-1.0.0"

Running Rails 2.3 console causes the following exception:

/Users/dev/.rvm/gems/ruby-1.8.7-p302@project/gems/bundler-1.0.10/lib/bundler/rubygems_ext.rb:28:in `loaded_from': undefined method `path' for #<Bundler::Source::Rubygems:0x1018f79b8> (NoMethodError)

This exception does not occur if the same gem is used with a gemspec provided and no version number indicated in the Gemfile.

brookr commented Nov 30, 2011

Bizarrely, I'm getting a similar error in a different context.

I have a gem I'm loading form source:

gem "mechanize", "=1.0.0", :path => "vendor/gems/mechanize-1.0.0"

It loads fine if I use bundle install. However, running a rake task that includes:

 puts %x[bundle install]

causes an error:

Using mechanize (1.0.0) 
NoMethodError: undefined method `path' for #<Bundler::Source::Rubygems:0x109130c90>
An error occured while installing mechanize (1.0.0), and Bundler cannot continue.
Make sure that `gem install mechanize -v '1.0.0'` succeeds before bundling.

This is also with Rails 2.3[.14]. I've seen with with bundler 1.0.21 and bundler 1.1rc. I'm using rake 0.9.2.2, and gem version 1.8.11.

What other info would be helpful in tracking this down?

I've just run into this too, but I think it's probably something to do with Rake or the environment it invokes bundler from. Calling from a bootstrap rake task

sh "bundle install"

results in:

NoMethodError: undefined method `path' for rubygems repository http://rubygems.org/:Bundler::Source::Rubygems
An error occured while installing <local gem> (0.1), and Bundler cannot continue.
Make sure that `gem install <local gem> -v '0.1'` succeeds before bundling.

but bundle install in the terminal works fine, and more interestingly bundle install from irb/pry also works fine.

Using ruby 1.9.3-p194, bundler 1.1.3, rake 0.9.2.2, gem 1.8.23

There are two environment variables causing problems for everyone BUNDLE_GEMFILE and RUBYOPT. BUNDLE_GEMFILE causes problems because it means that the bundle called from rake will use the same Gemfile, Gemfile.lock and root as the project from which it's called. RUBYOPT causes problems because something (probably bundler, but I didn't trace it) is making sure that bundler/setup is always required because here's an excerpt of my environment:

RUBYOPT=-I/Users/luke.imhoff/.rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.5/lib -rbundler/setup

Since having BUNDLE_GEMFILE and RUBYOPT set is expected behavior, I think it's best that everyone just works around the issue like I am with this:

Dir.chdir(root) do
  without_groups = ['assets', 'development', 'test']
  old_bundle_gemfile = ENV.delete('BUNDLE_GEMFILE')
  old_rubyopt = ENV.delete('RUBYOPT')

  begin
    sh 'bundle', 'install', '--deployment', '--without', *without_groups
  ensure
    ENV['BUNDLE_GEMFILE'] = old_bundle_gemfile
    ENV['RUBYOPT'] = old_rubyopt
  end
end

I was reading through https://github.com/carlhuda/bundler/blob/master/CHANGELOG.md and stumbled on Bundler.with_clean_env. It takes a block and cleans out all the BUNDLE_* environment variable and removes the -I and -rbundler/setup from ENV['RUBYOPT']. This means a better way to write my last comment is

Dir.chdir(root) do
  without_groups = ['assets', 'development', 'test']

  Bundler.with_clean_env do
    sh 'bundle', 'install', '--deployment', '--without', *without_groups
  end
end
Contributor

xaviershay commented Aug 10, 2013

No bug here.

@xaviershay xaviershay closed this Aug 10, 2013

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment