-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Fix the path to the Gemfile during evaluation. #4244
Conversation
Could you add test coverage for whatever issue this is fixing? |
c14d04e
to
1955f7a
Compare
`Bundler.default_gemfile` was being used instead of the explicitly passed Gemfile path. From: rubygems@ea3ded9
1955f7a
to
8f8c1c4
Compare
That's a good idea. It's a bit unclear to me where a test case should go. Can you point me to the right place? |
Test running |
I'm not sure that would catch this. Bundler supports that already by using the "default gemfile" which will be whatever is passed as the The issue is when you use a different Gemfile than the default. And that begs the question... Why am I doing that? I'm pulling in bundler to use def with_bundler_using_gemfile
original_gemfile_env = ENV["BUNDLE_GEMFILE"]
ENV["BUNDLE_GEMFILE"] = @gemfile_path
original_root = Bundler.root
Bundler.instance_variable_set(:@root, Pathname.new(@base_path))
Dir.chdir(@base_path) do
yield
end
ensure
Bundler.instance_variable_set(:@root, original_root)
ENV["BUNDLE_GEMFILE"] = original_gemfile_env
end Then I can use bundler's classes: with_bundler_using_gemfile do
all_gems = Bundler::LockfileParser.new(File.read(@lockfile_path))
... This is working for me at the moment. I'm not sure if these classes are intended to be used outside of bundler. I'd prefer to code to a public API. Does bundler have a public API that I can code to? Lastly, I think these changes have merit even without my use case.
Similarly, |
These classes arent public API, though. Honestly, I'd prefer to add a |
Fair enough. I think these changes are improvements as they remove assumptions regarding global state. I interpreted @indirect's response in the original PR as a green light toward making these changes happen. Where can I find the public API? I'd guess that the design is limited to support a single Gemfile per process. If that's the case, I shouldn't be using bundler at all to parse Gemfiles. I'll probably write my own parser to avoid bumping up against bundler's internal design. These observations make me curious as to whether anybody has thought about creating a gem for interacting with Gemfile/Gemfile.lock files. I'm not sure if bundler itself will ever support being used in this fashion; though it could. |
The bundler public API at the moment is the CLI, Again, I'd be happy to introduce a private API that makes this easier, as I proposed in my last comment, but it needs to be thoroughly tested, and implemented in such a way that we can support it while changing the internals of Bundler -- and even then, we wouldn't make it 100% public. |
Great! How can I help? |
Ideally, it would also be usable for |
I'm not sure the with_gemfile private API would be enough for my case. I'd like to use other classes with with_gemfile. Would those classes also be in the private API and be supported? |
@dtognazzini what specifically would you like to be public? Right now, we're not willing to commit to making bundler internals public because it would be a significant maintainance burden for us. |
For what I'm doing to work I need access to a |
Supported officially? No, not really. Loosely "supported" so that they're very unlikely to break but we won't make any promises? Sure. |
@segiddins thanks for your time here. I see that Appraisals has their own version of Bundler's DSL: I'll probably do something similar and avoid using Bundler internals altogether. I'm curious as to whether anybody has thought about creating a gem for interacting with Gemfile/Gemfile.lock files. A utility gem that provides Gemfile/Gemfile.lock files parsing would be useful. |
@segiddins How do I find out what is supported in the "private API"? That is, what things are in the set of "loosely 'supported' so that they're very unlikely to break but we won't make any promises"? #3463 discusses a Bundler Plugin System. I'd guess that plugins would access the private API. On Rubygems I found the following uses by other gems:
Are these part of the "private API"? |
@dtognazzini |
@indirect Right on, thanks. I've found It's unclear to me where to find what's included in the public API and the "loosely supported" API. Can you point me to the right place? |
@dtognazzini unfortunately, we don't (yet) have API docs. Mostly because the public API is so small and specialized. I can't think of anything beyond |
Thanks! |
This seems like a good change (in the sense that it allows instances of Bundler::DSL to function correctly independent of the @homu r+ |
📌 Commit 8f8c1c4 has been approved by |
Fix the path to the Gemfile during evaluation. This is a continuation of #3349 Following up per: #3349 (comment) The issue here is that paths used with `Bundler::Dsl#gemspec` will only work when the Gemfile being evaluated is `Bundler.default_gemfile`. Passing a Gemfile other than `Bundler.default_gemfile` to `Bundler::Dsl.evaluate` will break uses of `path:` options in the Gemfile. These changes update `Bundler::Dsl` to remember the Gemfile passed into `eval_gemfile` and use it to resolve relative paths.
☀️ Test successful - status |
This is a continuation of #3349 Following up per: #3349 (comment)
The issue here is that paths used with
Bundler::Dsl#gemspec
will only work when the Gemfile being evaluated isBundler.default_gemfile
.Passing a Gemfile other than
Bundler.default_gemfile
toBundler::Dsl.evaluate
will break uses ofpath:
options in the Gemfile.These changes update
Bundler::Dsl
to remember the Gemfile passed intoeval_gemfile
and use it to resolve relative paths.