-
-
Notifications
You must be signed in to change notification settings - Fork 2k
bundler/inline should ignore BUNDLE_PATH and install gems to GEM_HOME #7154
Conversation
Thanks for opening a pull request and helping make Bundler better! Someone from the Bundler team will take a look at your pull request shortly and leave any feedback. Please make sure that your pull request has tests for any changes or added functionality. We use Travis CI to test and make sure your change works functionally and uses acceptable conventions, you can review the current progress of Travis CI in the PR status window below. If you have any questions or concerns that you wish to ask, feel free to leave a comment in this PR or join our #bundler channel on Slack. For more information about contributing to the Bundler project feel free to review our CONTRIBUTING guide |
Hi Bundler team 👋 I see the tests on Travis are failing when |
Hei! We should make this easier, but the current way to try that would be |
Thank you, I will give it a try and come back, hopefully with fixes! |
Hi again! I pushed a commit with a simple fix. It makes the test a bit more fragile as it depends on the implementation of bundler install path now, but it should be very straightforward to understand and fix if needed one day. I was trying to make it better, but I would always hit a wall when I got to It's been fun & great learning experience to dive into Bundler codebase. If you think this P/R could be improved let me know. Thanks! |
Hi @robuye. The approach for the test looks fine to me 👍. Regarding style, what's normally done for these cases in the code base is to use a common context, and different specs for each version. So something like: context "when BUNDLE_PATH set" do
let(:app_dir) do
dir = bundled_app("inline_with_bundle_path")
dir.mkpath
dir
end
before do
Dir.chdir(app_dir) do
script <<-RUBY, :env => { "BUNDLE_PATH" => "./vendor/inline" }
gemfile(true) do
source "file://#{gem_repo1}"
gem "rack"
end
RUBY
end
end
after do
app_dir.rmtree
end
it "installs inline gems to the configured path", :bundler => "2" do
expect(last_command).to be_success
expect(app_dir.join("./vendor/inline/gems/rack-1.0.0")).to exist
end
it "installs inline gems to the configured path, appending the ruby scope to it", :bundler => "3" do
expect(last_command).to be_success
expect(app_dir.join("./vendor/inline/ruby/#{Gem::ConfigMap[:ruby_version]}/gems/rack-1.0.0")).to exist
end
end Regarding the fix itself, it also looks fine to me, but I want to ask about the current behavior. Does it actually work, but ignores I ask because if it's "working", people might be relying on the bug and successfully sharing |
👍 makes sense and sounds good, I will rewrite my spec.
It works fine, only ignores BUNDLE_PATH and installs gems to the global location. Given the following code (from the original issue): require 'bundler/inline'
gemfile(true) do
source 'https://rubygems.org'
gem 'hello-ruby-gem'
end When I run When I run You're right this may be a breaking change for people who rely on sharing inline & default gems. I think a workaround for this would be to reset the env inside inline script ( I didn't test unsetting the ENV but I will confirm that and come back with the answer. |
It took longer than I expected, but I think it's all good. I force-pushed the last commit with updates to tests (thanks for doing the hard part!). There's one significant change I'm introducing to Adding Below is summary of my manual tests. Before my change both bundler v2 and v3 install to system location regardless of BUNDLE_PATH:
With my change and no BUNDLE_PATH Bundler 3 installs to local directory:
Bundler 2 installs to system location as before:
With my change and
Bundler 2 installs into vendor without ruby scope:
|
@robuye We ended up backporting the new behavior of prepending the ruby scope to bundler 2, so you can actually simplify the tests now (you can rebase to double check it's all good, although our bot will do it anyways, so not needed). Regarding the change itself, @indirect do you have any thoughts about this? In principle it makes sense to me, and I think it's independent from the fact that once we start installing gems to a local path by default, and autocleaning after I wonder if we should provide a different default installation path and environment variable for |
When inline was created it was a deliberate choice to use GEM_HOME rather than BUNDLE_PATH, I think because then 1) all inline scripts can reuse other inline gems, and 2) scripts typically need to be run outside the bundle of the current application. I might be missing something, but it seems like you would never want to share gems between a bundler/inline script and an application's gems in BUNDLE_PATH. It seems like can use |
No, I don't think you're missing anything. The rationale makes sense although I do find the reported bug a bit confusing. The current solution is probably worse than the current situation... :( Should we introduce the environment variable and default path I suggested in my previous message? |
Hey guys, that's very interesting, thanks for taking the time! Is there any risk in having both application and inline gems installed into the same location? Aside how it'd fit with planned changes I think Bundler handles that perfectly fine and in the end the scripts would work exactly the same regardless if we used Respecting Just my 2 cents 😃 |
The problem I forsee is that bundler 3 automatically cleans up unused gems after |
Yea, that makes sense and it should definitely be factored in. I wanted to provide a different point of view because I use I think |
Another way of looking at this situation: That said, if you want to set the location for inline gems with an env var... you can do that today by setting GEM_HOME, either from the command line or inside your script before you require |
Hey guys, apologies for very long wait. @indirect I hear you and see the motivation behind current behaviour. I'm not using I opened this P/R because I saw an issue on Github and figured that would be a great way to learn more about I didn't intend to introduce a big change here and based on the original issue I assumed it's a bug. Would you guys like me to rebase this P/R, undo the changes and add a test to ensure Otherwise there's an idea from @deivid-rodriguez to introduce I'm familiar with the available workarounds, but I'm not original author of the issue. Granted we're mostly settled on not making this change it's probably good idea to check in with @lastk. Let me know how you'd like to proceed and thanks very much for all the time you guys invested into this P/R! |
Hi all, sorry for my late reply, my motivation to open the ticket was because I thought it was a bug. I just wanted to run some scripts to test a rubygem and be able to edit the gem( that's why I wanted to set the folder where those gems were installed ) and I thought the easiest way was just getting one file with everything without worrying about creating a Gemfile. I suppose now I can close the ticket and maybe just use |
@robuye @lastk thanks so much for following up on this <3 I think it's a good idea to write a test to verify that For changing the destination, I think I personally would also be ok with a |
I pushed one more commit. Given it's just one spec in the context and the required setup is much easier I decided to inline it to avoid excessive code. Hopefully you will find it easier to read this way, but if the @lastk that's what I thought too. I use @indirect I agree, there's no need to be adding an option before someone needs it. Both me and @lastk would be able to use proposed workarounds should we need it. This has been very fruitful discussion, thank you everyone for participating. |
@robuye The spec looks good to me, I think you can squash everything yeah. |
As discussed in the P/R, when `BUNDLE_PATH` env is set Bundler should still install gems to the system path. `GEM_HOME` can be used to provide different location if needed. The test is added to document expected behavior of `bundler/inline`.
Hey guys, I updated the branch last night. I think I will leave it in your hands now. Thanks again for your time! 👋 |
Merging this since it's exactly what @indirect requested :). Thanks so much @robuye ❤️ @bundlerbot r+ |
7154: bundler/inline should install gems to BUNDLE_PATH r=deivid-rodriguez a=robuye ### What was the end-user problem that led to this PR? This addresses the problem described in issue #7131. `bundler/inline` does not respect `BUNDLE_PATH` env variable and installs gems to the default location. ### What was your diagnosis of the problem? `Bundler.configure` is not called at any point in `bundler/inline`. ### What is your fix for the problem, implemented in this PR? To call it :) ### Why did you choose this fix out of the possible options? When bundler is invoked via `bundle install` this method gets called. --- The included test is failing without this change as expected. I have also tested it manually using the code from the issue on ruby 2.6 and with bundler `1.17.2` & `2.0.1`. Co-authored-by: robuye <rulejczyk@gmail.com>
Build succeeded |
Whaaaat. The title of this PR is
That's a very strong assumption. Respecting
This is how I tricked coderpad.io to make it possible to use dependencies from Rubygems there. However, this also breaks some of Coderpad's own code that runs right after user code since |
Title updated, good catch @Nowaker, thanks! 👍
Does it work if you restore |
@robuye I tried restoring |
What was the end-user problem that led to this PR?
This addresses the problem described in issue #7131.
bundler/inline
does not respectBUNDLE_PATH
env variable and installs gems to the default location.What was your diagnosis of the problem?
Bundler.configure
is not called at any point inbundler/inline
.What is your fix for the problem, implemented in this PR?
To call it :)
Why did you choose this fix out of the possible options?
When bundler is invoked via
bundle install
this method gets called.The included test is failing without this change as expected.
I have also tested it manually using the code from the issue on ruby 2.6 and with bundler
1.17.2
&2.0.1
.