jimweirich/rake

Unable to use repo in Gemfile because gemspec is missing

contentfree opened this issue · 7 comments

In a Gemfile, I'm often able to use syntax like gem 'something', github: 'user/repo' and install the gem from the head of the repo. I'm unable to do that with Rake, unexpectedly. Is this on purpose and what is the work-around?

Apparently Bundler tries hard to make-do when a git repo has no gemspec, but it requires specifying the version as well.

So in my case, I actually needed gem 'rake', '10.1.0.0', github: 'jimweirich/rake' and it then installed (and internally creates a simple gemspec). However, I'd like to not specify the version for obvious reasons.

Is there a reason to not have a gemspec in the repo?

The canonical "gemspec" is in rakelib/gemspec.rake. We build the gemspec in Ruby rather than in a serialized Yaml file. We could generate the YAML file (there is a rake task for that) and add it to the repo, but don't see the sense of duplicating that info (and having the danger of having it get out of sync), and it is much easier to manage in the Ruby code than in a YAML file.

Just noting that I think you can use any version you want for your bundler file. It just wants a version, but doesn't care what the version is, right?

Since the head of the repo isn't likely to be any particular version exactly, I would use something like '10.1.0.alpha.20130527'. Adding a YAML gemfile won't solve the problem because whatever version is in it wouldn't be exactly right either.

(Seems to me that arbitrarily loading up the head of a repo that's not under your control is asking for trouble. Can you tie it to a particular commit instead of HEAD? I least then I can't accidently change it out from under you.)

Nokogiri and mechanize don't include the gemspec in the repository as it's a dangerous thing to install directly from the development branch: http://blog.flavorjon.es/2012/03/y-u-no-gemspec.html

Thanks, that's a good explanation. I'm going to bookmark that for future reference.

I read Nokogiri's explanation and it makes sense. Though it seems inflexible: If I, as a developer, want to install directly from a git repo I probably need to do that for a reason.

However, there really isn't a problem here: I was just missing the (arbitrary) version on the direct-from-the-repo gem's line in my Gemfile and I can install directly from a git repo in most cases.

@jimweirich, you are able to specify a particular revision using the ref: key. And a derivation of your version idea would be to just use the same ref in the version.

So, for a complete line to install (most) gems directly from a git repo: gem "some_gem", git: "http://some/url.git", version: "1.2.3.alpha.abcd4567", ref: "abcd4567"

Yes, I strongly recommend that you use the a particular ref rather than whatever head happens to be ... at least on projects that don't have a designated branch that is intended to be "user-ready" at all times.