Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle BUNDLER_VERSION being set to an empty string #6928

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

ccutrer
Copy link
Contributor

@ccutrer ccutrer commented Aug 30, 2023

This is useful, in case you're using Docker, and an upstream Dockerfile sets BUNDLER_VERSION to something you don't want. It's impossible to unset it... only override to be the empty string.

What was the end-user or developer problem that led to this PR?

I have a Dockerfile that has an upstream Dockerfile that sets BUNDLER_VERSION, but I don't want that set. I instead want bundler to automatically use the correct version from my Gemfile.lock. Unfortunately, once an env var is set in Docker, it can't be unset. Only overridden (and set to the empty string). When I do that, I get this:

% BUNDLER_VERSION= bundle --version                                
/Users/cody/.rubies/ruby-3.1.3/lib/ruby/site_ruby/3.1.0/rubygems/requirement.rb:107:in `parse': Illformed requirement [""] (Gem::Requirement::BadRequirementError)
	from /Users/cody/.rubies/ruby-3.1.3/lib/ruby/site_ruby/3.1.0/rubygems/requirement.rb:139:in `block in initialize'
	from /Users/cody/.rubies/ruby-3.1.3/lib/ruby/site_ruby/3.1.0/rubygems/requirement.rb:139:in `map!'
	from /Users/cody/.rubies/ruby-3.1.3/lib/ruby/site_ruby/3.1.0/rubygems/requirement.rb:139:in `initialize'
	from /Users/cody/src/canvas-lms/bin/bundle:114:in `new'
	from /Users/cody/src/canvas-lms/bin/bundle:114:in `activate_bundler'
	from /Users/cody/src/canvas-lms/bin/bundle:102:in `load_bundler!'
	from /Users/cody/src/canvas-lms/bin/bundle:128:in `<main>'

What is your fix for the problem, implemented in this PR?

Treat an empty BUNDLER_VERSION env var the same as not present at all.

Make sure the following tasks are checked

@welcome
Copy link

welcome bot commented Aug 30, 2023

Thanks for opening a pull request and helping make RubyGems and Bundler better! Someone from the RubyGems 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 GitHub Actions to test and make sure your change works functionally and uses acceptable conventions, you can review the current progress of GitHub Actions 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 #rubygems or #bundler channel on Slack.

For more information about contributing to the RubyGems project feel free to review our CONTRIBUTING guide

@ccutrer ccutrer force-pushed the BUNDLER_VERSION-empty-string branch from cb1e1cb to 68eb32a Compare August 30, 2023 23:09
@hsbt hsbt force-pushed the BUNDLER_VERSION-empty-string branch from fb76694 to 98277dc Compare December 6, 2023 02:54
@@ -150,6 +150,12 @@
sys_exec "bin/bundle install", :env => { "BUNDLER_VERSION" => "999.999.998", "DEBUG" => "1" }, :raise_on_error => false
expect(out).to include %(Using bundler 999.999.998\n)
end

it "runs correctly even if empty" do
skip "does not work on old rubies" if RUBY_VERSION < "2.7.0"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we are now 3.0+, this line should be deletable

This is useful, in case you're using Docker, and an upstream
Dockerfile sets BUNDLER_VERSION to something you don't want.
It's impossible to unset it... only override to be the empty
string.
@hsbt hsbt force-pushed the BUNDLER_VERSION-empty-string branch from dec8cda to 8246cec Compare December 8, 2023 02:23
Co-authored-by: Hiroshi SHIBATA <hsbt@ruby-lang.org>
@simi
Copy link
Member

simi commented Feb 21, 2024

Instead of trying to update all usage of ENV["BUNDLER_VERSION"], wouldn't make sense to do the opposite and update the ENV["BUNDLER_VERSION"] to nil if set to empty string somewhere in initialisation code? That way it will not be possible to forget handling "" as nil in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants