Skip to content
This repository has been archived by the owner on Apr 14, 2021. It is now read-only.

'bundle check' checks if gems are cached, not installed #162

Closed
thinkerbot opened this issue Mar 2, 2010 · 11 comments
Closed

'bundle check' checks if gems are cached, not installed #162

thinkerbot opened this issue Mar 2, 2010 · 11 comments

Comments

@thinkerbot
Copy link
Contributor

It appears that 'bundle check' only checks for cached gems when resolving dependencies. This cause false positives when you have multiple projects like so:

Project A:

[Gemfile]
source :gemcutter
gem 'rack-test', :group => :development

% bundle install --without development

Project B:

[Gemfile]
source :gemcutter
gem 'rack-test'

% bundle check
The Gemfile's dependencies are satisfied
% bundle exec ruby -e 'require "rack/test"'
/Library/Ruby/Site/1.8/rubygems/specification.rb:618:in `installation_path': spec rack-test-0.5.3 is not from an installed gem (Gem::Exception)
...

According to 'bundle check', the dependencies for project B are satisfied. I interpreted this to mean the dependencies are installed, but clearly they are not. I think the check should verify that the dependencies are actually installed and available, rather than just cached. Alternatively, there should be a way to check if the dependencies are installed without running a full 'bundle install'.

I found this on bundler-0.9.10

@thinkerbot
Copy link
Contributor Author

In investigating this issue it may help to know that I find the following:

  • 'bundle install' to install a gem dependency (say rack-test)
  • 'bundle check' is satisfied
  • remove rack-test from ~/.bundle/.../gems
  • 'bundle check' is satisfied
  • remove rack-test from ~/.bundle/.../specifications
  • 'bundle check' is satisfied
  • remove rack-test from ~/.bundle/.../cache
  • 'bundle check' is no longer satisfied

Then from the other direction:

  • 'bundle install' to install a gem dependency (say rack-test)
  • 'bundle check' is satisfied
  • remove rack-test from ~/.bundle/.../cache
  • 'bundle check' is satisfied
  • remove rack-test from ~/.bundle/.../specifications
  • 'bundle check' is no longer satisfied

So it appears that the check looks for a cached gem, then it looks for a specification, but it doesn't require in either case that the gem is installed under the gems directory.

@indirect
Copy link
Member

indirect commented Mar 3, 2010

I can reproduce this. Make sure that you don't have rack-test installed in system gems.

@carllerche
Copy link
Contributor

This is fixed on master. Please let me know if this works.

@thinkerbot
Copy link
Contributor Author

I still see the same problem at commit fdb0f0c:

[Gemfile]
source :gemcutter
gem 'rack-test', :group => :development

% bundle version
Bundler version 0.9.11.pre
% bundle install --without development
% bundle check
The Gemfile's dependencies are satisfied
% bundle exec ruby -e 'require "rack/test"'
-e:1:in `require': no such file to load -- rack/test (LoadError)
from -e:1

The check passes even when all the dependencies are expected. I guess this is what I would expect to happen:

% bundle install --without development
% bundle check --without development
The Gemfile's dependencies are satisfied
% bundle check
The following dependencies are missing
  * rack-test (>= 0, runtime)

@thinkerbot
Copy link
Contributor Author

FYI, I just updated my last comment with the correct error. I accidentally listed the error in my initial report (a Gem::Exception) but the current error is a LoadError as shown.

@indirect
Copy link
Member

indirect commented Mar 9, 2010

That is not the same problem, and that is not a bug. When you run bundle install --without development, you are committing to a bundle without any of the development gems until you specify otherwise. If you want bundler to include development gems, again, you need to run bundle install without excluding any groups.

@thinkerbot
Copy link
Contributor Author

I may not have been clear in my explanation but this is the original issue I was
reporting. I was trying to report that according to the documentation,
'bundle check' checks that all gems are installed and available for use.

% bundle help check
Usage:
  bundle check

Checks if the dependencies listed in Gemfile are satisfied by currently installed gems

The problem is that right now if you're in project A and you install --without
development, then in project B 'bundle check' passes and implies that all the
gems are installed and available but clearly they are not. At present the
'bundle install --without development' commits ALL projects to work without,
in this case, the rack-test gem.

You can get around this in project B by doing 'bundle install', but the issue
is that the check is producing a false positive (in project B).

This issue will be solved if 'bundle check' in fact checks to see if the necessary
gems are installed and not just cached. That way the check in project A will
pass (because the gem doesn't need to be installed) and the check in project B will fail (because the gem won't be installed).

Looking over my last comment, I did cheat on the demonstration regarding how this
issue isn't fixed. Here is a proper demo. It shows that I get the same errors
as I first reported.

First what is correct:

[project_a/Gemfile]
source :gemcutter
gem 'rack-test', :group => :development

project_a % bundle install --without development
project_a % bundle check
The Gemfile's dependencies are satisfied
project_a % bundle exec ruby -e 'require "rack/test"'
-e:1:in `require': no such file to load -- rack/test (LoadError)
    from -e:1

Now what is amiss:

[project_b/Gemfile]
source :gemcutter
gem 'rack-test'

project_b % bundle check
The Gemfile's dependencies are satisfied
project_b % bundle exec ruby -e 'require "rack/test"'
bundle exec ruby -e 'require "rack/test"'
/Library/Ruby/Site/1.8/rubygems/specification.rb:618:in `installation_path': spec rack-test-0.5.3 is not from an installed gem (Gem::Exception)
...
project_b % bundle version
Bundler version 0.9.11.pre

IMO this is a bug. If it's not then I think the documentation on 'bundle
check' should be updated. In that case this issue is really a feature request
for some way to check that the bundle is fully ready and available for use.

@indirect
Copy link
Member

indirect commented Mar 9, 2010

Thanks for your example. This is a bug, and should be fixed shortly.

@indirect
Copy link
Member

indirect commented Mar 9, 2010

Should be working as of b5f28d6.

@thinkerbot
Copy link
Contributor Author

Great, thanks! That fixes the issue.

@thinkerbot
Copy link
Contributor Author

Whoops. I thought the fix worked but turns out I overlooked something important. At present check doesn't remember the --without. Here's what I currently get:

[project_a/Gemfile]
source :gemcutter
gem 'rack-test', :group => :development

project_a % bundle install --without development
project_a % bundle check; echo $?
rack-test (0.5.3) is cached, but not installed
Try running `bundle install`
0

I expect the check should actually return satisfied because it should remember the --without flag. In project B the output is correct:

[project_b/Gemfile]
source :gemcutter
gem 'rack-test'

project_b % bundle check; echo $?
rack-test (0.5.3) is cached, but not installed
Try running `bundle install`
0

This is the right text but the exit status should probably be 1, not 0. This was some bad checking on my part, so I took the initiative to make a patch: bahuvrihi/bundler@4916626b1a620cfb566f4344ab0c7ca631915e3d

The patch makes check remember the --without option and causes an exit code of 1 when the check fails. Note that 1) I just copy/pasted the without logic from Installer#run, so I'm not sure if it's the best thing to do and 2) something goes wonky when you merge this code with master. It works as a branch off of 0.9.11 but then one of the specs starts failing mysteriously when merged with 0.10.0.pre (d2c92e4).

This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants