Skip to content
New issue

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

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optional gem dependency problems #35

Open
robd opened this issue Jul 4, 2015 · 3 comments
Open

Optional gem dependency problems #35

robd opened this issue Jul 4, 2015 · 3 comments
Labels

Comments

@robd
Copy link
Contributor

robd commented Jul 4, 2015

I'm not sure if this was intentional, but this change:

group :extras, :optional => true

Caused my call to rake to fail like this:

airbrussh:rake
There was an error in your Gemfile, and Bundler cannot continue.

I tried bundle install and I got this:

bundle install
/Users/robd/.rbenv/versions/2.2.2/lib/ruby/gems/2.2.0/gems/bundler-1.9.4/lib/bundler/dependency.rb:54:in `block in initialize': undefined method `to_sym' for {:optional=>true}:Hash (NoMethodError)

Basically, looks like :optional => true is not backwards compatible with older versions of bundler. I'm not sure if this was intentional - looks like the intention was for v1.10 of bundler to only be needed for people who wanted to run the optional tasks, but this doesn't work - everyone needs v1.10.

I upgraded bundler, reinstalled the gems and then I saw:

airbrussh:rake                                                                                                                                                                        2.2.2
rake aborted!
LoadError: cannot load such file -- chandler/tasks
/Users/robd/dev/airbrussh/Rakefile:14:in `require'

This can be fixed by patching the rake file like this, (but I don't know what gem version find_all_by_name was added):

if !ENV["TRAVIS"] &&  Gem::Specification::find_all_by_name('chandler').any?
  require "chandler/tasks"
  task "release:rubygem_push" => "chandler:push"
end

I'm not sure what the motivation was as far as making some gems optional. I think it is a nice idea in principle, but I wonder if the complexity of trying to make them optional is worth it. Personally I'm happy to just install everything even if I don't use guard, chandler etc.

I'm happy to do a PR for this, but I wanted to discuss first to find out which direction it should go in.

@mattbrictson
Copy link
Owner

The conditional logic is necessary because guard and chandler do not work in 1.9.3. I believe Ruby 2.1 or higher is required for those. Bundler 1.10 adds some new features regarding optional dependencies, so I wanted to check if that would help solve this problem. Sounds like I didn't get it working quite right.

Maybe the Rakefile problem could be rewritten as:

begin
  require "chandler/tasks"
rescue LoadError
end
task "release:rubygem_push" => "chandler:push" if defined?(Chandler)

Then it just becomes a matter of whether to install the extra gems or not. Perhaps the better Bundler 1.10 feature to use in this case is install_if.

group :ruby_2, :install_if => -> { check_ruby_gte_2_1_0 } do
  #...
end

I mentioned in the CHANGELOG that Bundler 1.10 is now a requirement. Maybe that should go in CONTRIBUTING as well.

@mattbrictson
Copy link
Owner

I will make the above change to the Rakefile, which will solve the immediate problem. I'm still open to discuss whether the Bundler 1.10 requirement is unreasonable or if bundle install --with extras is a unnecessary step that we should do away with.

@huerlisi
Copy link
Contributor

I think this issue can be closed. It's been fine for me to work with and is properly documented in the contributor documentation.

Bundler >= 1.10 is fine nowadays;-)

I think dropping support for 1.9 could be a topic for the next major release. But as long as it's no pain, this compatibility is a 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants