-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Document source priority in 2.0 #4629
Comments
Also what if there are two gems that depend on rack in different source blocks, each which have rack? |
💥 (undefined, and we should figure that out) |
IMHO that should be an error, and you should have to specify rack in one of them |
I'm in support of requiring more explicitness in the |
When more than one source hosts a gem of the same name, and that gem is a dependency of a gem listed in the Currently, the state of working with multiple sources in ruby is a bit frustrating, because gems aren't canonically referenced by fully qualified URLs. Instead, there is a global namespace ala DNS. I, for one, am tired of getting stumped to come up with a name every time I publish an open source library in ruby. As it stands, bundler & rubygems works great if you want to throw up a private server with a few gems to augment what's on http://rubygems.org, but I think this change would move more in the direction of being able to support more decentralized setups, which is a big win, in my view. Going along with the example, a gem called So, I think I'm in agreement with @RochesterinNYC . Just wanted to voice my preference as well. |
Another note: I think the behavior of dependencies-of-dependencies ought to be the same as the behavior of dependencies. So, going along @indirect 's example above, suppose I have: source 'https://source-a.com'
source 'https://source-b.com' do
gem 'depends_on_something_that_depends_on_rack'
end In that case, I believe that bundler should prefer any gem called |
This still needs docs, I think, @indirect ? |
@segiddins do we have an executable example that we can use to demonstrate source priority? should I build one? should we document it solely inside the manpage for Gemfile, or elsewhere as well? |
I can dig up a spec we can use for an example. Gemfile seems fine for now, unless it starts confusing people |
@segiddins looks like we still need to implement the error, if you still think we should have that:
|
Why would that error? |
@segiddins earlier in this ticket, you said:
The example above is my attempt to deliberately create that situation. Did I do it wrong? Or have you changed your mind about what should error? |
ah I didn't look that far up... :/ That might be hard to do, but I can look into it |
I can't really think of how to implement this sanely in the resolver at the moment -- the problem is that it's valid for the gem to come from multiple sources, so long as the source it ends up coming from is "'nearer" to the vertex in the dependency graph than any other source that contains a gem with that name |
@greysteil not intending to really rope you into this, but can you think of anything off of the top of your head? |
@segiddins I'm struggling to see how that description ("the source is nearer to the vertex") applies to the second gem, which has a "rack" gem in its own source, and still ends up using the "rack" gem from the other source block instead. Can you elaborate a little bit? |
In this case, they're equally far away. But in this scenario
Unrelated, but a further wrinkle is that the default source exists, but ideally would only be treated as a fallback for those gems we can find in any source of its transitive predecessors? |
@segiddins the |
Here are the available gems:
Here are the gems chosen by Bundler:
The rake is close to one gem, but farther from another. |
Based on previous discussion, I think we should actively raise if |
Even if one of those sources is the default source? Even if one of those sources is not considered a potential source for the gem in question? |
rake is equally far from |
No top-of-my-head idea how to implement a distance-based source error in the resolver. If you go down that route, I guess we could do it in |
@segiddins I think what I'm trying to get at is that Moving wayyyy back to look at the big picture, isn't this situation supposed to raise an error if any gem needs |
I don't know. I think there's an argument to be made that source "https://rubygems.org"
source other_source do
gem "depends_on_rack"
end Should succeed and install rack from other_source. But I'm honestly not sure what the best answer is in this scenario. I guess, from a conservative standpoint, it might be best to error in that scenario for now because that gives us the most latitude to make "improvements" should we think up some brilliant algorithm? |
Another question -- should we raise in this scenario? source source1 do
gem "depend_on_rack"
end
source source2 do
gem "does_not_depend_on_rack"
end where both sources contain rack? |
it turns out we actually have a test for the scenario I described in #4629 (comment), and it asserts that you should be able to install in that scenario, without warning, with the gem coming from the source block source |
[2.0] [Resolver] Error when it is ambigous which transitive source a gem should come from ### What was the end-user problem that led to this PR? The problem was the "source priority" in ambiguous source situations was ... ambiguous. ### What was your diagnosis of the problem? My diagnosis was we should error and require a user explicitly pin the dependency to a source in those situations, rather than leaving the source used up to an implementation detail. ### What is your fix for the problem, implemented in this PR? My fix attempts to implement the priority described in the conversation in #4629. ### Why did you choose this fix out of the possible options? I chose this fix because it still allows using the default source as a backup, while only taking the "relevant" sources into account, so that the error/warning is not overzealous.
Closed by #5985. |
In Bundler 2, all gems have to have an unambiguous source. Since all sources after the first must have blocks with gems in them, this is pretty straightforward:
If a usable version of
rack
is present in the private source, it will be installed. If there is no usable version of rack in the private source, a usable version of rack from the "rubygems" source will be installed. We should document this in the Gemfile manpage and in the website guide to sources.The text was updated successfully, but these errors were encountered: